void avfilter_unref_buffer(AVFilterBufferRef *ref)
{
    if (!ref)
        return;
    if (!(--ref->buf->refcount))
        ref->buf->free(ref->buf);
    av_free(ref->video);
    av_free(ref->audio);
    av_free(ref);
}
['static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *pkt_pts)\n{\n    AVFrame *decoded_frame, *filtered_frame = NULL;\n    void *buffer_to_free = NULL;\n    int i, ret = 0;\n    float quality;\n    int frame_available = 1;\n    if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame()))\n        return AVERROR(ENOMEM);\n    else\n        avcodec_get_frame_defaults(ist->decoded_frame);\n    decoded_frame = ist->decoded_frame;\n    pkt->pts  = *pkt_pts;\n    pkt->dts  = ist->last_dts;\n    *pkt_pts  = AV_NOPTS_VALUE;\n    ret = avcodec_decode_video2(ist->st->codec,\n                                decoded_frame, got_output, pkt);\n    if (ret < 0)\n        return ret;\n    quality = same_quant ? decoded_frame->quality : 0;\n    if (!*got_output) {\n        return ret;\n    }\n    decoded_frame->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts,\n                                           decoded_frame->pkt_dts);\n    pkt->size = 0;\n    pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free);\n    rate_emu_sleep(ist);\n    if (ist->st->sample_aspect_ratio.num)\n        decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;\n    for (i = 0; i < nb_output_streams; i++) {\n        OutputStream *ost = &output_streams[i];\n        int frame_size, resample_changed;\n        if (!check_output_constraints(ist, ost) || !ost->encoding_needed)\n            continue;\n        resample_changed = ost->resample_width   != decoded_frame->width  ||\n                           ost->resample_height  != decoded_frame->height ||\n                           ost->resample_pix_fmt != decoded_frame->format;\n        if (resample_changed) {\n            av_log(NULL, AV_LOG_INFO,\n                    "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\\n",\n                    ist->file_index, ist->st->index,\n                    ost->resample_width,  ost->resample_height,  av_get_pix_fmt_name(ost->resample_pix_fmt),\n                    decoded_frame->width, decoded_frame->height, av_get_pix_fmt_name(decoded_frame->format));\n            avfilter_graph_free(&ost->graph);\n            if (configure_video_filters(ist, ost)) {\n                av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\\n");\n                exit_program(1);\n            }\n            ost->resample_width   = decoded_frame->width;\n            ost->resample_height  = decoded_frame->height;\n            ost->resample_pix_fmt = decoded_frame->format;\n        }\n        if (ist->st->codec->codec->capabilities & CODEC_CAP_DR1) {\n            FrameBuffer      *buf = decoded_frame->opaque;\n            AVFilterBufferRef *fb = avfilter_get_video_buffer_ref_from_arrays(\n                                        decoded_frame->data, decoded_frame->linesize,\n                                        AV_PERM_READ | AV_PERM_PRESERVE,\n                                        ist->st->codec->width, ist->st->codec->height,\n                                        ist->st->codec->pix_fmt);\n            avfilter_copy_frame_props(fb, decoded_frame);\n            fb->buf->priv           = buf;\n            fb->buf->free           = filter_release_buffer;\n            buf->refcount++;\n            av_buffersrc_buffer(ost->input_video_filter, fb);\n        } else\n            av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame,\n                                     decoded_frame->pts, decoded_frame->sample_aspect_ratio);\n        if (!ist->filtered_frame && !(ist->filtered_frame = avcodec_alloc_frame())) {\n            ret = AVERROR(ENOMEM);\n            goto fail;\n        } else\n            avcodec_get_frame_defaults(ist->filtered_frame);\n        filtered_frame = ist->filtered_frame;\n        frame_available = avfilter_poll_frame(ost->output_video_filter->inputs[0]);\n        while (frame_available) {\n            AVFilterBufferRef *picref;\n            AVRational ist_pts_tb;\n            if ((ret = get_filtered_video_frame(ost->output_video_filter,\n                                                filtered_frame, &picref,\n                                                &ist_pts_tb)) < 0)\n                goto fail;\n            filtered_frame->pts = av_rescale_q(picref->pts, ist_pts_tb, AV_TIME_BASE_Q);\n            if (!ost->frame_aspect_ratio)\n                ost->st->codec->sample_aspect_ratio = picref->video->pixel_aspect;\n            do_video_out(output_files[ost->file_index].ctx, ost, filtered_frame, &frame_size,\n                         same_quant ? quality : ost->st->codec->global_quality);\n            if (vstats_filename && frame_size)\n                do_video_stats(output_files[ost->file_index].ctx, ost, frame_size);\n            frame_available = ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]);\n            avfilter_unref_buffer(picref);\n        }\n    }\nfail:\n    av_free(buffer_to_free);\n    return ret;\n}', 'static void do_video_out(AVFormatContext *s,\n                         OutputStream *ost,\n                         AVFrame *in_picture,\n                         int *frame_size, float quality)\n{\n    int nb_frames, i, ret, format_video_sync;\n    AVCodecContext *enc;\n    double sync_ipts, delta;\n    enc = ost->st->codec;\n    sync_ipts = get_sync_ipts(ost, in_picture->pts) / av_q2d(enc->time_base);\n    delta = sync_ipts - ost->sync_opts;\n    nb_frames = 1;\n    *frame_size = 0;\n    format_video_sync = video_sync_method;\n    if (format_video_sync == VSYNC_AUTO)\n        format_video_sync = (s->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH :\n                            (s->oformat->flags & AVFMT_VARIABLE_FPS) ? VSYNC_VFR : VSYNC_CFR;\n    switch (format_video_sync) {\n    case VSYNC_CFR:\n        if (delta < -1.1)\n            nb_frames = 0;\n        else if (delta > 1.1)\n            nb_frames = lrintf(delta);\n        break;\n    case VSYNC_VFR:\n        if (delta <= -0.6)\n            nb_frames = 0;\n        else if (delta > 0.6)\n            ost->sync_opts = lrintf(sync_ipts);\n        break;\n    case VSYNC_PASSTHROUGH:\n        ost->sync_opts = lrintf(sync_ipts);\n        break;\n    default:\n        av_assert0(0);\n    }\n    nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number);\n    if (nb_frames == 0) {\n        nb_frames_drop++;\n        av_log(NULL, AV_LOG_VERBOSE, "*** drop!\\n");\n        return;\n    } else if (nb_frames > 1) {\n        nb_frames_dup += nb_frames - 1;\n        av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\\n", nb_frames - 1);\n    }\n    if (!ost->frame_number)\n        ost->first_pts = ost->sync_opts;\n    for (i = 0; i < nb_frames; i++) {\n        AVPacket pkt;\n        av_init_packet(&pkt);\n        pkt.data = NULL;\n        pkt.size = 0;\n        if (!check_recording_time(ost))\n            return;\n        if (s->oformat->flags & AVFMT_RAWPICTURE &&\n            enc->codec->id == CODEC_ID_RAWVIDEO) {\n            enc->coded_frame->interlaced_frame = in_picture->interlaced_frame;\n            enc->coded_frame->top_field_first  = in_picture->top_field_first;\n            pkt.data   = (uint8_t *)in_picture;\n            pkt.size   =  sizeof(AVPicture);\n            pkt.pts    = av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base);\n            pkt.flags |= AV_PKT_FLAG_KEY;\n            write_frame(s, &pkt, ost);\n        } else {\n            int got_packet;\n            AVFrame big_picture;\n            big_picture = *in_picture;\n            big_picture.interlaced_frame = in_picture->interlaced_frame;\n            if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)) {\n                if (ost->top_field_first == -1)\n                    big_picture.top_field_first = in_picture->top_field_first;\n                else\n                    big_picture.top_field_first = !!ost->top_field_first;\n            }\n            big_picture.quality = quality;\n            if (!enc->me_threshold)\n                big_picture.pict_type = 0;\n            big_picture.pts = ost->sync_opts;\n            if (ost->forced_kf_index < ost->forced_kf_count &&\n                big_picture.pts >= ost->forced_kf_pts[ost->forced_kf_index]) {\n                big_picture.pict_type = AV_PICTURE_TYPE_I;\n                ost->forced_kf_index++;\n            }\n            ret = avcodec_encode_video2(enc, &pkt, &big_picture, &got_packet);\n            if (ret < 0) {\n                av_log(NULL, AV_LOG_FATAL, "Video encoding failed\\n");\n                exit_program(1);\n            }\n            if (got_packet) {\n                if (pkt.pts != AV_NOPTS_VALUE)\n                    pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);\n                if (pkt.dts != AV_NOPTS_VALUE)\n                    pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);\n                write_frame(s, &pkt, ost);\n                *frame_size = pkt.size;\n                video_size += pkt.size;\n                if (ost->logfile && enc->stats_out) {\n                    fprintf(ost->logfile, "%s", enc->stats_out);\n                }\n            }\n        }\n        ost->sync_opts++;\n        ost->frame_number++;\n    }\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n    if (!ref)\n        return;\n    if (!(--ref->buf->refcount))\n        ref->buf->free(ref->buf);\n    av_free(ref->video);\n    av_free(ref->audio);\n    av_free(ref);\n}']