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 output_packet(InputStream *ist, int ist_index,\n                         OutputStream *ost_table, int nb_ostreams,\n                         const AVPacket *pkt)\n{\n    AVFormatContext *os;\n    OutputStream *ost;\n    int ret, i;\n    int got_output;\n    AVFrame picture;\n    void *buffer_to_free = NULL;\n    static unsigned int samples_size= 0;\n    AVSubtitle subtitle, *subtitle_to_free;\n    int64_t pkt_pts = AV_NOPTS_VALUE;\n#if CONFIG_AVFILTER\n    int frame_available;\n#endif\n    float quality;\n    AVPacket avpkt;\n    int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);\n    if(ist->next_pts == AV_NOPTS_VALUE)\n        ist->next_pts= ist->pts;\n    if (pkt == NULL) {\n        av_init_packet(&avpkt);\n        avpkt.data = NULL;\n        avpkt.size = 0;\n        goto handle_eof;\n    } else {\n        avpkt = *pkt;\n    }\n    if(pkt->dts != AV_NOPTS_VALUE)\n        ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);\n    if(pkt->pts != AV_NOPTS_VALUE)\n        pkt_pts = av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q);\n    while (avpkt.size > 0 || (!pkt && got_output)) {\n        uint8_t *data_buf, *decoded_data_buf;\n        int data_size, decoded_data_size;\n    handle_eof:\n        ist->pts= ist->next_pts;\n        if(avpkt.size && avpkt.size != pkt->size &&\n           ((!ist->showed_multi_packet_warning && verbose>0) || verbose>1)){\n            fprintf(stderr, "Multiple frames in a packet from stream %d\\n", pkt->stream_index);\n            ist->showed_multi_packet_warning=1;\n        }\n        decoded_data_buf = NULL;\n        decoded_data_size= 0;\n        data_buf  = avpkt.data;\n        data_size = avpkt.size;\n        subtitle_to_free = NULL;\n        if (ist->decoding_needed) {\n            switch(ist->st->codec->codec_type) {\n            case AVMEDIA_TYPE_AUDIO:{\n                if(pkt && samples_size < FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE)) {\n                    samples_size = FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE);\n                    av_free(samples);\n                    samples= av_malloc(samples_size);\n                }\n                decoded_data_size= samples_size;\n                ret = avcodec_decode_audio3(ist->st->codec, samples, &decoded_data_size,\n                                            &avpkt);\n                if (ret < 0)\n                    return ret;\n                avpkt.data += ret;\n                avpkt.size -= ret;\n                data_size   = ret;\n                got_output  = decoded_data_size > 0;\n                if (!got_output) {\n                    continue;\n                }\n                decoded_data_buf = (uint8_t *)samples;\n                ist->next_pts += ((int64_t)AV_TIME_BASE/bps * decoded_data_size) /\n                    (ist->st->codec->sample_rate * ist->st->codec->channels);\n                break;}\n            case AVMEDIA_TYPE_VIDEO:\n                    decoded_data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2;\n                    avcodec_get_frame_defaults(&picture);\n                    avpkt.pts = pkt_pts;\n                    avpkt.dts = ist->pts;\n                    pkt_pts = AV_NOPTS_VALUE;\n                    ret = avcodec_decode_video2(ist->st->codec,\n                                                &picture, &got_output, &avpkt);\n                    quality = same_quant ? picture.quality : 0;\n                    if (ret < 0)\n                        return ret;\n                    if (!got_output) {\n                        goto discard_packet;\n                    }\n                    ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, picture.pkt_pts, picture.pkt_dts);\n                    if (ist->st->codec->time_base.num != 0) {\n                        int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;\n                        ist->next_pts += ((int64_t)AV_TIME_BASE *\n                                          ist->st->codec->time_base.num * ticks) /\n                            ist->st->codec->time_base.den;\n                    }\n                    avpkt.size = 0;\n                    buffer_to_free = NULL;\n                    pre_process_video_frame(ist, (AVPicture *)&picture, &buffer_to_free);\n                    break;\n            case AVMEDIA_TYPE_SUBTITLE:\n                ret = avcodec_decode_subtitle2(ist->st->codec,\n                                               &subtitle, &got_output, &avpkt);\n                if (ret < 0)\n                    return ret;\n                if (!got_output) {\n                    goto discard_packet;\n                }\n                subtitle_to_free = &subtitle;\n                avpkt.size = 0;\n                break;\n            default:\n                return -1;\n            }\n        } else {\n            switch(ist->st->codec->codec_type) {\n            case AVMEDIA_TYPE_AUDIO:\n                ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) /\n                    ist->st->codec->sample_rate;\n                break;\n            case AVMEDIA_TYPE_VIDEO:\n                if (ist->st->codec->time_base.num != 0) {\n                    int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;\n                    ist->next_pts += ((int64_t)AV_TIME_BASE *\n                                      ist->st->codec->time_base.num * ticks) /\n                        ist->st->codec->time_base.den;\n                }\n                break;\n            }\n            ret = avpkt.size;\n            avpkt.size = 0;\n        }\n        if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {\n            if (audio_volume != 256) {\n                short *volp;\n                volp = samples;\n                for(i=0;i<(decoded_data_size / sizeof(short));i++) {\n                    int v = ((*volp) * audio_volume + 128) >> 8;\n                    if (v < -32768) v = -32768;\n                    if (v >  32767) v = 32767;\n                    *volp++ = v;\n                }\n            }\n        }\n        if (rate_emu) {\n            int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE);\n            int64_t now = av_gettime() - ist->start;\n            if (pts > now)\n                usleep(pts - now);\n        }\n        for (i = 0; i < nb_ostreams; i++) {\n            OutputFile *of = &output_files[ost_table[i].file_index];\n            int frame_size;\n            ost = &ost_table[i];\n            if (ost->source_index != ist_index)\n                continue;\n            if (of->start_time && ist->pts < of->start_time)\n                continue;\n            if (of->recording_time != INT64_MAX &&\n                av_compare_ts(ist->pts, AV_TIME_BASE_Q, of->recording_time + of->start_time,\n                              (AVRational){1, 1000000}) >= 0) {\n                ost->is_past_recording_time = 1;\n                continue;\n            }\n#if CONFIG_AVFILTER\n            if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&\n                ost->input_video_filter) {\n                AVRational sar;\n                if (ist->st->sample_aspect_ratio.num)\n                    sar = ist->st->sample_aspect_ratio;\n                else\n                    sar = ist->st->codec->sample_aspect_ratio;\n                av_vsrc_buffer_add_frame(ost->input_video_filter, &picture, ist->pts, sar);\n            }\n            frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||\n                !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]);\n            while (frame_available) {\n                AVRational ist_pts_tb;\n                if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter)\n                    get_filtered_video_frame(ost->output_video_filter, &picture, &ost->picref, &ist_pts_tb);\n                if (ost->picref)\n                    ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);\n#endif\n                os = output_files[ost->file_index].ctx;\n                if (ost->encoding_needed) {\n                    av_assert0(ist->decoding_needed);\n                    switch(ost->st->codec->codec_type) {\n                    case AVMEDIA_TYPE_AUDIO:\n                        do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size);\n                        break;\n                    case AVMEDIA_TYPE_VIDEO:\n#if CONFIG_AVFILTER\n                        if (ost->picref->video && !ost->frame_aspect_ratio)\n                            ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect;\n#endif\n                        do_video_out(os, ost, ist, &picture, &frame_size,\n                                     same_quant ? quality : ost->st->codec->global_quality);\n                        if (vstats_filename && frame_size)\n                            do_video_stats(os, ost, frame_size);\n                        break;\n                    case AVMEDIA_TYPE_SUBTITLE:\n                        do_subtitle_out(os, ost, ist, &subtitle,\n                                        pkt->pts);\n                        break;\n                    default:\n                        abort();\n                    }\n                } else {\n                    AVFrame avframe;\n                    AVPacket opkt;\n                    int64_t ost_tb_start_time= av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base);\n                    av_init_packet(&opkt);\n                    if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes)\n#if !CONFIG_AVFILTER\n                        continue;\n#else\n                        goto cont;\n#endif\n                    avcodec_get_frame_defaults(&avframe);\n                    ost->st->codec->coded_frame= &avframe;\n                    avframe.key_frame = pkt->flags & AV_PKT_FLAG_KEY;\n                    if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)\n                        audio_size += data_size;\n                    else if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n                        video_size += data_size;\n                        ost->sync_opts++;\n                    }\n                    opkt.stream_index= ost->index;\n                    if(pkt->pts != AV_NOPTS_VALUE)\n                        opkt.pts= av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base) - ost_tb_start_time;\n                    else\n                        opkt.pts= AV_NOPTS_VALUE;\n                    if (pkt->dts == AV_NOPTS_VALUE)\n                        opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->st->time_base);\n                    else\n                        opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base);\n                    opkt.dts -= ost_tb_start_time;\n                    opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base);\n                    opkt.flags= pkt->flags;\n                    if(   ost->st->codec->codec_id != CODEC_ID_H264\n                       && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO\n                       && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO\n                       ) {\n                        if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & AV_PKT_FLAG_KEY))\n                            opkt.destruct= av_destruct_packet;\n                    } else {\n                        opkt.data = data_buf;\n                        opkt.size = data_size;\n                    }\n                    write_frame(os, &opkt, ost->st->codec, ost->bitstream_filters);\n                    ost->st->codec->frame_number++;\n                    ost->frame_number++;\n                    av_free_packet(&opkt);\n                }\n#if CONFIG_AVFILTER\n                cont:\n                frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&\n                                   ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]);\n                if (ost->picref)\n                    avfilter_unref_buffer(ost->picref);\n            }\n#endif\n            }\n        av_free(buffer_to_free);\n        if (subtitle_to_free) {\n            avsubtitle_free(subtitle_to_free);\n            subtitle_to_free = NULL;\n        }\n    }\n discard_packet:\n    if (pkt == NULL) {\n        flush_encoders(ist_index, ost_table, nb_ostreams);\n    }\n    return 0;\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}']