Opened 2 weeks ago

Last modified 2 weeks ago

#6703 new defect

ffmpeg rounds duration_ts and duration

Reported by: mucikiki Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: mov edts duration regression
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

if you use NTSC videos (29.97fps), duration_ts and duration are rounded, so codec_time_base is wrong.

For example, if input video has duration=74.574500, it become duration=74.575000 (note the last 3 zeros), if duration=60.093367 it become duration=60.094000.

How to reproduce:

/usr/local/bin/ffmpeg -i input.mp4 -r ntsc -c:v libx264 -profile:v main -level:v 3.1 -crf 18 output.mp4

ffmpeg version N-85647-g59d219b
built with gcc 4.9.2 (Debian 4.9.2-10)

Attachments (4)

test1.mp4 (36.1 KB) - added by mucikiki 2 weeks ago.
test2.mp4 (13.8 KB) - added by mucikiki 2 weeks ago.
test1concat.mp4 (51.0 KB) - added by mucikiki 2 weeks ago.
test2concat.mp4 (26.7 KB) - added by mucikiki 2 weeks ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 2 weeks ago by cehoyos

  • Keywords ntsc duration duration_ts codec_time_base removed

Please provide the command line you tested together with the complete, uncut console output and explain how we can reproduce the issue you see. Please attach an input sample.

Changed 2 weeks ago by mucikiki

Changed 2 weeks ago by mucikiki

comment:2 Changed 2 weeks ago by mucikiki

Yes, this is the command, with the complete output:

/usr/local/bin/ffmpeg -i /var/www/html/1/download/test1.mp4 -c:v libx264 -profile:v main -level:v 3.1 -crf 18 /var/www/html/1/download/test2.mp4
ffmpeg version N-85647-g59d219b Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      55. 61.100 / 55. 61.100
  libavcodec     57. 93.100 / 57. 93.100
  libavformat    57. 72.101 / 57. 72.101
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 87.100 /  6. 87.100
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/1/download/test1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2017-09-30T12:49:58.000000Z
  Duration: 00:00:06.24, start: 0.000000, bitrate: 47 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 30 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2017-09-30T12:49:58.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x3c858a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x3c858a0] profile Main, level 3.1
[libx264 @ 0x3c858a0] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/var/www/html/1/download/test2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf57.72.101
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
    Metadata:
      creation_time   : 2017-09-30T12:49:58.000000Z
      handler_name    : Alias Data Handler
      encoder         : Lavc57.93.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=  187 fps=126 q=-1.0 Lsize=      14kB time=00:00:06.13 bitrate=  18.3kbits/s speed=4.13x    
video:11kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 27.948391%
[libx264 @ 0x3c858a0] frame I:1     Avg QP: 5.78  size:  1351
[libx264 @ 0x3c858a0] frame P:47    Avg QP:10.86  size:    63
[libx264 @ 0x3c858a0] frame B:139   Avg QP:10.70  size:    43
[libx264 @ 0x3c858a0] consecutive B-frames:  0.5%  1.1%  0.0% 98.4%
[libx264 @ 0x3c858a0] mb I  I16..4: 99.3%  0.0%  0.7%
[libx264 @ 0x3c858a0] mb P  I16..4:  0.1%  0.0%  0.0%  P16..4:  0.1%  0.0%  0.0%  0.0%  0.0%    skip:99.7%
[libx264 @ 0x3c858a0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.1%  0.0%  0.0%  direct: 0.0%  skip:99.9%  L0:29.0% L1:71.0% BI: 0.0%
[libx264 @ 0x3c858a0] coded y,uvDC,uvAC intra: 0.3% 3.8% 0.9% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x3c858a0] i16 v,h,dc,p: 93%  6%  2%  0%
[libx264 @ 0x3c858a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 22% 42%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x3c858a0] i8c dc,h,v,p: 76%  6% 18%  0%
[libx264 @ 0x3c858a0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x3c858a0] ref P L0: 81.7%  0.6% 17.1%  0.6%
[libx264 @ 0x3c858a0] ref B L0: 51.6% 48.4%
[libx264 @ 0x3c858a0] ref B L1: 99.6%  0.4%
[libx264 @ 0x3c858a0] kb/s:13.25

And these are both durations (obtained via ffprobe):

ffprobe -show_streams -i "/var/www/html/1/download/test1.mp4"

duration=6.239567

ffprobe -show_streams -i "/var/wwwt/html/1/download/test2.mp4"

duration=6.240000

You can find both videos attached.

comment:3 Changed 2 weeks ago by mucikiki

You can also see the duration in this way:

root@Debian2:/home/t2s4e0p# ffprobe /var/www/html/1/download/test2.mp4 -show_entries format=duration -v 0

[FORMAT]
duration=6.240000
[/FORMAT]

root@Debian2:/home/t2s4e0p# ffprobe /var/www/html/1/download/test1.mp4 -show_entries format=duration -v 0

[FORMAT]
duration=6.239567
[/FORMAT]

comment:4 Changed 2 weeks ago by cehoyos

  • Component changed from undetermined to avformat
  • Keywords mov edts duration regression added
  • Version changed from unspecified to git-master

As described above, this is a regression since a53201879ca36af6fcc8a0d4bcc1fa6d759b67ec but I don't know if the file has an issue or if the shown duration is wrong (or if there was a bug that is fixed now).

comment:5 Changed 2 weeks ago by mucikiki

I try to concat test1.mp4 with themself, and to concat test2.mp4 with themself, and I check both videos with MediaInfo? (to have a different point of view).

With test1concat.mp4, the frame rate mode is still Costant, but with test2concat.mp4 is now Variable:

Frame rate : 29.970 (29970/1000) FPS
Minimum frame rate : 29.586 FPS
Maximum frame rate : 29.970 FPS

So I think this is an issue of the file.

Changed 2 weeks ago by mucikiki

Changed 2 weeks ago by mucikiki

comment:6 Changed 2 weeks ago by mucikiki

First concat:

/usr/local/bin/ffmpeg -f concat -i /var/www/html/1/download/test-1-2.txt -c copy /var/www/html/1/download/test1concat.mp4
ffmpeg version N-85647-g59d219b Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      55. 61.100 / 55. 61.100
  libavcodec     57. 93.100 / 57. 93.100
  libavformat    57. 72.101 / 57. 72.101
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 87.100 /  6. 87.100
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3912a20] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from '/var/www/html/1/download/test-1-2.txt':
  Duration: N/A, start: 0.000000, bitrate: 30 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 30 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc
    Metadata:
      creation_time   : 2017-09-30T12:49:58.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
Output #0, mp4, to '/var/www/html/1/download/test1concat.mp4':
  Metadata:
    encoder         : Lavf57.72.101
    Stream #0:0(eng): Video: h264 (Main) ([33][0][0][0] / 0x0021), yuv420p(tv, bt709), 1280x720, q=2-31, 30 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc
    Metadata:
      creation_time   : 2017-09-30T12:49:58.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x39182c0] Auto-inserting h264_mp4toannexb bitstream filter
frame=  374 fps=0.0 q=-1.0 Lsize=      51kB time=00:00:12.41 bitrate=  33.7kbits/s speed=1.17e+03x    
video:47kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.141509%

Second concat:

root@Debian2:/home/t2s4e0p# /usr/local/bin/ffmpeg -f concat -i /var/www/html/1/download/test-1-2b.txt -c copy /var/www/html/1/download/test2concat.mp4
ffmpeg version N-85647-g59d219b Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      55. 61.100 / 55. 61.100
  libavcodec     57. 93.100 / 57. 93.100
  libavformat    57. 72.101 / 57. 72.101
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 87.100 /  6. 87.100
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2dcea20] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from '/var/www/html/1/download/test-1-2b.txt':
  Duration: N/A, start: 0.000000, bitrate: 14 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720, 14 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc
    Metadata:
      handler_name    : VideoHandler
Output #0, mp4, to '/var/www/html/1/download/test2concat.mp4':
  Metadata:
    encoder         : Lavf57.72.101
    Stream #0:0(eng): Video: h264 (Main) ([33][0][0][0] / 0x0021), yuv420p, 1280x720, q=2-31, 14 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2df9180] Auto-inserting h264_mp4toannexb bitstream filter
frame=  374 fps=0.0 q=-1.0 Lsize=      27kB time=00:00:12.37 bitrate=  17.7kbits/s speed=1.57e+03x    
video:21kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 24.252748%

I noticed a great difference in muxing overhead, maybe it can be useful.

comment:7 Changed 2 weeks ago by mucikiki

Last thing, I also test the newer version of ffmpeg, with same results:

ffmpeg version N-87628-g148c8e8 Copyright (c) 2000-2017 the FFmpeg developers

built with gcc 6.3.0 (Debian 6.3.0-18) 20170516
configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 55. 77.101 / 55. 77.101
libavcodec 57.106.104 / 57.106.104
libavformat 57. 82.102 / 57. 82.102
libavdevice 57. 9.101 / 57. 9.101
libavfilter 6.106.100 / 6.106.100
libswscale 4. 7.103 / 4. 7.103
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100

comment:8 Changed 2 weeks ago by mucikiki

I finally found a workaround, if I use concat protocol everything is ok, the error is only related to concat demuxer.

Note: See TracTickets for help on using tickets.