int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf, 

                   int size)

{

    AVStream *st;

    int64_t pts_mask;

    int ret, frame_size;



    st = s->streams[stream_index];

    pts_mask = (1LL << s->pts_wrap_bits) - 1;

    ret = s->oformat->write_packet(s, stream_index, buf, size, 

                                   st->pts.val & pts_mask);

    if (ret < 0)

        return ret;



    /* update pts */

    switch (st->codec.codec_type) {

    case CODEC_TYPE_AUDIO:

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



        /* note, 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 */

//        av_log(s, AV_LOG_DEBUG, "%d %lld %lld\n", size, st->pts.num, st->pts.val);

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

            av_frac_add(&st->pts, 

                        (int64_t)s->pts_den * frame_size);

        }

        break;

    case CODEC_TYPE_VIDEO:

        av_frac_add(&st->pts, 

                    (int64_t)s->pts_den * st->codec.frame_rate_base);

        break;

    default:

        break;

    }

    return ret;

}

int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf, 

                   int size)

{

    AVStream *st;

    int64_t pts_mask;

    int ret, frame_size;



    st = s->streams[stream_index];

    pts_mask = (1LL << s->pts_wrap_bits) - 1;

    ret = s->oformat->write_packet(s, stream_index, buf, size, 

                                   st->pts.val & pts_mask);

    if (ret < 0)

        return ret;



    

    switch (st->codec.codec_type) {

    case CODEC_TYPE_AUDIO:

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



        





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

            av_frac_add(&st->pts, 

                        (int64_t)s->pts_den * frame_size);

        }

        break;

    case CODEC_TYPE_VIDEO:

        av_frac_add(&st->pts, 

                    (int64_t)s->pts_den * st->codec.frame_rate_base);

        break;

    default:

        break;

    }

    return ret;

}

int FUNC_0(AVFormatContext *VAR_0, int VAR_1, const uint8_t *VAR_2, 

                   int VAR_3)

{

    AVStream *st;

    int64_t pts_mask;

    int VAR_4, VAR_5;



    st = VAR_0->streams[VAR_1];

    pts_mask = (1LL << VAR_0->pts_wrap_bits) - 1;

    VAR_4 = VAR_0->oformat->write_packet(VAR_0, VAR_1, VAR_2, VAR_3, 

                                   st->pts.val & pts_mask);

    if (VAR_4 < 0)

        return VAR_4;



    

    switch (st->codec.codec_type) {

    case CODEC_TYPE_AUDIO:

        VAR_5 = get_audio_frame_size(&st->codec, VAR_3);



        





        if (VAR_5 >= 0 && (VAR_3 || st->pts.num!=st->pts.den>>1 || st->pts.val)) {

            av_frac_add(&st->pts, 

                        (int64_t)VAR_0->pts_den * VAR_5);

        }

        break;

    case CODEC_TYPE_VIDEO:

        av_frac_add(&st->pts, 

                    (int64_t)VAR_0->pts_den * st->codec.frame_rate_base);

        break;

    default:

        break;

    }

    return VAR_4;

}

int FUNC_0(AVFormatContext *VAR_0, int VAR_1, const uint8_t *VAR_2,
int VAR_3)
{ AVStream *st; int64_t pts_mask; int VAR_4, VAR_5; st = VAR_0->streams[VAR_1]; pts_mask = (1LL << VAR_0->pts_wrap_bits) - 1; VAR_4 = VAR_0->oformat->write_packet(VAR_0, VAR_1, VAR_2, VAR_3,
st->pts.val & pts_mask); if (VAR_4 < 0)
return VAR_4; switch (st->codec.codec_type) { case CODEC_TYPE_AUDIO:
VAR_5 = get_audio_frame_size(&st->codec, VAR_3); if (VAR_5 >= 0 && (VAR_3 || st->pts.num!=st->pts.den>>1 || st->pts.val)) { av_frac_add(&st->pts,
(int64_t)VAR_0->pts_den * VAR_5); } break; case CODEC_TYPE_VIDEO:
av_frac_add(&st->pts,
(int64_t)VAR_0->pts_den * st->codec.frame_rate_base); break; default:
break; } return VAR_4; }