int av_fifo_size(AVFifoBuffer *f)
{
    return (uint32_t)(f->wndx - f->rndx);
}
['static int poll_filters(void)\n{\n    int i, ret = 0;\n    while (ret >= 0 && !received_sigterm) {\n        OutputStream *ost = NULL;\n        int64_t min_pts = INT64_MAX;\n        for (i = 0; i < nb_output_streams; i++) {\n            int64_t pts = output_streams[i]->sync_opts;\n            if (!output_streams[i]->filter || output_streams[i]->finished ||\n                !output_streams[i]->filter->graph->graph)\n                continue;\n            pts = av_rescale_q(pts, output_streams[i]->enc_ctx->time_base,\n                               AV_TIME_BASE_Q);\n            if (pts < min_pts) {\n                min_pts = pts;\n                ost = output_streams[i];\n            }\n        }\n        if (!ost)\n            break;\n        ret = poll_filter(ost);\n        if (ret == AVERROR_EOF) {\n            finish_output_stream(ost);\n            ret = 0;\n        } else if (ret == AVERROR(EAGAIN))\n            return 0;\n    }\n    return ret;\n}', 'static void finish_output_stream(OutputStream *ost)\n{\n    OutputFile *of = output_files[ost->file_index];\n    int i;\n    ost->finished = 1;\n    if (of->shortest) {\n        for (i = 0; i < of->ctx->nb_streams; i++)\n            output_streams[of->ost_index + i]->finished = 1;\n    }\n}', 'static int poll_filter(OutputStream *ost)\n{\n    OutputFile    *of = output_files[ost->file_index];\n    AVFrame *filtered_frame = NULL;\n    int frame_size, ret;\n    if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) {\n        return AVERROR(ENOMEM);\n    }\n    filtered_frame = ost->filtered_frame;\n    if (!ost->initialized) {\n        char error[1024];\n        ret = init_output_stream(ost, error, sizeof(error));\n        if (ret < 0) {\n            av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\\n",\n                   ost->file_index, ost->index, error);\n            exit_program(1);\n        }\n    }\n    if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&\n        !(ost->enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))\n        ret = av_buffersink_get_samples(ost->filter->filter, filtered_frame,\n                                         ost->enc_ctx->frame_size);\n    else\n        ret = av_buffersink_get_frame(ost->filter->filter, filtered_frame);\n    if (ret < 0)\n        return ret;\n    if (filtered_frame->pts != AV_NOPTS_VALUE) {\n        int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;\n        filtered_frame->pts = av_rescale_q(filtered_frame->pts,\n                                           ost->filter->filter->inputs[0]->time_base,\n                                           ost->enc_ctx->time_base) -\n                              av_rescale_q(start_time,\n                                           AV_TIME_BASE_Q,\n                                           ost->enc_ctx->time_base);\n    }\n    switch (ost->filter->filter->inputs[0]->type) {\n    case AVMEDIA_TYPE_VIDEO:\n        if (!ost->frame_aspect_ratio)\n            ost->enc_ctx->sample_aspect_ratio = filtered_frame->sample_aspect_ratio;\n        do_video_out(of, ost, filtered_frame, &frame_size);\n        if (vstats_filename && frame_size)\n            do_video_stats(ost, frame_size);\n        break;\n    case AVMEDIA_TYPE_AUDIO:\n        do_audio_out(of, ost, filtered_frame);\n        break;\n    default:\n        av_assert0(0);\n    }\n    av_frame_unref(filtered_frame);\n    return 0;\n}', 'static void do_video_out(OutputFile *of,\n                         OutputStream *ost,\n                         AVFrame *in_picture,\n                         int *frame_size)\n{\n    int ret, format_video_sync;\n    AVPacket pkt;\n    AVCodecContext *enc = ost->enc_ctx;\n    *frame_size = 0;\n    format_video_sync = video_sync_method;\n    if (format_video_sync == VSYNC_AUTO)\n        format_video_sync = (of->ctx->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH :\n                            (of->ctx->oformat->flags & AVFMT_VARIABLE_FPS) ? VSYNC_VFR : VSYNC_CFR;\n    if (format_video_sync != VSYNC_PASSTHROUGH &&\n        ost->frame_number &&\n        in_picture->pts != AV_NOPTS_VALUE &&\n        in_picture->pts < ost->sync_opts) {\n        nb_frames_drop++;\n        av_log(NULL, AV_LOG_WARNING,\n               "*** dropping frame %d from stream %d at ts %"PRId64"\\n",\n               ost->frame_number, ost->st->index, in_picture->pts);\n        return;\n    }\n    if (in_picture->pts == AV_NOPTS_VALUE)\n        in_picture->pts = ost->sync_opts;\n    ost->sync_opts = in_picture->pts;\n    if (!ost->frame_number)\n        ost->first_pts = in_picture->pts;\n    av_init_packet(&pkt);\n    pkt.data = NULL;\n    pkt.size = 0;\n    if (ost->frame_number >= ost->max_frames)\n        return;\n    if (enc->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) &&\n        ost->top_field_first >= 0)\n        in_picture->top_field_first = !!ost->top_field_first;\n    in_picture->quality = enc->global_quality;\n    in_picture->pict_type = 0;\n    if (ost->forced_kf_index < ost->forced_kf_count &&\n        in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {\n        in_picture->pict_type = AV_PICTURE_TYPE_I;\n        ost->forced_kf_index++;\n    }\n    ost->frames_encoded++;\n    ret = avcodec_send_frame(enc, in_picture);\n    if (ret < 0)\n        goto error;\n    ost->frame_number++;\n    while (1) {\n        ret = avcodec_receive_packet(enc, &pkt);\n        if (ret == AVERROR(EAGAIN))\n            break;\n        if (ret < 0)\n            goto error;\n        output_packet(of, &pkt, ost);\n        *frame_size = pkt.size;\n        if (ost->logfile && enc->stats_out) {\n            fprintf(ost->logfile, "%s", enc->stats_out);\n        }\n        ost->sync_opts++;\n    }\n    return;\nerror:\n    av_assert0(ret != AVERROR(EAGAIN) && ret != AVERROR_EOF);\n    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\\n");\n    exit_program(1);\n}', 'static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)\n{\n    int ret = 0;\n    if (ost->nb_bitstream_filters) {\n        int idx;\n        ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);\n        if (ret < 0)\n            goto finish;\n        idx = 1;\n        while (idx) {\n            ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);\n            if (ret == AVERROR(EAGAIN)) {\n                ret = 0;\n                idx--;\n                continue;\n            } else if (ret < 0)\n                goto finish;\n            if (idx < ost->nb_bitstream_filters) {\n                ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);\n                if (ret < 0)\n                    goto finish;\n                idx++;\n            } else\n                write_packet(of, pkt, ost);\n        }\n    } else\n        write_packet(of, pkt, ost);\nfinish:\n    if (ret < 0 && ret != AVERROR_EOF) {\n        av_log(NULL, AV_LOG_FATAL, "Error applying bitstream filters to an output "\n               "packet for stream #%d:%d.\\n", ost->file_index, ost->index);\n        exit_program(1);\n    }\n}', 'static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)\n{\n    AVFormatContext *s = of->ctx;\n    AVStream *st = ost->st;\n    int ret;\n    if (!of->header_written) {\n        AVPacket tmp_pkt;\n        if (!av_fifo_space(ost->muxing_queue)) {\n            int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),\n                                 ost->max_muxing_queue_size);\n            if (new_size <= av_fifo_size(ost->muxing_queue)) {\n                av_log(NULL, AV_LOG_ERROR,\n                       "Too many packets buffered for output stream %d:%d.\\n",\n                       ost->file_index, ost->st->index);\n                exit_program(1);\n            }\n            ret = av_fifo_realloc2(ost->muxing_queue, new_size);\n            if (ret < 0)\n                exit_program(1);\n        }\n        av_packet_move_ref(&tmp_pkt, pkt);\n        av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL);\n        return;\n    }\n    if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) {\n        if (ost->frame_number >= ost->max_frames) {\n            av_packet_unref(pkt);\n            return;\n        }\n        ost->frame_number++;\n    }\n    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {\n        uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,\n                                              NULL);\n        ost->quality = sd ? *(int *)sd : -1;\n        if (ost->frame_rate.num) {\n            pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate),\n                                         ost->mux_timebase);\n        }\n    }\n    if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&\n        ost->last_mux_dts != AV_NOPTS_VALUE &&\n        pkt->dts < ost->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT)) {\n        av_log(NULL, AV_LOG_WARNING, "Non-monotonous DTS in output stream "\n               "%d:%d; previous: %"PRId64", current: %"PRId64"; ",\n               ost->file_index, ost->st->index, ost->last_mux_dts, pkt->dts);\n        if (exit_on_error) {\n            av_log(NULL, AV_LOG_FATAL, "aborting.\\n");\n            exit_program(1);\n        }\n        av_log(NULL, AV_LOG_WARNING, "changing to %"PRId64". This may result "\n               "in incorrect timestamps in the output file.\\n",\n               ost->last_mux_dts + 1);\n        pkt->dts = ost->last_mux_dts + 1;\n        if (pkt->pts != AV_NOPTS_VALUE)\n            pkt->pts = FFMAX(pkt->pts, pkt->dts);\n    }\n    ost->last_mux_dts = pkt->dts;\n    ost->data_size += pkt->size;\n    ost->packets_written++;\n    pkt->stream_index = ost->index;\n    av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base);\n    ret = av_interleaved_write_frame(s, pkt);\n    if (ret < 0) {\n        print_error("av_interleaved_write_frame()", ret);\n        exit_program(1);\n    }\n}', 'int av_fifo_size(AVFifoBuffer *f)\n{\n    return (uint32_t)(f->wndx - f->rndx);\n}']