static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
{
    int i, ret;
    for (i = 0; i < nb_ostreams; i++) {
        OutputStream   *ost = &ost_table[i];
        AVCodecContext *enc = ost->st->codec;
        AVFormatContext *os = output_files[ost->file_index].ctx;
        int stop_encoding = 0;
        if (!ost->encoding_needed)
            continue;
        if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <= 1)
            continue;
        if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE) && enc->codec->id == CODEC_ID_RAWVIDEO)
            continue;
        for (;;) {
            AVPacket pkt;
            int fifo_bytes, got_packet;
            av_init_packet(&pkt);
            pkt.data = NULL;
            pkt.size = 0;
            switch (ost->st->codec->codec_type) {
            case AVMEDIA_TYPE_AUDIO:
                fifo_bytes = av_fifo_size(ost->fifo);
                if (fifo_bytes > 0) {
                    int frame_bytes = fifo_bytes;
                    av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);
                    if (!(enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME)) {
                        frame_bytes = enc->frame_size * enc->channels *
                                      av_get_bytes_per_sample(enc->sample_fmt);
                        if (allocated_audio_buf_size < frame_bytes)
                            exit_program(1);
                        generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);
                    }
                    encode_audio_frame(os, ost, audio_buf, frame_bytes);
                } else {
                    if (encode_audio_frame(os, ost, NULL, 0) == 0) {
                        stop_encoding = 1;
                        break;
                    }
                }
                break;
            case AVMEDIA_TYPE_VIDEO:
                ret = avcodec_encode_video2(enc, &pkt, NULL, &got_packet);
                if (ret < 0) {
                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
                    exit_program(1);
                }
                video_size += ret;
                if (ost->logfile && enc->stats_out) {
                    fprintf(ost->logfile, "%s", enc->stats_out);
                }
                if (!got_packet) {
                    stop_encoding = 1;
                    break;
                }
                if (pkt.pts != AV_NOPTS_VALUE)
                    pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);
                if (pkt.dts != AV_NOPTS_VALUE)
                    pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);
                write_frame(os, &pkt, ost);
                break;
            default:
                stop_encoding = 1;
            }
            if (stop_encoding)
                break;
        }
    }
}
['static void flush_encoders(OutputStream *ost_table, int nb_ostreams)\n{\n    int i, ret;\n    for (i = 0; i < nb_ostreams; i++) {\n        OutputStream   *ost = &ost_table[i];\n        AVCodecContext *enc = ost->st->codec;\n        AVFormatContext *os = output_files[ost->file_index].ctx;\n        int stop_encoding = 0;\n        if (!ost->encoding_needed)\n            continue;\n        if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <= 1)\n            continue;\n        if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE) && enc->codec->id == CODEC_ID_RAWVIDEO)\n            continue;\n        for (;;) {\n            AVPacket pkt;\n            int fifo_bytes, got_packet;\n            av_init_packet(&pkt);\n            pkt.data = NULL;\n            pkt.size = 0;\n            switch (ost->st->codec->codec_type) {\n            case AVMEDIA_TYPE_AUDIO:\n                fifo_bytes = av_fifo_size(ost->fifo);\n                if (fifo_bytes > 0) {\n                    int frame_bytes = fifo_bytes;\n                    av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);\n                    if (!(enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME)) {\n                        frame_bytes = enc->frame_size * enc->channels *\n                                      av_get_bytes_per_sample(enc->sample_fmt);\n                        if (allocated_audio_buf_size < frame_bytes)\n                            exit_program(1);\n                        generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);\n                    }\n                    encode_audio_frame(os, ost, audio_buf, frame_bytes);\n                } else {\n                    if (encode_audio_frame(os, ost, NULL, 0) == 0) {\n                        stop_encoding = 1;\n                        break;\n                    }\n                }\n                break;\n            case AVMEDIA_TYPE_VIDEO:\n                ret = avcodec_encode_video2(enc, &pkt, NULL, &got_packet);\n                if (ret < 0) {\n                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\\n");\n                    exit_program(1);\n                }\n                video_size += ret;\n                if (ost->logfile && enc->stats_out) {\n                    fprintf(ost->logfile, "%s", enc->stats_out);\n                }\n                if (!got_packet) {\n                    stop_encoding = 1;\n                    break;\n                }\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(os, &pkt, ost);\n                break;\n            default:\n                stop_encoding = 1;\n            }\n            if (stop_encoding)\n                break;\n        }\n    }\n}', 'void av_init_packet(AVPacket *pkt)\n{\n    pkt->pts   = AV_NOPTS_VALUE;\n    pkt->dts   = AV_NOPTS_VALUE;\n    pkt->pos   = -1;\n    pkt->duration = 0;\n    pkt->convergence_duration = 0;\n    pkt->flags = 0;\n    pkt->stream_index = 0;\n    pkt->destruct= NULL;\n    pkt->side_data       = NULL;\n    pkt->side_data_elems = 0;\n}', 'int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,\n                                              AVPacket *avpkt,\n                                              const AVFrame *frame,\n                                              int *got_packet_ptr)\n{\n    int ret;\n    int user_packet = !!avpkt->data;\n    if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) {\n        av_init_packet(avpkt);\n        avpkt->size     = 0;\n        *got_packet_ptr = 0;\n        return 0;\n    }\n    if (av_image_check_size(avctx->width, avctx->height, 0, avctx))\n        return AVERROR(EINVAL);\n    av_assert0(avctx->codec->encode2);\n    *got_packet_ptr = 0;\n    ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);\n    if (!ret) {\n        if (!*got_packet_ptr)\n            avpkt->size = 0;\n        else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))\n            avpkt->pts = avpkt->dts = frame->pts;\n    }\n    if (!ret)\n        avctx->frame_number++;\n    emms_c();\n    return ret;\n}', 'int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)\n{\n    ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx };\n    if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8)\n        return 0;\n    av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\\n", w, h);\n    return AVERROR(EINVAL);\n}']