Opened 5 years ago

Last modified 5 years ago

#2481 new enhancement

libavformat doesn't update file duration when file size changes during playback

Reported by: gjdfgh Owned by:
Priority: normal Component: avformat
Version: unspecified Keywords: duration
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


I would expect that libavformat updates AVFormatContext.duration when the size of the opened file changes, e.g. when playing partial files that are downloading.

This should work for all file formats or cases where the file duration is estimated from the size.

I tested with getting the first 10 MB of an avi file, starting a player using libavformat (mplayer based), then appending the next 30 MB to that file while the player was running. The AVFormatContext.duration field didn't change, and always contained the initial estimate.

Unfortunately this can't be reproduced with ffplay, it doesn't show the duration in its status line. Likewise, the ffmpeg program doesn't seem to show it anywhere.

Change History (5)

comment:1 Changed 5 years ago by cehoyos

  • Keywords duration added

Is this reproducible with mplayer -demuxer lavf ?

comment:2 Changed 5 years ago by gjdfgh

Is this reproducible with mplayer -demuxer lavf ?


comment:3 Changed 5 years ago by michael

This is not so easy to fix, as getting the filesize can be expensive (for example with anything remote like ftp/http or even a remotely mounted fs) so one cannot just check the new filesize unconditionally per packet

comment:4 Changed 5 years ago by gjdfgh

You could do it every few packets (or a similar heuristic to reduce load), or you could add a new API function that requests duration recalculation.

comment:5 Changed 5 years ago by gjdfgh

Actually, looking at the sources for http and ftp, maybe you can assume getting the size is a fast operation. In these two protocols, they return a value stored in a variable without doing any network operations.

Note: See TracTickets for help on using tickets.