Opened 5 years ago

Closed 5 years ago

#2300 closed defect (fixed)

segment muxer produces files with wrong duration

Reported by: Cigaes Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: segment
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

The duration stored in the headers of the segments produced by the segment demuxer is not consistent with the timestamps of the frames it contains. Example:

./ffmpeg_g -f lavfi -i testsrc=d=20 -f segment -c mpeg4 -map 0 -segment_time 10 -y /tmp/segment%03d.mp4
./ffprobe_g -show_packets -show_format -of compact -show_entries packet=pts_time -show_entries format=duration /tmp/segment000.mp4
./ffprobe_g -show_packets -show_format -of compact -show_entries packet=pts_time -show_entries format=duration /tmp/segment001.mp4
packet|pts_time=9.960000
packet|pts_time=10.000000
packet|pts_time=10.040000
format|duration=10.322000|tag:major_brand=<snip>
packet|pts_time=10.080000
packet|pts_time=10.120000
packet|pts_time=10.160000

As you can see, the timestamps of the segments are consistent, but the duration of the first fragment should be 10.08, that makes a 0.242 error.

The result is correct without the segment muxer:

./ffmpeg_g -f lavfi -i testsrc=d=10.08 -c mpeg4 -map 0 -y /tmp/segment.mp4
./ffprobe_g -show_packets -show_format -of compact -show_entries packet=pts_time -show_entries format=duration /tmp/segment.mp4
packet|pts_time=10.000000
packet|pts_time=10.040000
format|duration=10.080000|tag:major_brand=<snip>

The same problem seems to happen with other formats than MP4, for example Matroska:

packet|pts_time=10.000000
packet|pts_time=10.040000
format|duration=13.640000|tag:ENCODER=Lavf54.63.100

Full (almost) console output of the previous commands (probably not helpful):

./ffmpeg_g -f lavfi -i testsrc=d=20 -f segment -c mpeg4 -map 0 -segment_time 10 -y /tmp/segment%03d.mp4
ffmpeg version N-50194-g0ac71f9 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 23 2013 11:34:47 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libass --enable-libfreetype --enable-libopus --assert-level=2
  libavutil      52. 17.103 / 52. 17.103
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 39.101 /  3. 39.101
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[lavfi @ 0x101c0c0] Estimating duration from bitrate, this may be inaccurate
Input #0, lavfi, from 'testsrc=d=20':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Output #0, segment, to '/tmp/segment%03d.mp4':
  Metadata:
    encoder         : Lavf54.63.100
    Stream #0:0: Video: mpeg4, yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mpeg4)
Press [q] to stop, [?] for help
frame=  500 fps=0.0 q=3.6 Lsize=N/A time=00:00:20.00 bitrate=N/A    
video:742kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.002896%
./ffprobe_g -show_packets -show_format -of compact -show_entries packet=pts_time -show_entries format=duration /tmp/segment000.mp4
ffprobe version N-50194-g0ac71f9 Copyright (c) 2007-2013 the FFmpeg developers
  built on Feb 23 2013 11:34:47 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libass --enable-libfreetype --enable-libopus --assert-level=2
  libavutil      52. 17.103 / 52. 17.103
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 39.101 /  3. 39.101
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/segment000.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf54.63.100
  Duration: 00:00:10.32, start: 0.000000, bitrate: 313 kb/s
    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 312 kb/s, 24.42 fps, 25 tbr, 12800 tbn, 25 tbc
    Metadata:
      handler_name    : VideoHandler
packet|pts_time=0.000000
packet|pts_time=0.040000
packet|pts_time=0.080000
packet|pts_time=0.120000
...
packet|pts_time=9.880000
packet|pts_time=9.920000
packet|pts_time=9.960000
packet|pts_time=10.000000
packet|pts_time=10.040000
format|duration=10.322000|tag:major_brand=isom|tag:minor_version=512|tag:compatible_brands=isomiso2mp41|tag:encoder=Lavf54.63.100
./ffmpeg_g -f lavfi -i testsrc=d=10.08 -c mpeg4 -map 0 -y /tmp/segment.mp4
ffmpeg version N-50194-g0ac71f9 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 23 2013 11:34:47 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libass --enable-libfreetype --enable-libopus --assert-level=2
  libavutil      52. 17.103 / 52. 17.103
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 39.101 /  3. 39.101
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[lavfi @ 0x10b8000] Estimating duration from bitrate, this may be inaccurate
Input #0, lavfi, from 'testsrc=d=10.08':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Output #0, mp4, to '/tmp/segment.mp4':
  Metadata:
    encoder         : Lavf54.63.100
    Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 12800 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mpeg4)
Press [q] to stop, [?] for help
frame=  252 fps=0.0 q=2.7 Lsize=     396kB time=00:00:10.08 bitrate= 321.5kbits/s    
video:394kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.471736%
./ffprobe_g -show_packets -show_format -of compact -show_entries packet=pts_time -show_entries format=duration /tmp/segment.mp4
ffprobe version N-50194-g0ac71f9 Copyright (c) 2007-2013 the FFmpeg developers
  built on Feb 23 2013 11:34:47 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --enable-shared --disable-static --enable-gpl --enable-libx264 --enable-libass --enable-libfreetype --enable-libopus --assert-level=2
  libavutil      52. 17.103 / 52. 17.103
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 39.101 /  3. 39.101
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/segment.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf54.63.100
  Duration: 00:00:10.08, start: 0.000000, bitrate: 321 kb/s
    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 319 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc
    Metadata:
      handler_name    : VideoHandler
packet|pts_time=0.000000
packet|pts_time=0.040000
packet|pts_time=0.080000
...
packet|pts_time=9.960000
packet|pts_time=10.000000
packet|pts_time=10.040000
format|duration=10.080000|tag:major_brand=isom|tag:minor_version=512|tag:compatible_brands=isomiso2mp41|tag:encoder=Lavf54.63.100

Change History (1)

comment:1 Changed 5 years ago by cehoyos

  • Reproduced by developer set
  • Resolution set to fixed
  • Status changed from new to closed

Fixed by Nicolas.

Note: See TracTickets for help on using tickets.