static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){

    int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames);

    int num, den, frame_size, i;



//    av_log(st->codec, AV_LOG_DEBUG, "av_write_frame: pts:%"PRId64" dts:%"PRId64" cur_dts:%"PRId64" b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index);



/*    if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE)

        return -1;*/



    /* duration field */

    if (pkt->duration == 0) {

        compute_frame_duration(&num, &den, st, NULL, pkt);

        if (den && num) {

            pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num);

        }

    }



    if(pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay==0)

        pkt->pts= pkt->dts;



    //XXX/FIXME this is a temporary hack until all encoders output pts

    if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay){

        pkt->dts=

//        pkt->pts= st->cur_dts;

        pkt->pts= st->pts.val;

    }



    //calculate dts from pts

    if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){

        st->pts_buffer[0]= pkt->pts;

        for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)

            st->pts_buffer[i]= (i-delay-1) * pkt->duration;

        for(i=0; i<delay && st->pts_buffer[i] > st->pts_buffer[i+1]; i++)

            FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]);



        pkt->dts= st->pts_buffer[0];

    }



    if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){

        av_log(st->codec, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", st->cur_dts, pkt->dts);

        return -1;

    }

    if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){

        av_log(st->codec, AV_LOG_ERROR, "error, pts < dts\n");

        return -1;

    }



//    av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n", pkt->pts, pkt->dts);

    st->cur_dts= pkt->dts;

    st->pts.val= pkt->dts;



    /* update pts */

    switch (st->codec->codec_type) {

    case CODEC_TYPE_AUDIO:

        frame_size = get_audio_frame_size(st->codec, pkt->size);



        /* HACK/FIXME, we skip the initial 0 size packets as they are most

           likely equal to the encoder delay, but it would be better if we

           had the real timestamps from the encoder */

        if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) {

            av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);

        }

        break;

    case CODEC_TYPE_VIDEO:

        av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);

        break;

    default:

        break;

    }

    return 0;

}

static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){

    int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames);

    int num, den, frame_size, i;













    

    if (pkt->duration == 0) {

        compute_frame_duration(&num, &den, st, NULL, pkt);

        if (den && num) {

            pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num);

        }

    }



    if(pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay==0)

        pkt->pts= pkt->dts;



    

    if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay){

        pkt->dts=



        pkt->pts= st->pts.val;

    }



    

    if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){

        st->pts_buffer[0]= pkt->pts;

        for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)

            st->pts_buffer[i]= (i-delay-1) * pkt->duration;

        for(i=0; i<delay && st->pts_buffer[i] > st->pts_buffer[i+1]; i++)

            FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]);



        pkt->dts= st->pts_buffer[0];

    }



    if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){

        av_log(st->codec, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", st->cur_dts, pkt->dts);

        return -1;

    }

    if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){

        av_log(st->codec, AV_LOG_ERROR, "error, pts < dts\n");

        return -1;

    }





    st->cur_dts= pkt->dts;

    st->pts.val= pkt->dts;



    

    switch (st->codec->codec_type) {

    case CODEC_TYPE_AUDIO:

        frame_size = get_audio_frame_size(st->codec, pkt->size);



        





        if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) {

            av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);

        }

        break;

    case CODEC_TYPE_VIDEO:

        av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);

        break;

    default:

        break;

    }

    return 0;

}

    if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){
static int FUNC_0(AVStream *VAR_0, AVPacket *VAR_1){

    int VAR_2 = FFMAX(VAR_0->codec->has_b_frames, !!VAR_0->codec->max_b_frames);

    int VAR_3, VAR_4, VAR_5, VAR_6;













    

    if (VAR_1->duration == 0) {

        compute_frame_duration(&VAR_3, &VAR_4, VAR_0, NULL, VAR_1);

        if (VAR_4 && VAR_3) {

            VAR_1->duration = av_rescale(1, VAR_3 * (int64_t)VAR_0->time_base.VAR_4, VAR_4 * (int64_t)VAR_0->time_base.VAR_3);

        }

    }



    if(VAR_1->pts == AV_NOPTS_VALUE && VAR_1->dts != AV_NOPTS_VALUE && VAR_2==0)

        VAR_1->pts= VAR_1->dts;



    

    if((VAR_1->pts == 0 || VAR_1->pts == AV_NOPTS_VALUE) && VAR_1->dts == AV_NOPTS_VALUE && !VAR_2){

        VAR_1->dts=



        VAR_1->pts= VAR_0->pts.val;

    }



    

    if(VAR_1->pts != AV_NOPTS_VALUE && VAR_1->dts == AV_NOPTS_VALUE){

        VAR_0->pts_buffer[0]= VAR_1->pts;

        for(VAR_6=1; VAR_6<VAR_2+1 && VAR_0->pts_buffer[VAR_6] == AV_NOPTS_VALUE; VAR_6++)

            VAR_0->pts_buffer[VAR_6]= (VAR_6-VAR_2-1) * VAR_1->duration;

        for(VAR_6=0; VAR_6<VAR_2 && VAR_0->pts_buffer[VAR_6] > VAR_0->pts_buffer[VAR_6+1]; VAR_6++)

            FFSWAP(int64_t, VAR_0->pts_buffer[VAR_6], VAR_0->pts_buffer[VAR_6+1]);



        VAR_1->dts= VAR_0->pts_buffer[0];

    }



    if(VAR_0->cur_dts && VAR_0->cur_dts != AV_NOPTS_VALUE && VAR_0->cur_dts >= VAR_1->dts){

        av_log(VAR_0->codec, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", VAR_0->cur_dts, VAR_1->dts);

        return -1;

    }

    if(VAR_1->dts != AV_NOPTS_VALUE && VAR_1->pts != AV_NOPTS_VALUE && VAR_1->pts < VAR_1->dts){

        av_log(VAR_0->codec, AV_LOG_ERROR, "error, pts < dts\n");

        return -1;

    }





    VAR_0->cur_dts= VAR_1->dts;

    VAR_0->pts.val= VAR_1->dts;



    

    switch (VAR_0->codec->codec_type) {

    case CODEC_TYPE_AUDIO:

        VAR_5 = get_audio_frame_size(VAR_0->codec, VAR_1->size);



        





        if (VAR_5 >= 0 && (VAR_1->size || VAR_0->pts.VAR_3!=VAR_0->pts.VAR_4>>1 || VAR_0->pts.val)) {

            av_frac_add(&VAR_0->pts, (int64_t)VAR_0->time_base.VAR_4 * VAR_5);

        }

        break;

    case CODEC_TYPE_VIDEO:

        av_frac_add(&VAR_0->pts, (int64_t)VAR_0->time_base.VAR_4 * VAR_0->codec->time_base.VAR_3);

        break;

    default:

        break;

    }

    return 0;

}

static int FUNC_0(AVStream *VAR_0, AVPacket *VAR_1){ int VAR_2 = FFMAX(VAR_0->codec->has_b_frames, !!VAR_0->codec->max_b_frames); int VAR_3, VAR_4, VAR_5, VAR_6; if (VAR_1->duration == 0) { compute_frame_duration(&VAR_3, &VAR_4, VAR_0, NULL, VAR_1); if (VAR_4 && VAR_3) { VAR_1->duration = av_rescale(1, VAR_3 * (int64_t)VAR_0->time_base.VAR_4, VAR_4 * (int64_t)VAR_0->time_base.VAR_3); } } if(VAR_1->pts == AV_NOPTS_VALUE && VAR_1->dts != AV_NOPTS_VALUE && VAR_2==0)
VAR_1->pts= VAR_1->dts; if((VAR_1->pts == 0 || VAR_1->pts == AV_NOPTS_VALUE) && VAR_1->dts == AV_NOPTS_VALUE && !VAR_2){ VAR_1->dts=
VAR_1->pts= VAR_0->pts.val; } if(VAR_1->pts != AV_NOPTS_VALUE && VAR_1->dts == AV_NOPTS_VALUE){ VAR_0->pts_buffer[0]= VAR_1->pts; for(VAR_6=1; VAR_6<VAR_2+1 && VAR_0->pts_buffer[VAR_6] == AV_NOPTS_VALUE; VAR_6++) VAR_0->pts_buffer[VAR_6]= (VAR_6-VAR_2-1) * VAR_1->duration; for(VAR_6=0; VAR_6<VAR_2 && VAR_0->pts_buffer[VAR_6] > VAR_0->pts_buffer[VAR_6+1]; VAR_6++) FFSWAP(int64_t, VAR_0->pts_buffer[VAR_6], VAR_0->pts_buffer[VAR_6+1]); VAR_1->dts= VAR_0->pts_buffer[0]; } if(VAR_0->cur_dts && VAR_0->cur_dts != AV_NOPTS_VALUE && VAR_0->cur_dts >= VAR_1->dts){ av_log(VAR_0->codec, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", VAR_0->cur_dts, VAR_1->dts); return -1; } if(VAR_1->dts != AV_NOPTS_VALUE && VAR_1->pts != AV_NOPTS_VALUE && VAR_1->pts < VAR_1->dts){ av_log(VAR_0->codec, AV_LOG_ERROR, "error, pts < dts\n"); return -1; } VAR_0->cur_dts= VAR_1->dts; VAR_0->pts.val= VAR_1->dts; switch (VAR_0->codec->codec_type) { case CODEC_TYPE_AUDIO:
VAR_5 = get_audio_frame_size(VAR_0->codec, VAR_1->size); if (VAR_5 >= 0 && (VAR_1->size || VAR_0->pts.VAR_3!=VAR_0->pts.VAR_4>>1 || VAR_0->pts.val)) { av_frac_add(&VAR_0->pts, (int64_t)VAR_0->time_base.VAR_4 * VAR_5); } break; case CODEC_TYPE_VIDEO:
av_frac_add(&VAR_0->pts, (int64_t)VAR_0->time_base.VAR_4 * VAR_0->codec->time_base.VAR_3); break; default:
break; } return 0; }