static int yop_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    YopDecContext *yop = s->priv_data;
    AVIOContext *pb  = s->pb;
    AVCodecContext *audio_dec, *video_dec;
    AVStream *audio_stream, *video_stream;
    int frame_rate, ret;
    audio_stream = av_new_stream(s, 0);
    video_stream = av_new_stream(s, 1);
    video_stream->codec->extradata_size = 8;
    video_stream->codec->extradata = av_mallocz(video_stream->codec->extradata_size +
                                                FF_INPUT_BUFFER_PADDING_SIZE);
    if (!video_stream->codec->extradata)
        return AVERROR(ENOMEM);
    audio_dec               = audio_stream->codec;
    audio_dec->codec_type   = AVMEDIA_TYPE_AUDIO;
    audio_dec->codec_id     = CODEC_ID_ADPCM_IMA_WS;
    audio_dec->channels     = 1;
    audio_dec->sample_rate  = 22050;
    video_dec               = video_stream->codec;
    video_dec->codec_type   = AVMEDIA_TYPE_VIDEO;
    video_dec->codec_id     = CODEC_ID_YOP;
    avio_skip(pb, 6);
    frame_rate              = avio_r8(pb);
    yop->frame_size         = avio_r8(pb) * 2048;
    video_dec->width        = avio_rl16(pb);
    video_dec->height       = avio_rl16(pb);
    video_stream->sample_aspect_ratio = (AVRational){1, 2};
    ret = avio_read(pb, video_dec->extradata, 8);
    if (ret < 8)
        return ret < 0 ? ret : AVERROR_EOF;
    yop->palette_size       = video_dec->extradata[0] * 3 + 4;
    yop->audio_block_length = AV_RL16(video_dec->extradata + 6);
    if (yop->audio_block_length < 920 ||
        yop->audio_block_length + yop->palette_size >= yop->frame_size) {
        av_log(s, AV_LOG_ERROR, "YOP has invalid header\n");
        return AVERROR_INVALIDDATA;
    }
    avio_seek(pb, 2048, SEEK_SET);
    av_set_pts_info(video_stream, 32, 1, frame_rate);
    return 0;
}
['static int yop_read_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n    YopDecContext *yop = s->priv_data;\n    AVIOContext *pb  = s->pb;\n    AVCodecContext *audio_dec, *video_dec;\n    AVStream *audio_stream, *video_stream;\n    int frame_rate, ret;\n    audio_stream = av_new_stream(s, 0);\n    video_stream = av_new_stream(s, 1);\n    video_stream->codec->extradata_size = 8;\n    video_stream->codec->extradata = av_mallocz(video_stream->codec->extradata_size +\n                                                FF_INPUT_BUFFER_PADDING_SIZE);\n    if (!video_stream->codec->extradata)\n        return AVERROR(ENOMEM);\n    audio_dec               = audio_stream->codec;\n    audio_dec->codec_type   = AVMEDIA_TYPE_AUDIO;\n    audio_dec->codec_id     = CODEC_ID_ADPCM_IMA_WS;\n    audio_dec->channels     = 1;\n    audio_dec->sample_rate  = 22050;\n    video_dec               = video_stream->codec;\n    video_dec->codec_type   = AVMEDIA_TYPE_VIDEO;\n    video_dec->codec_id     = CODEC_ID_YOP;\n    avio_skip(pb, 6);\n    frame_rate              = avio_r8(pb);\n    yop->frame_size         = avio_r8(pb) * 2048;\n    video_dec->width        = avio_rl16(pb);\n    video_dec->height       = avio_rl16(pb);\n    video_stream->sample_aspect_ratio = (AVRational){1, 2};\n    ret = avio_read(pb, video_dec->extradata, 8);\n    if (ret < 8)\n        return ret < 0 ? ret : AVERROR_EOF;\n    yop->palette_size       = video_dec->extradata[0] * 3 + 4;\n    yop->audio_block_length = AV_RL16(video_dec->extradata + 6);\n    if (yop->audio_block_length < 920 ||\n        yop->audio_block_length + yop->palette_size >= yop->frame_size) {\n        av_log(s, AV_LOG_ERROR, "YOP has invalid header\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    avio_seek(pb, 2048, SEEK_SET);\n    av_set_pts_info(video_stream, 32, 1, frame_rate);\n    return 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n    AVStream *st = avformat_new_stream(s, NULL);\n    if (st)\n        st->id = id;\n    return st;\n}', 'AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c)\n{\n    AVStream *st;\n    int i;\n    AVStream **streams;\n    if (s->nb_streams >= INT_MAX/sizeof(*streams))\n        return NULL;\n    streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));\n    if (!streams)\n        return NULL;\n    s->streams = streams;\n    st = av_mallocz(sizeof(AVStream));\n    if (!st)\n        return NULL;\n    if (!(st->info = av_mallocz(sizeof(*st->info)))) {\n        av_free(st);\n        return NULL;\n    }\n    st->codec = avcodec_alloc_context3(c);\n    if (s->iformat) {\n        st->codec->bit_rate = 0;\n    }\n    st->index = s->nb_streams;\n    st->start_time = AV_NOPTS_VALUE;\n    st->duration = AV_NOPTS_VALUE;\n    st->cur_dts = 0;\n    st->first_dts = AV_NOPTS_VALUE;\n    st->probe_packets = MAX_PROBE_PACKETS;\n    av_set_pts_info(st, 33, 1, 90000);\n    st->last_IP_pts = AV_NOPTS_VALUE;\n    for(i=0; i<MAX_REORDER_DELAY+1; i++)\n        st->pts_buffer[i]= AV_NOPTS_VALUE;\n    st->reference_dts = AV_NOPTS_VALUE;\n    st->sample_aspect_ratio = (AVRational){0,1};\n    s->streams[s->nb_streams++] = st;\n    return st;\n}']