[FFmpeg-devel] [PATCH] Keep track of stream duration and nb_frames when muxing

Michael Niedermayer michaelni
Tue Jan 19 16:51:08 CET 2010


On Tue, Jan 19, 2010 at 01:41:57AM -0500, David Conrad wrote:
> On Jan 19, 2010, at 12:25 AM, Baptiste Coudurier wrote:
> 
> > Hi,
> > 
> > On 1/18/10 9:18 PM, David Conrad wrote:
> >> Hi,
> >> 
> >> [...]
> >> 
> >> @@ -2785,6 +2791,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
> >>      if(compute_pkt_fields2(s, st, pkt)<  0&&  !(s->oformat->flags&  AVFMT_NOTIMESTAMPS))
> >>          return -1;
> >> 
> >> +    if (!st->nb_frames)
> >> +        st->start_time = pkt->pts;
> >> +    st->duration = pkt->pts + pkt->duration;
> > 
> > st->duration = FFMAX(st->duration, pkt->pts + pkt->duration);
> > 
> > and same above, is more correct.
> 
> Whoops, fixed
> 

> commit 06137c90d1cbc7b0aba086b954d5781f4ef603bd
> Author: David Conrad <lessen42 at gmail.com>
> Date:   Tue Jan 19 00:08:14 2010 -0500
> 
>     Update stream start_time, duration, and nb_frames in
>     av_(interleaved)_write_frame()
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 64c5ec4..fea28a0 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2668,8 +2668,14 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){
>  
>  int av_write_frame(AVFormatContext *s, AVPacket *pkt)
>  {
> +    AVStream *st = s->streams[pkt->stream_index];
>      int ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
>  
> +    if (!st->nb_frames)
> +        st->start_time = pkt->pts;
> +    st->duration = FFMAX(st->duration, pkt->pts + pkt->duration);
> +    st->nb_frames++;
> +

PTS reordering will break this, youd need something like this

if(pkt->pts != AV_NOPTS_VALUE){
    int64_t end= st->start_time + st->duration;
    st->start_time = FFMIN(st->start_time, pkt->pts);
    st->duration= FFMAX(end, pkt->pts) - st->start_time
}

I also hope this stuff has no performance inpact for audio steams with small
packets


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I wish the Xiph folks would stop pretending they've got something they
do not.  Somehow I fear this will remain a wish. -- M?ns Rullg?rd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100119/f7a587a9/attachment.pgp>



More information about the ffmpeg-devel mailing list