Opened 6 years ago

Last modified 2 years ago

#259 open defect

framerate detection does not work properly. (mkv with default duration != actual average duration)

Reported by: mbosner Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: vc1 pulldown mkv fps
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: yes

Description

Frameratedetection does not work well on some of my files:

ffmpeg -i wrong_framerate.mkv:
[matroska,webm @ 0x276e420] Estimating duration from bitrate, this may be inaccurate
Input #0, matroska,webm, from 'wrong_framerate.mkv':

Duration: 01:47:42.18, start: 0.000000, bitrate: 1984 kb/s

Stream #0.0: Video: vc1 (Advanced), yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 29.97 tbc (default)
Stream #0.1: Audio: eac3, 48000 Hz, 5.1, s16, 1536 kb/s (default)
Stream #0.2: Audio: eac3, 48000 Hz, 5.1, s16, 448 kb/s

At least one output file must be specified

ffmpeg version: git-N-30444-geb5a3ab
correct framerate: 23.98/24 fps
same false framerate detection with latest VLC
xbmc does play it with the correct framerate and does play it without problems.

Change History (12)

comment:1 Changed 6 years ago by mbosner

First 10MB of problematic file:
http://x-ion.de/wrong_framerate.mkv

comment:2 Changed 6 years ago by cehoyos

The sample contains 196 frames, audio plays for ~6.7 seconds.

Could you explain what your problem is? Is ffmpeg -i wrong_framerate.mkv -qscale 2 -acodec ac3 -ab 512k out.avi unable to keep A/V-sync (when you play out.avi)? Is ffplay unable to keep A/V-sync? Or mplayer -demuxer lavf?

And please add complete, uncut output (including the command line) of the failing command - preferably ffmpeg, but if ffmpeg works, and ffplay does not work correctly, please add ffplay output.

If you are seeing a problem with a playback software that is not reproducible with FFmpeg, consider reporting it there.

comment:3 follow-up: Changed 6 years ago by mbosner

The sample file is ofc just the first 10 MB of 17 GB. If you need more please tell me.

Maybe i should explain what i am doing:
I try to batch convert video files using some script code that i wrote. Normaly everything works fine or i can workaround problems. But with this file ffmpeg guesses the wrong frame rate and i convert the file from 24fps to ~29.97fps which lead to stutter movie playback. Audio and Video is in sync. But since i detect the wrong fps with ffmpeg -i i convert it to the wrong framerate:

I am getting informations about the file using ffmpeg:
ffmpeg -i "temporary_filename000.mkv" 2>&1
FFMPEG OUT: ffmpeg version git-N-30444-geb5a3ab, Copyright (c) 2000-2011 the FFmpeg developers
FFMPEG OUT: built on Jun 1 2011 16:42:49 with gcc 4.5.2
FFMPEG OUT: configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid
FFMPEG OUT: libavutil 51. 3. 0 / 51. 3. 0
FFMPEG OUT: libavcodec 53. 6. 1 / 53. 6. 1
FFMPEG OUT: libavformat 53. 2. 0 / 53. 2. 0
FFMPEG OUT: libavdevice 53. 1. 0 / 53. 1. 0
FFMPEG OUT: libavfilter 2. 11. 0 / 2. 11. 0
FFMPEG OUT: libswscale 0. 14. 0 / 0. 14. 0
FFMPEG OUT: libpostproc 51. 2. 0 / 51. 2. 0
FFMPEG OUT: [matroska,webm @ 0x23c5420] Estimating duration from bitrate, this may be inaccurate
FFMPEG OUT: Input #0, matroska,webm, from 'temporary_filename000.mkv':
FFMPEG OUT: Duration: 01:47:42.18, start: 0.000000, bitrate: 1984 kb/s
FFMPEG OUT: Stream #0.0: Video: vc1 (Advanced), yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 29.97 tbc (default)
FFMPEG OUT: Stream #0.1: Audio: eac3, 48000 Hz, 5.1, s16, 1536 kb/s (default)
FFMPEG OUT: Stream #0.2: Audio: eac3, 48000 Hz, 5.1, s16, 448 kb/s
FFMPEG OUT: At least one output file must be specified

i extract the audio(...)

and i convert the video:
ffmpeg -i 'temporary_filename000.mkv' -flags ilme -an -pix_fmt yuv420p -f rawvideo -vcodec rawvideo -| x264 --preset veryslow --fps 29.970 --crf 18 -o track1.mp4 - --input-res 1920x1080

i can playback the original file without problems using xbmc. I am not sure if this is the only file with the problem but it is the first one where i noticed the problem.

comment:4 in reply to: ↑ 3 Changed 6 years ago by cehoyos

  • Keywords vc1 pulldown added; false framerate detection removed
  • Status changed from new to open

Replying to mbosner:

But with this file ffmpeg guesses the wrong frame rate and i convert the file from 24fps to ~29.97fps which lead to stutter movie playback.

Which software shows 24fps for the sample you provided?
mkvinfo reports "29.970 fps"

The heavy stutter that was originally visible on playback and reencoding with every telecined VC1 sample should not be reproducible anymore, but encoding into mp4 still duplicates frames if -r 24 is not used.

This is also reproducible for evo samples that correctly show 23.98 fps

$ ffmpeg -i JerkyVC1Pulldown.EVO -qscale 2 -strict experimental -t 5 out.mp4
ffmpeg version N-33758-gc4e02d3, Copyright (c) 2000-2011 the FFmpeg developers
  built on Oct 18 2011 03:46:14 with gcc 4.5.3
  configuration: --cc=/usr/local/gcc-4.5.3/bin/gcc
  libavutil    51. 21. 0 / 51. 21. 0
  libavcodec   53. 21. 0 / 53. 21. 0
  libavformat  53. 16. 1 / 53. 16. 1
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 43. 7 /  2. 43. 7
  libswscale    2.  1. 0 /  2.  1. 0

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (60000/2002)
Input #0, mpeg, from 'JerkyVC1Pulldown.EVO':
  Duration: 00:00:05.90, start: 0.036744, bitrate: 13875 kb/s
    Stream #0:0[0xfd55]: Video: vc1 (Advanced), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0xc4]: Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s
    Stream #0:2[0xc3]: Audio: eac3, 48000 Hz, 5.1(side), s16, 768 kb/s
    Stream #0:3[0xc2]: Audio: eac3, 48000 Hz, 5.1(side), s16, 768 kb/s
    Stream #0:4[0x89]: Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s
    Stream #0:5[0xc0]: Audio: eac3, 48000 Hz, 5.1(side), s16, 1536 kb/s
[buffer @ 0x1309d60] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[mpeg4 @ 0x1370ca0] removing common factors from framerate
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf53.16.1
    Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30k tbn, 29.97 tbc
    Stream #0:1: Audio: aac (@[0][0][0] / 0x0040), 48000 Hz, 5.1(side), s16, 128 kb/s
Stream mapping:
  Stream #0.0 -> #0.0 (vc1 -> mpeg4)
  Stream #0.2 -> #0.1 (eac3 -> aac)
Press [q] to stop, [?] for help
frame=  150 fps= 45 q=2.0 Lsize=    1971kB time=00:00:05.00 bitrate=3226.0kbits/s dup=30 drop=0
video:1923kB audio:43kB global headers:0kB muxing overhead 0.215599%
$ ffmpeg -i JerkyVC1Pulldown.EVO -qscale 2 -strict experimental -t 5 -r 24 out.mp4
ffmpeg version N-33758-gc4e02d3, Copyright (c) 2000-2011 the FFmpeg developers
  built on Oct 18 2011 03:46:14 with gcc 4.5.3
  configuration: --cc=/usr/local/gcc-4.5.3/bin/gcc
  libavutil    51. 21. 0 / 51. 21. 0
  libavcodec   53. 21. 0 / 53. 21. 0
  libavformat  53. 16. 1 / 53. 16. 1
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 43. 7 /  2. 43. 7
  libswscale    2.  1. 0 /  2.  1. 0

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (60000/2002)
Input #0, mpeg, from 'JerkyVC1Pulldown.EVO':
  Duration: 00:00:05.90, start: 0.036744, bitrate: 13875 kb/s
    Stream #0:0[0xfd55]: Video: vc1 (Advanced), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0xc4]: Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s
    Stream #0:2[0xc3]: Audio: eac3, 48000 Hz, 5.1(side), s16, 768 kb/s
    Stream #0:3[0xc2]: Audio: eac3, 48000 Hz, 5.1(side), s16, 768 kb/s
    Stream #0:4[0x89]: Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s
    Stream #0:5[0xc0]: Audio: eac3, 48000 Hz, 5.1(side), s16, 1536 kb/s
[buffer @ 0x1309360] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf53.16.1
    Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 24 tbn, 24 tbc
    Stream #0:1: Audio: aac (@[0][0][0] / 0x0040), 48000 Hz, 5.1(side), s16, 128 kb/s
Stream mapping:
  Stream #0.0 -> #0.0 (vc1 -> mpeg4)
  Stream #0.2 -> #0.1 (eac3 -> aac)
Press [q] to stop, [?] for help
frame=  120 fps= 39 q=2.0 Lsize=    1817kB time=00:00:05.00 bitrate=2977.6kbits/s
video:1770kB audio:43kB global headers:0kB muxing overhead 0.220256%

comment:5 Changed 5 years ago by michael

http://x-ion.de/wrong_framerate.mkv
is ERROR 404: Not Found.

comment:6 Changed 5 years ago by cehoyos

Samples uploaded to http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket259/
The following command lines do not lead to frame duplication (and smaller files are written) if "-r 24" is used:

$ ffmpeg -i wrong_framerate.mkv -strict -2 -qscale 2 -vframes 196 out1.mov
ffmpeg version N-48375-gc14f8a5 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan  1 2013 16:29:16 with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl --disable-indev=jack
  libavutil      52. 13.100 / 52. 13.100
  libavcodec     54. 85.100 / 54. 85.100
  libavformat    54. 58.102 / 54. 58.102
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 30.102 /  3. 30.102
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from 'wrong_framerate.mkv':
  Metadata:
    creation_time   : 2009-05-12 23:34:50
  Duration: 01:47:42.19, start: 0.000000, bitrate: 12 kb/s
    Stream #0:0: Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
    Stream #0:1: Audio: eac3, 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
    Stream #0:2: Audio: eac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Please use -q:a or -q:v, -qscale is ambiguous
Output #0, mov, to 'out1.mov':
  Metadata:
    encoder         : Lavf54.58.102
    Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30k tbn, 29.97 tbc (default)
    Stream #0:1: Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1(side), fltp, 128 kb/s (default)
Stream mapping:
  Stream #0:0 -> #0:0 (vc1 -> mpeg4)
  Stream #0:1 -> #0:1 (eac3 -> aac)
Press [q] to stop, [?] for help
frame=  196 fps= 63 q=2.0 Lsize=    3522kB time=00:00:06.53 bitrate=4411.3kbits/s dup=42 drop=0
video:3467kB audio:47kB subtitle:0 global headers:0kB muxing overhead 0.223866%
$ ffmpeg -i JerkyVC1Pulldown.EVO -strict -2 -qscale 2 -vframes 178 out.mov
ffmpeg version N-48375-gc14f8a5 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan  1 2013 16:29:16 with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl --disable-indev=jack
  libavutil      52. 13.100 / 52. 13.100
  libavcodec     54. 85.100 / 54. 85.100
  libavformat    54. 58.102 / 54. 58.102
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 30.102 /  3. 30.102
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mpeg, from 'JerkyVC1Pulldown.EVO':
  Duration: 00:00:05.90, start: 0.036744, bitrate: 13875 kb/s
    Stream #0:0[0xfd55]: Video: vc1 (Advanced), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 28.58 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0xc4]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:2[0xc3]: Audio: eac3, 48000 Hz, 5.1(side), fltp, 768 kb/s
    Stream #0:3[0xc2]: Audio: eac3, 48000 Hz, 5.1(side), fltp, 768 kb/s
    Stream #0:4[0x89]: Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s
    Stream #0:5[0xc0]: Audio: eac3, 48000 Hz, 5.1(side), fltp, 1536 kb/s
Please use -q:a or -q:v, -qscale is ambiguous
Output #0, mov, to 'out.mov':
  Metadata:
    encoder         : Lavf54.58.102
    Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30k tbn, 29.97 tbc
    Stream #0:1: Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1(side), fltp, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (vc1 -> mpeg4)
  Stream #0:2 -> #0:1 (eac3 -> aac)
Press [q] to stop, [?] for help
frame=  178 fps= 61 q=2.0 Lsize=    2978kB time=00:00:05.93 bitrate=4107.8kbits/s dup=35 drop=0
video:2918kB audio:53kB subtitle:0 global headers:0kB muxing overhead 0.214350%

comment:7 Changed 4 years ago by michael

  • Analyzed by developer set

This files header states 29.97 as framerate / default duration, libavformat currently blindly believes this value. The actual frame durations are 2 and 3 fields with a field rate of 2*29.97

comment:8 Changed 4 years ago by michael

  • Keywords mkv fps added
  • Summary changed from framerate detection does not work properly. to framerate detection does not work properly. (mkv with default duration != actual average duration)

comment:9 Changed 2 years ago by michael

Is this kind of issue common or is this a rare file ?
the codec stream itself seems to match the default duration which mismatches the timestamps

comment:10 follow-up: Changed 2 years ago by gjdfgh

This happens all the time. The most fun issue I've hit was when the framerate stored in the file was based on a frame duration... rounded to milliseconds. mkvinfo said "Default duration: 42.000ms (23.810 frames/fields per second for a video track)". Even thouhg the file was actually 23.976, and there were frames with 41 ms duration. (Keep in mind that Matroska rounds timestamps to milliseconds.)

But IMO libavformat shouldn't try to guess this. This belongs into a layer somewhere above the decoder. And it would need to be adaptive: what do you do about VFR files?

Also, since such broken files can be remuxed to other formats, other formats can exhibit the same issue. I've seen it e.g. in a HLS stream too.

comment:11 in reply to: ↑ 10 Changed 2 years ago by michael

Replying to gjdfgh:

This happens all the time. The most fun issue I've hit was when the framerate stored in the file was based on a frame duration... rounded to milliseconds. mkvinfo said "Default duration: 42.000ms (23.810 frames/fields per second for a video track)". Even thouhg the file was actually 23.976, and there were frames with 41 ms duration. (Keep in mind that Matroska rounds timestamps to milliseconds.)

But IMO libavformat shouldn't try to guess this. This belongs into a layer somewhere above the decoder. And it would need to be adaptive: what do you do about VFR files?

so what do you suggest ?
just closing this ticket ? (ATM lavf doesnt really guess it trusts the default duration)
and timestamps should be "correct" so a layer above should be fine as long as it doesnt trust the fps

comment:12 Changed 2 years ago by gjdfgh

Persobally I'd vote for separating framerate values stored in the files, and framerate values guessed by utils.c (but my real opinion is that utils.c should never guess anyway). So I'd vote for WONTFIX.

Note: See TracTickets for help on using tickets.