Opened 4 years ago

Last modified 4 years ago

#3251 new defect

Since version 1.1 ffmpeg produces DNxHD files with wrong codec time base.

Reported by: martastain Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords: dnxhd mov
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Version 1.0.8 is the latest stable unaffected by this behaviour. Let's create DNxHD QuickTime? from png sequence:

root@dcore:~$ ffmpeg -i render/test%04d.png -s 1920x1080 -r 25 -pix_fmt yuv422p -c:v dnxhd -b:v 120M -an test.mov
ffmpeg version 1.0.8 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct 31 2013 13:06:33 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --prefix= --enable-libmp3lame --enable-librtmp --enable-libx264 --enable-libfaac --enable-libvorbis --enable-pic --enable-shared --enable-gpl --enable-nonfree --enable-libtheora
  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, image2, from 'render/test%04d.png':
  Duration: 00:00:10.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgb24, 1920x1080, 25 fps, 25 tbr, 25 tbn, 25 tbc
Output #0, mov, to 'test.mov':
  Metadata:
    encoder         : Lavf54.29.104
    Stream #0:0: Video: dnxhd (AVdn / 0x6E645641), yuv422p, 1920x1080, q=2-1024, 120000 kb/s, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png -> dnxhd)
Press [q] to stop, [?] for help
frame=  250 fps= 20 q=1.0 Lsize=  148002kB time=00:00:10.00 bitrate=121243.1kbits/s
video:148000kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.001243%

root@dcore:~$ ffprobe test.mov
ffprobe version 1.0.8 Copyright (c) 2007-2013 the FFmpeg developers
  built on Oct 31 2013 13:06:33 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --prefix= --enable-libmp3lame --enable-librtmp --enable-libx264 --enable-libfaac --enable-libvorbis --enable-pic --enable-shared --enable-gpl --enable-nonfree --enable-libtheora
  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf54.29.104
  Duration: 00:00:10.00, start: 0.000000, bitrate: 121243 kb/s
    Stream #0:0(eng): Video: dnxhd (AVdn / 0x6E645641), yuv422p, 1920x1080, 121241 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Metadata:
      handler_name    : DataHandler

You can see the resulting mov file has fps = tbr = tbn = tbc = 25 as expected. If you run the same command with ffmpeg >= 1.1, resulting file is different:

root@magrathea:~# ffmpeg -i render/test%04d.png -s 1920x1080 -r 25 -pix_fmt yuv422p -c:v dnxhd -b:v 120M -an test.mov
ffmpeg version 1.1.7 Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 18 2013 12:09:08 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --prefix= --enable-libmp3lame --enable-librtmp --enable-libx264 --enable-libfaac --enable-libvorbis --enable-pic --enable-shared --enable-gpl --enable-nonfree --enable-libtheora
  libavutil      52. 13.100 / 52. 13.100
  libavcodec     54. 86.100 / 54. 86.100
  libavformat    54. 59.106 / 54. 59.106
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 32.100 /  3. 32.100
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, image2, from 'render/test%04d.png':
  Duration: 00:00:10.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgb24, 1920x1080 [SAR 2835:2835 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Output #0, mov, to 'test.mov':
  Metadata:
    encoder         : Lavf54.59.106
    Stream #0:0: Video: dnxhd (AVdn / 0x6E645641), yuv422p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-1024, 120000 kb/s, 12800 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png -> dnxhd)
Press [q] to stop, [?] for help
frame=  250 fps= 16 q=1.0 Lsize=  148002kB time=00:00:10.00 bitrate=121243.1kbits/s
video:148000kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.001243%

You can see, that tbn and tbc values differ - they are always 12800 instead of expected 25. This issue is still present in latest git version and can be reproduced also using zeranoe builds.

Change History (13)

comment:1 Changed 4 years ago by cehoyos

  • Component changed from FFmpeg to undetermined
  • Keywords timebase quicktime removed

What is wrong with the different timebase?

comment:2 follow-ups: Changed 4 years ago by martastain

  • Avid Media Composer (and generally QuickTime? based applications with Avid codec) creates files with timebase 25.
  • CasparCG server (casparcg.com) cannot seek in files /w tbc=12800

comment:3 in reply to: ↑ 2 Changed 4 years ago by michael

Replying to martastain:

  • Avid Media Composer (and generally QuickTime? based applications with Avid codec) creates files with timebase 25.
  • CasparCG server (casparcg.com) cannot seek in files /w tbc=12800

So you are saying CasparCG server is buggy and you want us to workaround that?
Or is there some specification or other official document that says that specific mov files must contain a specific timebase? if so which spec, which specific cases and which specific timebases are that ? (iam asking as without that knowledge working around that is hard)

comment:4 follow-up: Changed 4 years ago by kierank

If the user asks for a timebase of 25 they should get a timebase of 25, no? He/she's just making the point that applications don't like this weird timebase.

comment:5 Changed 4 years ago by martastain

I am just saying, that ffmpeg behavior has changed in the way, which causes a problem.
As previous versions worked in the same fashion as (as far as i know) official (Avid) implementation, I believe, this may be a bug.

comment:6 in reply to: ↑ 2 ; follow-up: Changed 4 years ago by cehoyos

Replying to martastain:

  • CasparCG server (casparcg.com) cannot seek in files /w tbc=12800

Can you confirm that seeking works if you only change the output timebase?

comment:7 in reply to: ↑ 6 Changed 4 years ago by martastain

Replying to cehoyos:

Can you confirm that seeking works if you only change the output timebase?

Yes, tested with latest stable (CasparCG 2.0.4) as well as previous (2.0.3). My test files are here http://nxme.eu/1j along with ffprobe results.

test_108.mov - ffmpeg 1.0.8
test_latest.mov - latest git version
test_avid.mov - Avid MediaComposer? 7.0.2 (there are also audio and timecode tracks)

CasparCG command "PLAY 1-1 filename SEEK 250" should play video file from 10th second, which works with test_108.mov and test_avid.mov.
test_latest.mov as well as every file created using ffmpeg >= 1.1 starts from the first frame.

Only difference I can see with ffprobe is timebase.

comment:8 follow-up: Changed 4 years ago by cehoyos

Sorry, what I meant was: Does seeking work if you force the timescale to 25 with -video_track_timescale?

$ ffmpeg -i render/test%04d.png -s 1920x1080 -r 25 -pix_fmt yuv422p -c:v dnxhd -b:v 120M -an -video_track_timescale 25 test.mov

comment:9 in reply to: ↑ 8 Changed 4 years ago by martastain

Replying to cehoyos:

Sorry, what I meant was: Does seeking work if you force the timescale to 25 with -video_track_timescale?

$ ffmpeg -i render/test%04d.png -s 1920x1080 -r 25 -pix_fmt yuv422p -c:v dnxhd -b:v 120M -an -video_track_timescale 25 test.mov

Perfect! This works great with 2.1.1 as well as latest zeranoe build. I guess I can modify my encoding profiles this way, but I still believe, this should be done as default while using -r parameter.

Thanks a lot anyway! I should dig into a source code and not just rely on documentation. I've never heard about this parameter before :-/

comment:10 Changed 4 years ago by cehoyos

Could you test (or do you know from looking at a known good file with ffmpeg -i ) what the correct video_track_timescale is for 23.97 fps and 29.97 fps?

comment:11 Changed 4 years ago by martastain

Hello,
These are results for files created using Avid MediaComposer?'s "Export same as source" profile from 23.976 and 29.97 based projects.

23.976

c:\martas>ffprobe 23976dnx.mov
ffprobe version N-59137-gf618cb1 Copyright (c) 2007-2013 the FFmpeg developers
  built on Dec 15 2013 22:06:11 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 58.100 / 52. 58.100
  libavcodec     55. 45.101 / 55. 45.101
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     3. 92.100 /  3. 92.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2397dnx.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2014-01-24 12:47:58
  Duration: 00:00:30.03, start: 0.000000, bitrate: 37676 kb/s
    Stream #0:0(eng): Video: dnxhd (AVdn / 0x6E645641), yuv422p, 1920x1080, 3613
9 kb/s, 23.98 fps, 23.98 tbr, 23976 tbn, 23976 tbc (default)
    Metadata:
      creation_time   : 2014-01-24 12:47:58
      handler_name    : Apple Alias Data Handler
    Stream #0:1(eng): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, 2 channels
, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2014-01-24 12:47:58
      handler_name    : Apple Alias Data Handler

29.97

c:\martas>ffprobe 2997.mov
ffprobe version N-59137-gf618cb1 Copyright (c) 2007-2013 the FFmpeg developers
  built on Dec 15 2013 22:06:11 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 58.100 / 52. 58.100
  libavcodec     55. 45.101 / 55. 45.101
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     3. 92.100 /  3. 92.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 00000000026e3960] Stream #1: not enough frames to est
imate rate; consider increasing probesize
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2997.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2014-01-24 12:52:24
  Duration: 00:00:30.03, start: 0.000000, bitrate: 74209 kb/s
    Stream #0:0(eng): Video: dnxhd (AVdn / 0x6E645641), yuv422p, 1280x720, 72672
 kb/s, 29.97 fps, 29.97 tbr, 29970 tbn, 29970 tbc (default)
    Metadata:
      creation_time   : 2014-01-24 12:52:24
      handler_name    : Apple Alias Data Handler
    Stream #0:1(eng): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, 2 channels
, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2014-01-24 12:52:24
      handler_name    : Apple Alias Data Handler

comment:12 Changed 4 years ago by cehoyos

These files work fine with CasparCG?
(I ask because they have larger timescales than 25fps files written with FFmpeg by default.)

comment:13 in reply to: ↑ 4 Changed 4 years ago by michael

Replying to kierank:

If the user asks for a timebase of 25 they should get a timebase of 25, no?

yes but he is asking for a frame rate of 25 not a timebase

He/she's just making the point that applications don't like this weird timebase.

The problem is with a timebase of 1/25 audio and video frames cant be synced more precissely than within 1/25 sec. (yes some user did complain about this and no edit lists didnt work)
It would be interresting to know if theres a timebase thats more precisse than 1/25 and still works with all applications

Last edited 4 years ago by michael (previous) (diff)
Note: See TracTickets for help on using tickets.