Ticket #2245 (closed enhancement: fixed)
Speed difference when using -ss on similar MKVs when extracting frame image
| Reported by: | eelco | Owned by: | |
|---|---|---|---|
| Priority: | wish | Component: | avformat |
| Version: | git-master | Keywords: | h264 mkv |
| Cc: | Blocked By: | ||
| Blocking: | Reproduced by developer: | no | |
| Analyzed by developer: | no |
Description
Summary of the bug:
When using -ss on the input file, some MKVs are significantly slower than others, while they’re the same resolution. I would expect a small speed difference due to encoding differences, but in this case it’s about 6-8 times.
How to reproduce:
> time ./ffmpeg "-ss" "10" "-i" ~/Desktop/ffmpeg-ss-bug/slow-ss.mkv "-f" "image2" "-vframes" "1" /dev/null
ffmpeg version N-49666-g4745194 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 7 2013 10:22:14 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --prefix=/Users/eelco/Projects/Beamer/FFmpeg/build --enable-gpl --enable-version3 --enable-libx264 --disable-shared --enable-static --enable-libtheora --enable-libvorbis --enable-libvo-aacenc --disable-doc --extra-cflags='-DMACOSX_DEPLOYMENT_TARGET=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -I/Users/eelco/Projects/Beamer/FFmpeg/build/include' --extra-ldflags='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -L/Users/eelco/Projects/Beamer/FFmpeg/build/lib'
libavutil 52. 17.101 / 52. 17.101
libavcodec 54. 91.101 / 54. 91.101
libavformat 54. 61.104 / 54. 61.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 35.101 / 3. 35.101
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, matroska,webm, from '/Users/eelco/Desktop/ffmpeg-ss-bug/slow-ss.mkv':
Metadata:
ENCODER : Lavf54.59.106
Duration: 00:00:11.22, start: 0.000000, bitrate: 9890 kb/s
Chapter #0.0: start 0.000000, end 11.000000
Metadata:
title : 00:00:00.000
Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: truehd, 48000 Hz, 7.1, s32 (default)
Metadata:
title : English TRUE-HD
LANGUAGE : eng
Output #0, image2, to '/dev/null':
Metadata:
encoder : Lavf54.61.104
Chapter #0.0: start 0.000000, end 1.000000
Metadata:
title : 00:00:00.000
Stream #0:0(eng): Video: mjpeg, yuvj420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 23.98 tbc (default)
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> mjpeg)
Press [q] to stop, [?] for help
frame= 1 fps=0.4 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A dup=0 drop=236
video:50kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.043320%
2.41 real 5.94 user 0.10 sys
VS.
> time ./ffmpeg "-ss" "10" "-i" ~/Desktop/ffmpeg-ss-bug/fast-ss.mkv "-f" "image2" "-vframes" "1" /dev/null
ffmpeg version N-49666-g4745194 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 7 2013 10:22:14 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --prefix=/Users/eelco/Projects/Beamer/FFmpeg/build --enable-gpl --enable-version3 --enable-libx264 --disable-shared --enable-static --enable-libtheora --enable-libvorbis --enable-libvo-aacenc --disable-doc --extra-cflags='-DMACOSX_DEPLOYMENT_TARGET=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -I/Users/eelco/Projects/Beamer/FFmpeg/build/include' --extra-ldflags='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -L/Users/eelco/Projects/Beamer/FFmpeg/build/lib'
libavutil 52. 17.101 / 52. 17.101
libavcodec 54. 91.101 / 54. 91.101
libavformat 54. 61.104 / 54. 61.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 35.101 / 3. 35.101
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, matroska,webm, from '/Users/eelco/Desktop/ffmpeg-ss-bug/fast-ss.mkv':
Metadata:
MAJOR_BRAND : qt
MINOR_VERSION : 537199360
COMPATIBLE_BRANDS: qt
TIMECODE : 00:00:00:00
ENCODER : Lavf54.59.106
Duration: 00:00:11.08, start: 0.000000, bitrate: 14054 kb/s
Stream #0:0(eng): Video: h264 (Main), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 1k tbn, 2k tbc (default)
Metadata:
CREATION_TIME : 2008-05-27 18:40:35
LANGUAGE : eng
HANDLER_NAME : Apple Alias Data Handler
Stream #0:1(eng): Audio: aac, 48000 Hz, 5.1, fltp (default)
Metadata:
CREATION_TIME : 2008-05-27 18:40:35
LANGUAGE : eng
HANDLER_NAME : Apple Alias Data Handler
Output #0, image2, to '/dev/null':
Metadata:
MAJOR_BRAND : qt
MINOR_VERSION : 537199360
COMPATIBLE_BRANDS: qt
TIMECODE : 00:00:00:00
encoder : Lavf54.61.104
Stream #0:0(eng): Video: mjpeg, yuvj420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 24 tbc (default)
Metadata:
CREATION_TIME : 2008-05-27 18:40:35
LANGUAGE : eng
HANDLER_NAME : Apple Alias Data Handler
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> mjpeg)
Press [q] to stop, [?] for help
frame= 1 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A dup=0 drop=21
video:205kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.010488%
0.42 real 0.70 user 0.07 sys
I’ll upload the sample files to the FTP server.
Change History
comment:2 Changed 3 months ago by cehoyos
- Keywords h264 mkv added
- Status changed from new to closed
- Resolution set to invalid
The "slow" sample has one keyframe (at 0:00) before your desired seeking end-point, the "fast" sample has eleven, one of them less than half a second before your seeking destination. In both cases, frames have to be decoded to be able to decode the frame that you want to seek to, in one case ~10, in the other ~250.
I don't think this can be "fixed".
comment:3 Changed 3 months ago by eelco
Interesting. I hadn’t looked at that yet. I saw that the “slow” sample also has a keyframe at ~10.5 seconds and seeking to 11 seconds is indeed fast. However, when I try the same on the original file, it is still slow. (I created the slow file using the -t option and using the copy codec.)
I’ve created a new sample with dd that does have the same problem as the original file though.
This is the keyframe information:
> ./ffprobe -of compact -show_frames ~/Desktop/ffmpeg-ss-bug/2245-slow-ss-dd.mkv | grep 'video|key_frame=1' ... (still the same ffmpeg version) frame|media_type=video|key_frame=1|pkt_pts=0|pkt_pts_time=0.000000|pkt_dts=0|pkt_dts_time=0.000000|pkt_duration=N/A|pkt_duration_time=N/A|pkt_pos=6670|pkt_size=148182|width=1920|height=1080|pix_fmt=yuv420p|sample_aspect_ratio=1:1|pict_type=I|coded_picture_number=0|display_picture_number=0|interlaced_frame=0|top_field_first=0|repeat_pict=0|reference=3 frame|media_type=video|key_frame=1|pkt_pts=10427|pkt_pts_time=10.427000|pkt_dts=10427|pkt_dts_time=10.427000|pkt_duration=41|pkt_duration_time=0.041000|pkt_pos=13743718|pkt_size=99527|width=1920|height=1080|pix_fmt=yuv420p|sample_aspect_ratio=1:1|pict_type=I|coded_picture_number=250|display_picture_number=0|interlaced_frame=0|top_field_first=0|repeat_pict=0|reference=3
Since there is a keyframe at 10.427, I’d expect getting the image at 11 seconds would be pretty fast, but it isn’t:
time ./ffmpeg "-ss" "11" "-i" ~/Desktop/ffmpeg-ss-bug/2245-slow-ss-dd.mkv "-f" "image2" "-vframes" "1" /dev/null
ffmpeg version N-49666-g4745194 Copyright (c) 2000-2013 the FFmpeg developers
built on Feb 7 2013 10:22:14 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --prefix=/Users/eelco/Projects/Beamer/FFmpeg/build --enable-gpl --enable-version3 --enable-libx264 --disable-shared --enable-static --enable-libtheora --enable-libvorbis --enable-libvo-aacenc --disable-doc --extra-cflags='-DMACOSX_DEPLOYMENT_TARGET=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -I/Users/eelco/Projects/Beamer/FFmpeg/build/include' --extra-ldflags='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -L/Users/eelco/Projects/Beamer/FFmpeg/build/lib'
libavutil 52. 17.101 / 52. 17.101
libavcodec 54. 91.101 / 54. 91.101
libavformat 54. 61.104 / 54. 61.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 35.101 / 3. 35.101
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, matroska,webm, from '/Users/eelco/Desktop/ffmpeg-ss-bug/2245-slow-ss-dd.mkv':
Metadata:
creation_time : 2012-12-09 16:32:15
Duration: 01:33:24.19, start: 0.000000, bitrate: 21 kb/s
Chapter #0.0: start 0.000000, end 316.316000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 316.316000, end 651.985000
Metadata:
title : 00:05:16.316
Chapter #0.2: start 651.985000, end 1186.310000
Metadata:
title : 00:10:51.985
Chapter #0.3: start 1186.310000, end 1669.835000
Metadata:
title : 00:19:46.310
Chapter #0.4: start 1669.835000, end 1970.552000
Metadata:
title : 00:27:49.835
Chapter #0.5: start 1970.552000, end 2434.974000
Metadata:
title : 00:32:50.552
Chapter #0.6: start 2434.974000, end 2811.976000
Metadata:
title : 00:40:34.974
Chapter #0.7: start 2811.976000, end 3120.534000
Metadata:
title : 00:46:51.976
Chapter #0.8: start 3120.534000, end 3535.157000
Metadata:
title : 00:52:00.534
Chapter #0.9: start 3535.157000, end 3623.411000
Metadata:
title : 00:58:55.157
Chapter #0.10: start 3623.411000, end 3859.314000
Metadata:
title : 01:00:23.411
Chapter #0.11: start 3859.314000, end 4259.672000
Metadata:
title : 01:04:19.314
Chapter #0.12: start 4259.672000, end 4530.317000
Metadata:
title : 01:10:59.672
Chapter #0.13: start 4530.317000, end 4869.782000
Metadata:
title : 01:15:30.317
Chapter #0.14: start 4869.782000, end 4968.630000
Metadata:
title : 01:21:09.782
Chapter #0.15: start 4968.630000, end 5604.192000
Metadata:
title : 01:22:48.630
Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: truehd, 48000 Hz, 7.1, s32
Metadata:
title : English TRUE-HD
Stream #0:2(swe): Audio: ac3, 48000 Hz, 5.1(side), fltp, 640 kb/s (default)
Metadata:
title : Swedish AC3
Stream #0:3(swe): Subtitle: dvd_subtitle (default)
Metadata:
title : Swedish
Stream #0:4(eng): Subtitle: dvd_subtitle
Metadata:
title : English
Output #0, image2, to '/dev/null':
Metadata:
encoder : Lavf54.61.104
Chapter #0.0: start 0.000000, end 305.316000
Metadata:
title : 00:00:00.000
Chapter #0.1: start 305.316000, end 640.985000
Metadata:
title : 00:05:16.316
Chapter #0.2: start 640.985000, end 1175.310000
Metadata:
title : 00:10:51.985
Chapter #0.3: start 1175.310000, end 1658.835000
Metadata:
title : 00:19:46.310
Chapter #0.4: start 1658.835000, end 1959.552000
Metadata:
title : 00:27:49.835
Chapter #0.5: start 1959.552000, end 2423.974000
Metadata:
title : 00:32:50.552
Chapter #0.6: start 2423.974000, end 2800.976000
Metadata:
title : 00:40:34.974
Chapter #0.7: start 2800.976000, end 3109.534000
Metadata:
title : 00:46:51.976
Chapter #0.8: start 3109.534000, end 3524.157000
Metadata:
title : 00:52:00.534
Chapter #0.9: start 3524.157000, end 3612.411000
Metadata:
title : 00:58:55.157
Chapter #0.10: start 3612.411000, end 3848.314000
Metadata:
title : 01:00:23.411
Chapter #0.11: start 3848.314000, end 4248.672000
Metadata:
title : 01:04:19.314
Chapter #0.12: start 4248.672000, end 4519.317000
Metadata:
title : 01:10:59.672
Chapter #0.13: start 4519.317000, end 4858.782000
Metadata:
title : 01:15:30.317
Chapter #0.14: start 4858.782000, end 4957.630000
Metadata:
title : 01:21:09.782
Chapter #0.15: start 4957.630000, end 5593.192000
Metadata:
title : 01:22:48.630
Stream #0:0(eng): Video: mjpeg, yuvj420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 23.98 tbc (default)
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> mjpeg)
Press [q] to stop, [?] for help
frame= 1 fps=0.5 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A dup=0 drop=262
video:47kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.045473%
2.14 real 6.04 user 0.10 sys
I’ve uploaded the file to the FTP.
comment:4 Changed 3 months ago by eelco
- Status changed from closed to reopened
- Resolution invalid deleted
comment:5 Changed 3 months ago by cehoyos
- Priority changed from normal to wish
- Resolution set to fixed
- Status changed from reopened to closed
- Component changed from undetermined to avformat
- Type changed from defect to enhancement
Concerning your original request, you can now use "-seek2any 1" to speed up the seeking (please do not report that this is not what you wanted).
If there still is a problem (with the second sample), please explain what does not work the way you expect, if it is unrelated to the new option, please consider opening a new ticket.
comment:6 Changed 3 months ago by eelco
I indeed want to speed up the seeking, but the output should still be correct ;)
When I try with the new option added (with git-master) on the 2245-slow-ss-dd.mkv sample it is indeed very fast, but generates a bunch of warnings and an completely empty output picture.
...
matroska,webm @ 0x101806600] File is broken, keyframes not correctly marked!
[h264 @ 0x10281ea00] reference picture missing during reorder
Last message repeated 3 times
[h264 @ 0x10281ea00] Missing reference picture, default is 0
[h264 @ 0x10281ea00] decode_slice_header error
[h264 @ 0x10281f600] reference picture missing during reorder
Last message repeated 2 times
[h264 @ 0x10281f600] Missing reference picture, default is 65564
Last message repeated 2 times
[h264 @ 0x10281fc00] mmco: unref short failure
Last message repeated 1 times
[h264 @ 0x102820200] reference picture missing during reorder
[h264 @ 0x102820200] Missing reference picture, default is 65568
[h264 @ 0x102820800] reference picture missing during reorder
[h264 @ 0x102820800] Missing reference picture, default is 65570
[h264 @ 0x10281ea00] mmco: unref short failure
[matroska,webm @ 0x101806600] Read error
frame= 1 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A dup=0 drop=1
video:393kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.005461%
Regarding the second sample (2245-slow-ss-dd.mkv), can you explain why the second keyframe (at 10.427s) was not used to generate the image at 11s? In the output is says
frame= 1 fps=0.5 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A dup=0 drop=262
It seems to me that it dropped 262 frames. When using it on the first “slow” file (2245-slow-ss.mkv) however, it does seem to detect the keyframe and only drops 15 frames:
frame= 1 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A dup=0 drop=15



Uploaded as 2245-slow-ss.mkv and 2245-fast-ss.mkv to ftp://upload.ffmpeg.org/incoming.