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;



        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))

            continue;



        for(;;) {

            AVPacket pkt;

            int fifo_bytes;

            av_init_packet(&pkt);

            pkt.stream_index= ost->index;



            switch (ost->st->codec->codec_type) {

            case AVMEDIA_TYPE_AUDIO:

                fifo_bytes = av_fifo_size(ost->fifo);

                ret = 0;

                /* encode any samples remaining in fifo */

                if (fifo_bytes > 0) {

                    int osize = av_get_bytes_per_sample(enc->sample_fmt);

                    int fs_tmp = enc->frame_size;



                    av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);

                    if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {

                        enc->frame_size = fifo_bytes / (osize * enc->channels);

                    } else { /* pad */

                        int frame_bytes = enc->frame_size*osize*enc->channels;

                        if (allocated_audio_buf_size < frame_bytes)

                            exit_program(1);

                        generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);

                    }



                    ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);

                    pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,

                                              ost->st->time_base.num, enc->sample_rate);

                    enc->frame_size = fs_tmp;

                }

                if (ret <= 0) {

                    ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);

                }

                if (ret < 0) {

                    av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");

                    exit_program(1);

                }

                audio_size += ret;

                pkt.flags |= AV_PKT_FLAG_KEY;

                break;

            case AVMEDIA_TYPE_VIDEO:

                ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);

                if (ret < 0) {

                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");

                    exit_program(1);

                }

                video_size += ret;

                if(enc->coded_frame && enc->coded_frame->key_frame)

                    pkt.flags |= AV_PKT_FLAG_KEY;

                if (ost->logfile && enc->stats_out) {

                    fprintf(ost->logfile, "%s", enc->stats_out);

                }

                break;

            default:

                ret=-1;

            }



            if (ret <= 0)

                break;

            pkt.data = bit_buffer;

            pkt.size = ret;

            if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)

                pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);

            write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters);

        }

    }

}

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;



        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))

            continue;



        for(;;) {

            AVPacket pkt;

            int fifo_bytes;

            av_init_packet(&pkt);

            pkt.stream_index= ost->index;



            switch (ost->st->codec->codec_type) {

            case AVMEDIA_TYPE_AUDIO:

                fifo_bytes = av_fifo_size(ost->fifo);

                ret = 0;

                

                if (fifo_bytes > 0) {

                    int osize = av_get_bytes_per_sample(enc->sample_fmt);

                    int fs_tmp = enc->frame_size;



                    av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);

                    if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {

                        enc->frame_size = fifo_bytes / (osize * enc->channels);

                    } else { 

                        int frame_bytes = enc->frame_size*osize*enc->channels;

                        if (allocated_audio_buf_size < frame_bytes)

                            exit_program(1);

                        generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);

                    }



                    ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);

                    pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,

                                              ost->st->time_base.num, enc->sample_rate);

                    enc->frame_size = fs_tmp;

                }

                if (ret <= 0) {

                    ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);

                }

                if (ret < 0) {

                    av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");

                    exit_program(1);

                }

                audio_size += ret;

                pkt.flags |= AV_PKT_FLAG_KEY;

                break;

            case AVMEDIA_TYPE_VIDEO:

                ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);

                if (ret < 0) {

                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");

                    exit_program(1);

                }

                video_size += ret;

                if(enc->coded_frame && enc->coded_frame->key_frame)

                    pkt.flags |= AV_PKT_FLAG_KEY;

                if (ost->logfile && enc->stats_out) {

                    fprintf(ost->logfile, "%s", enc->stats_out);

                }

                break;

            default:

                ret=-1;

            }



            if (ret <= 0)

                break;

            pkt.data = bit_buffer;

            pkt.size = ret;

            if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)

                pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);

            write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters);

        }

    }

}

static void FUNC_0(OutputStream *VAR_0, int VAR_1)

{

    int VAR_2, VAR_3;



    for (VAR_2 = 0; VAR_2 < VAR_1; VAR_2++) {

        OutputStream   *ost = &VAR_0[VAR_2];

        AVCodecContext *enc = ost->st->codec;

        AVFormatContext *os = output_files[ost->file_index].ctx;



        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))

            continue;



        for(;;) {

            AVPacket pkt;

            int VAR_4;

            av_init_packet(&pkt);

            pkt.stream_index= ost->index;



            switch (ost->st->codec->codec_type) {

            case AVMEDIA_TYPE_AUDIO:

                VAR_4 = av_fifo_size(ost->fifo);

                VAR_3 = 0;

                

                if (VAR_4 > 0) {

                    int VAR_5 = av_get_bytes_per_sample(enc->sample_fmt);

                    int VAR_6 = enc->frame_size;



                    av_fifo_generic_read(ost->fifo, audio_buf, VAR_4, NULL);

                    if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {

                        enc->frame_size = VAR_4 / (VAR_5 * enc->channels);

                    } else { 

                        int VAR_7 = enc->frame_size*VAR_5*enc->channels;

                        if (allocated_audio_buf_size < VAR_7)

                            exit_program(1);

                        generate_silence(audio_buf+VAR_4, enc->sample_fmt, VAR_7 - VAR_4);

                    }



                    VAR_3 = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);

                    pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,

                                              ost->st->time_base.num, enc->sample_rate);

                    enc->frame_size = VAR_6;

                }

                if (VAR_3 <= 0) {

                    VAR_3 = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);

                }

                if (VAR_3 < 0) {

                    av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");

                    exit_program(1);

                }

                audio_size += VAR_3;

                pkt.flags |= AV_PKT_FLAG_KEY;

                break;

            case AVMEDIA_TYPE_VIDEO:

                VAR_3 = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);

                if (VAR_3 < 0) {

                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");

                    exit_program(1);

                }

                video_size += VAR_3;

                if(enc->coded_frame && enc->coded_frame->key_frame)

                    pkt.flags |= AV_PKT_FLAG_KEY;

                if (ost->logfile && enc->stats_out) {

                    fprintf(ost->logfile, "%s", enc->stats_out);

                }

                break;

            default:

                VAR_3=-1;

            }



            if (VAR_3 <= 0)

                break;

            pkt.data = bit_buffer;

            pkt.size = VAR_3;

            if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)

                pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);

            write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters);

        }

    }

}

static void FUNC_0(OutputStream *VAR_0, int VAR_1)
{ int VAR_2, VAR_3; for (VAR_2 = 0; VAR_2 < VAR_1; VAR_2++) { OutputStream   *ost = &VAR_0[VAR_2]; AVCodecContext *enc = ost->st->codec; AVFormatContext *os = output_files[ost->file_index].ctx; 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))
continue; for(;;) { AVPacket pkt; int VAR_4; av_init_packet(&pkt); pkt.stream_index= ost->index; switch (ost->st->codec->codec_type) { case AVMEDIA_TYPE_AUDIO:
VAR_4 = av_fifo_size(ost->fifo); VAR_3 = 0; if (VAR_4 > 0) { int VAR_5 = av_get_bytes_per_sample(enc->sample_fmt); int VAR_6 = enc->frame_size; av_fifo_generic_read(ost->fifo, audio_buf, VAR_4, NULL); if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) { enc->frame_size = VAR_4 / (VAR_5 * enc->channels); } else { int VAR_7 = enc->frame_size*VAR_5*enc->channels; if (allocated_audio_buf_size < VAR_7)
exit_program(1); generate_silence(audio_buf+VAR_4, enc->sample_fmt, VAR_7 - VAR_4); } VAR_3 = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf); pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,
ost->st->time_base.num, enc->sample_rate); enc->frame_size = VAR_6; } if (VAR_3 <= 0) { VAR_3 = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL); } if (VAR_3 < 0) { av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n"); exit_program(1); } audio_size += VAR_3; pkt.flags |= AV_PKT_FLAG_KEY; break; case AVMEDIA_TYPE_VIDEO:
VAR_3 = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL); if (VAR_3 < 0) { av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n"); exit_program(1); } video_size += VAR_3; if(enc->coded_frame && enc->coded_frame->key_frame)
pkt.flags |= AV_PKT_FLAG_KEY; if (ost->logfile && enc->stats_out) { fprintf(ost->logfile, "%s", enc->stats_out); } break; default:
VAR_3=-1; } if (VAR_3 <= 0)
break; pkt.data = bit_buffer; pkt.size = VAR_3; if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters); } } }