static int process_input_packet(InputStream *ist, const AVPacket *pkt)

{

    int i;

    int got_output;

    AVPacket avpkt;



    if (ist->next_dts == AV_NOPTS_VALUE)

        ist->next_dts = ist->last_dts;



    if (pkt == NULL) {

        /* EOF handling */

        av_init_packet(&avpkt);

        avpkt.data = NULL;

        avpkt.size = 0;

        goto handle_eof;

    } else {

        avpkt = *pkt;

    }



    if (pkt->dts != AV_NOPTS_VALUE)

        ist->next_dts = ist->last_dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);



    // while we have more to decode or while the decoder did output something on EOF

    while (ist->decoding_needed && (avpkt.size > 0 || (!pkt && got_output))) {

        int ret = 0;

    handle_eof:



        ist->last_dts = ist->next_dts;



        if (avpkt.size && avpkt.size != pkt->size &&

            !(ist->dec->capabilities & CODEC_CAP_SUBFRAMES)) {

            av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,

                   "Multiple frames in a packet from stream %d\n", pkt->stream_index);

            ist->showed_multi_packet_warning = 1;

        }



        switch (ist->dec_ctx->codec_type) {

        case AVMEDIA_TYPE_AUDIO:

            ret = decode_audio    (ist, &avpkt, &got_output);

            break;

        case AVMEDIA_TYPE_VIDEO:

            ret = decode_video    (ist, &avpkt, &got_output);

            if (avpkt.duration)

                ist->next_dts += av_rescale_q(avpkt.duration, ist->st->time_base, AV_TIME_BASE_Q);

            else if (ist->st->avg_frame_rate.num)

                ist->next_dts += av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate),

                                              AV_TIME_BASE_Q);

            else if (ist->dec_ctx->time_base.num != 0) {

                int ticks      = ist->st->parser ? ist->st->parser->repeat_pict + 1 :

                                                   ist->dec_ctx->ticks_per_frame;

                ist->next_dts += av_rescale_q(ticks, ist->dec_ctx->time_base, AV_TIME_BASE_Q);

            }

            break;

        case AVMEDIA_TYPE_SUBTITLE:

            ret = transcode_subtitles(ist, &avpkt, &got_output);

            break;

        default:

            return -1;

        }



        if (ret < 0)

            return ret;

        // touch data and size only if not EOF

        if (pkt) {

            avpkt.data += ret;

            avpkt.size -= ret;

        }

        if (!got_output) {

            continue;

        }

    }



    /* handle stream copy */

    if (!ist->decoding_needed) {

        ist->last_dts = ist->next_dts;

        switch (ist->dec_ctx->codec_type) {

        case AVMEDIA_TYPE_AUDIO:

            ist->next_dts += ((int64_t)AV_TIME_BASE * ist->dec_ctx->frame_size) /

                             ist->dec_ctx->sample_rate;

            break;

        case AVMEDIA_TYPE_VIDEO:

            if (ist->dec_ctx->time_base.num != 0) {

                int ticks = ist->st->parser ? ist->st->parser->repeat_pict + 1 : ist->dec_ctx->ticks_per_frame;

                ist->next_dts += ((int64_t)AV_TIME_BASE *

                                  ist->dec_ctx->time_base.num * ticks) /

                                  ist->dec_ctx->time_base.den;

            }

            break;

        }

    }

    for (i = 0; pkt && i < nb_output_streams; i++) {

        OutputStream *ost = output_streams[i];



        if (!check_output_constraints(ist, ost) || ost->encoding_needed)

            continue;



        do_streamcopy(ist, ost, pkt);

    }



    return 0;

}

static int process_input_packet(InputStream *ist, const AVPacket *pkt)

{

    int i;

    int got_output;

    AVPacket avpkt;



    if (ist->next_dts == AV_NOPTS_VALUE)

        ist->next_dts = ist->last_dts;



    if (pkt == NULL) {

        

        av_init_packet(&avpkt);

        avpkt.data = NULL;

        avpkt.size = 0;

        goto handle_eof;

    } else {

        avpkt = *pkt;

    }



    if (pkt->dts != AV_NOPTS_VALUE)

        ist->next_dts = ist->last_dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);



    

    while (ist->decoding_needed && (avpkt.size > 0 || (!pkt && got_output))) {

        int ret = 0;

    handle_eof:



        ist->last_dts = ist->next_dts;



        if (avpkt.size && avpkt.size != pkt->size &&

            !(ist->dec->capabilities & CODEC_CAP_SUBFRAMES)) {

            av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,

                   "Multiple frames in a packet from stream %d\n", pkt->stream_index);

            ist->showed_multi_packet_warning = 1;

        }



        switch (ist->dec_ctx->codec_type) {

        case AVMEDIA_TYPE_AUDIO:

            ret = decode_audio    (ist, &avpkt, &got_output);

            break;

        case AVMEDIA_TYPE_VIDEO:

            ret = decode_video    (ist, &avpkt, &got_output);

            if (avpkt.duration)

                ist->next_dts += av_rescale_q(avpkt.duration, ist->st->time_base, AV_TIME_BASE_Q);

            else if (ist->st->avg_frame_rate.num)

                ist->next_dts += av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate),

                                              AV_TIME_BASE_Q);

            else if (ist->dec_ctx->time_base.num != 0) {

                int ticks      = ist->st->parser ? ist->st->parser->repeat_pict + 1 :

                                                   ist->dec_ctx->ticks_per_frame;

                ist->next_dts += av_rescale_q(ticks, ist->dec_ctx->time_base, AV_TIME_BASE_Q);

            }

            break;

        case AVMEDIA_TYPE_SUBTITLE:

            ret = transcode_subtitles(ist, &avpkt, &got_output);

            break;

        default:

            return -1;

        }



        if (ret < 0)

            return ret;

        

        if (pkt) {

            avpkt.data += ret;

            avpkt.size -= ret;

        }

        if (!got_output) {

            continue;

        }

    }



    

    if (!ist->decoding_needed) {

        ist->last_dts = ist->next_dts;

        switch (ist->dec_ctx->codec_type) {

        case AVMEDIA_TYPE_AUDIO:

            ist->next_dts += ((int64_t)AV_TIME_BASE * ist->dec_ctx->frame_size) /

                             ist->dec_ctx->sample_rate;

            break;

        case AVMEDIA_TYPE_VIDEO:

            if (ist->dec_ctx->time_base.num != 0) {

                int ticks = ist->st->parser ? ist->st->parser->repeat_pict + 1 : ist->dec_ctx->ticks_per_frame;

                ist->next_dts += ((int64_t)AV_TIME_BASE *

                                  ist->dec_ctx->time_base.num * ticks) /

                                  ist->dec_ctx->time_base.den;

            }

            break;

        }

    }

    for (i = 0; pkt && i < nb_output_streams; i++) {

        OutputStream *ost = output_streams[i];



        if (!check_output_constraints(ist, ost) || ost->encoding_needed)

            continue;



        do_streamcopy(ist, ost, pkt);

    }



    return 0;

}

static int FUNC_0(InputStream *VAR_0, const AVPacket *VAR_1)

{

    int VAR_2;

    int VAR_3;

    AVPacket avpkt;



    if (VAR_0->next_dts == AV_NOPTS_VALUE)

        VAR_0->next_dts = VAR_0->last_dts;



    if (VAR_1 == NULL) {

        

        av_init_packet(&avpkt);

        avpkt.data = NULL;

        avpkt.size = 0;

        goto handle_eof;

    } else {

        avpkt = *VAR_1;

    }



    if (VAR_1->dts != AV_NOPTS_VALUE)

        VAR_0->next_dts = VAR_0->last_dts = av_rescale_q(VAR_1->dts, VAR_0->st->time_base, AV_TIME_BASE_Q);



    

    while (VAR_0->decoding_needed && (avpkt.size > 0 || (!VAR_1 && VAR_3))) {

        int VAR_4 = 0;

    handle_eof:



        VAR_0->last_dts = VAR_0->next_dts;



        if (avpkt.size && avpkt.size != VAR_1->size &&

            !(VAR_0->dec->capabilities & CODEC_CAP_SUBFRAMES)) {

            av_log(NULL, VAR_0->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,

                   "Multiple frames in a packet from stream %d\n", VAR_1->stream_index);

            VAR_0->showed_multi_packet_warning = 1;

        }



        switch (VAR_0->dec_ctx->codec_type) {

        case AVMEDIA_TYPE_AUDIO:

            VAR_4 = decode_audio    (VAR_0, &avpkt, &VAR_3);

            break;

        case AVMEDIA_TYPE_VIDEO:

            VAR_4 = decode_video    (VAR_0, &avpkt, &VAR_3);

            if (avpkt.duration)

                VAR_0->next_dts += av_rescale_q(avpkt.duration, VAR_0->st->time_base, AV_TIME_BASE_Q);

            else if (VAR_0->st->avg_frame_rate.num)

                VAR_0->next_dts += av_rescale_q(1, av_inv_q(VAR_0->st->avg_frame_rate),

                                              AV_TIME_BASE_Q);

            else if (VAR_0->dec_ctx->time_base.num != 0) {

                int VAR_6      = VAR_0->st->parser ? VAR_0->st->parser->repeat_pict + 1 :

                                                   VAR_0->dec_ctx->ticks_per_frame;

                VAR_0->next_dts += av_rescale_q(VAR_6, VAR_0->dec_ctx->time_base, AV_TIME_BASE_Q);

            }

            break;

        case AVMEDIA_TYPE_SUBTITLE:

            VAR_4 = transcode_subtitles(VAR_0, &avpkt, &VAR_3);

            break;

        default:

            return -1;

        }



        if (VAR_4 < 0)

            return VAR_4;

        

        if (VAR_1) {

            avpkt.data += VAR_4;

            avpkt.size -= VAR_4;

        }

        if (!VAR_3) {

            continue;

        }

    }



    

    if (!VAR_0->decoding_needed) {

        VAR_0->last_dts = VAR_0->next_dts;

        switch (VAR_0->dec_ctx->codec_type) {

        case AVMEDIA_TYPE_AUDIO:

            VAR_0->next_dts += ((int64_t)AV_TIME_BASE * VAR_0->dec_ctx->frame_size) /

                             VAR_0->dec_ctx->sample_rate;

            break;

        case AVMEDIA_TYPE_VIDEO:

            if (VAR_0->dec_ctx->time_base.num != 0) {

                int VAR_6 = VAR_0->st->parser ? VAR_0->st->parser->repeat_pict + 1 : VAR_0->dec_ctx->ticks_per_frame;

                VAR_0->next_dts += ((int64_t)AV_TIME_BASE *

                                  VAR_0->dec_ctx->time_base.num * VAR_6) /

                                  VAR_0->dec_ctx->time_base.den;

            }

            break;

        }

    }

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

        OutputStream *ost = output_streams[VAR_2];



        if (!check_output_constraints(VAR_0, ost) || ost->encoding_needed)

            continue;



        do_streamcopy(VAR_0, ost, VAR_1);

    }



    return 0;

}

static int FUNC_0(InputStream *VAR_0, const AVPacket *VAR_1)
{ int VAR_2; int VAR_3; AVPacket avpkt; if (VAR_0->next_dts == AV_NOPTS_VALUE)
VAR_0->next_dts = VAR_0->last_dts; if (VAR_1 == NULL) { av_init_packet(&avpkt); avpkt.data = NULL; avpkt.size = 0; goto handle_eof; } else { avpkt = *VAR_1; } if (VAR_1->dts != AV_NOPTS_VALUE)
VAR_0->next_dts = VAR_0->last_dts = av_rescale_q(VAR_1->dts, VAR_0->st->time_base, AV_TIME_BASE_Q); while (VAR_0->decoding_needed && (avpkt.size > 0 || (!VAR_1 && VAR_3))) { int VAR_4 = 0; handle_eof:
VAR_0->last_dts = VAR_0->next_dts; if (avpkt.size && avpkt.size != VAR_1->size &&
!(VAR_0->dec->capabilities & CODEC_CAP_SUBFRAMES)) { av_log(NULL, VAR_0->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING,
"Multiple frames in a packet from stream %d\n", VAR_1->stream_index); VAR_0->showed_multi_packet_warning = 1; } switch (VAR_0->dec_ctx->codec_type) { case AVMEDIA_TYPE_AUDIO:
VAR_4 = decode_audio    (VAR_0, &avpkt, &VAR_3); break; case AVMEDIA_TYPE_VIDEO:
VAR_4 = decode_video    (VAR_0, &avpkt, &VAR_3); if (avpkt.duration)
VAR_0->next_dts += av_rescale_q(avpkt.duration, VAR_0->st->time_base, AV_TIME_BASE_Q); else if (VAR_0->st->avg_frame_rate.num)
VAR_0->next_dts += av_rescale_q(1, av_inv_q(VAR_0->st->avg_frame_rate),
AV_TIME_BASE_Q); else if (VAR_0->dec_ctx->time_base.num != 0) { int VAR_6      = VAR_0->st->parser ? VAR_0->st->parser->repeat_pict + 1 :
VAR_0->dec_ctx->ticks_per_frame; VAR_0->next_dts += av_rescale_q(VAR_6, VAR_0->dec_ctx->time_base, AV_TIME_BASE_Q); } break; case AVMEDIA_TYPE_SUBTITLE:
VAR_4 = transcode_subtitles(VAR_0, &avpkt, &VAR_3); break; default:
return -1; } if (VAR_4 < 0)
return VAR_4; if (VAR_1) { avpkt.data += VAR_4; avpkt.size -= VAR_4; } if (!VAR_3) { continue; } } if (!VAR_0->decoding_needed) { VAR_0->last_dts = VAR_0->next_dts; switch (VAR_0->dec_ctx->codec_type) { case AVMEDIA_TYPE_AUDIO:
VAR_0->next_dts += ((int64_t)AV_TIME_BASE * VAR_0->dec_ctx->frame_size) /
VAR_0->dec_ctx->sample_rate; break; case AVMEDIA_TYPE_VIDEO:
if (VAR_0->dec_ctx->time_base.num != 0) { int VAR_6 = VAR_0->st->parser ? VAR_0->st->parser->repeat_pict + 1 : VAR_0->dec_ctx->ticks_per_frame; VAR_0->next_dts += ((int64_t)AV_TIME_BASE *
VAR_0->dec_ctx->time_base.num * VAR_6) /
VAR_0->dec_ctx->time_base.den; } break; } } for (VAR_2 = 0; VAR_1 && VAR_2 < nb_output_streams; VAR_2++) { OutputStream *ost = output_streams[VAR_2]; if (!check_output_constraints(VAR_0, ost) || ost->encoding_needed)
continue; do_streamcopy(VAR_0, ost, VAR_1); } return 0; }