Opened 10 years ago
Closed 9 years ago
#3716 closed defect (fixed)
ffmpeg can't seek to start of a mpeg video
Reported by: | hxuanyu | Owned by: | |
---|---|---|---|
Priority: | important | Component: | ffmpeg |
Version: | git-master | Keywords: | mpegps seek regression |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | yes | |
Analyzed by developer: | no |
Description
This issue can be reproduced using
ffmpeg version N-63861-g958168d Copyright (c) 2000-2014 the FFmpeg developers
built on Jun 9 2014 22:02:00 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 52. 89.100 / 52. 89.100
libavcodec 55. 66.100 / 55. 66.100
libavformat 55. 42.101 / 55. 42.101
libavdevice 55. 13.101 / 55. 13.101
libavfilter 4. 7.100 / 4. 7.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
steps to reproduce.
- convert attached mp4 into mpg: ffmpeg.exe -i "numbers fps 25.mp4" 25.mpg
- convert generated mpg to mp4 using -ss 0: ffmpeg.exe -ss 0 -i 25.mpg 25.mp4
then you can easily find that 25.mp4 doesn't start with the correct frame (original mp4 is a video with frames showing number 000 to 499, but 25.mp4 starts with 12)
I also spent little time to debug. seems the mpg file converted from mp4 has a non-zero offset
rhbc73 videostreamoffset = 48600
rhbc73 debug[V], ProcessVideoPacket, [DTS:45000 PTS:48600] KEY FRAME
rhbc73 debug[V], ProcessVideoPacket, [DTS:48600 PTS:52200]
rhbc73 debug[V]: get a complete frame [0] Best time:[48600 - 48600] = [0] = 0.000000
rhbc73 debug[V], ProcessVideoPacket, [DTS:52200 PTS:55800]
rhbc73 debug[V]: get a complete frame [1] Best time:[52200 - 48600] = [3600] = 0.040000
rhbc73 debug[V], ProcessVideoPacket, [DTS:55800 PTS:59400]
rhbc73 debug[V]: get a complete frame [2] Best time:[55800 - 48600] = [7200] = 0.080000
rhbc73 debug[V], ProcessVideoPacket, [DTS:59400 PTS:63000]
rhbc73 debug[V]: get a complete frame [3] Best time:[59400 - 48600] = [10800] = 0.120000
rhbc73 debug[V], ProcessVideoPacket, [DTS:63000 PTS:66600]
rhbc73 debug[V]: get a complete frame [4] Best time:[63000 - 48600] = [14400] = 0.160000
rhbc73 debug[V], ProcessVideoPacket, [DTS:66600 PTS:70200]
rhbc73 debug[V]: get a complete frame [5] Best time:[66600 - 48600] = [18000] = 0.200000
rhbc73 debug[V], ProcessVideoPacket, [DTS:70200 PTS:73800]
rhbc73 debug[V]: get a complete frame [6] Best time:[70200 - 48600] = [21600] = 0.240000
rhbc73 debug[V], ProcessVideoPacket, [DTS:73800 PTS:77400]
rhbc73 debug[V]: get a complete frame [7] Best time:[73800 - 48600] = [25200] = 0.280000
rhbc73 debug[V], ProcessVideoPacket, [DTS:77400 PTS:81000]
rhbc73 debug[V]: get a complete frame [8] Best time:[77400 - 48600] = [28800] = 0.320000
rhbc73 debug[V], ProcessVideoPacket, [DTS:81000 PTS:84600]
rhbc73 debug[V]: get a complete frame [9] Best time:[81000 - 48600] = [32400] = 0.360000
rhbc73 debug[V], ProcessVideoPacket, [DTS:84600 PTS:88200]
rhbc73 debug[V]: get a complete frame [10] Best time:[84600 - 48600] = [36000] = 0.400000
rhbc73 debug[V], ProcessVideoPacket, [DTS:88200 PTS:91800] KEY FRAME
rhbc73 debug[V]: get a complete frame [11] Best time:[88200 - 48600] = [39600] = 0.440000
rhbc73 debug[V], ProcessVideoPacket, [DTS:91800 PTS:95400]
rhbc73 debug[V]: get a complete frame [12] Best time:[91800 - 48600] = [43200] = 0.480000
videostreamoffset = pFormatCtx->start_time, so we can see offset is in pts. if I call av_seek_frame(48600, AVSEEK_FLAG_BACKWARD) then
I couldn't get a complete frame until [DTS:88200 PTS:91800] KEY FRAME packet is readout, but if I call av_seek(45000, AVSEEK_FLAG_BACKWARD) then I could successfully. This means seek is based on dts?
Attachments (2)
Change History (10)
by , 10 years ago
Attachment: | numbers fps 25.mp4 added |
---|
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Keywords: | mpegps seek added |
---|
comment:3 by , 10 years ago
below is the command and output
$ ffmpeg.exe -i "numbers fps 25.mp4" 25.mpg
ffmpeg version N-63861-g958168d Copyright (c) 2000-2014 the FFmpeg developers
built on Jun 9 2014 22:02:00 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 52. 89.100 / 52. 89.100
libavcodec 55. 66.100 / 55. 66.100
libavformat 55. 42.101 / 55. 42.101
libavdevice 55. 13.101 / 55. 13.101
libavfilter 4. 7.100 / 4. 7.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'numbers fps 25.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.21.102
Duration: 00:00:20.00, start: 0.000000, bitrate: 205 kb/s
Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 768x576, 203 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
[mpeg @ 03bf0060] VBV buffer size not set, using default size of 130KB
If you want the mpeg file to be compliant to some specification
Like DVD, VCD or others, make sure you set the correct buffer size
Output #0, mpeg, to '25.mpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.42.101
Stream #0:0(und): Video: mpeg1video, yuv420p, 768x576, q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc55.66.100 mpeg1video
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mpeg1video (mpeg1video))
Press [q] to stop, ? for help
[mpeg1video @ 03b59020] warning, clipping 1 dct coefficients to -255..255
Last message repeated 68 times
frame= 500 fps=455 q=31.0 Lsize= 1306kB time=00:00:19.96 bitrate= 536.0kbits/s
video:1292kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.097117%
Alex@vid003 ~/Downloads/image
$ ffmpeg.exe -ss 0 -i 25.mpg 25.mp4
ffmpeg version N-63861-g958168d Copyright (c) 2000-2014 the FFmpeg developers
built on Jun 9 2014 22:02:00 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 52. 89.100 / 52. 89.100
libavcodec 55. 66.100 / 55. 66.100
libavformat 55. 42.101 / 55. 42.101
libavdevice 55. 13.101 / 55. 13.101
libavfilter 4. 7.100 / 4. 7.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mpeg, from '25.mpg':
Duration: 00:00:19.96, start: 0.540000, bitrate: 536 kb/s
Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 768x576 [SAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
[libx264 @ 03c1ff40] using SAR=1/1
[libx264 @ 03c1ff40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 03c1ff40] profile High, level 3.1
[libx264 @ 03c1ff40] 264 - core 142 r2431 ac76440 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 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=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '25.mp4':
Metadata:
encoder : Lavf55.42.101
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 768x576 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc
Metadata:
encoder : Lavc55.66.100 libx264
Stream mapping:
Press [q] to stop, ? for help
frame= 488 fps=241 q=-1.0 Lsize= 930kB time=00:00:19.92 bitrate= 382.6kbits/s
video:924kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.659663%
[libx264 @ 03c1ff40] frame I:2 Avg QP:10.80 size: 7639
[libx264 @ 03c1ff40] frame P:205 Avg QP:21.40 size: 2429
[libx264 @ 03c1ff40] frame B:281 Avg QP:27.19 size: 1539
[libx264 @ 03c1ff40] consecutive B-frames: 21.9% 0.8% 9.2% 68.0%
[libx264 @ 03c1ff40] mb I I16..4: 62.9% 34.0% 3.2%
[libx264 @ 03c1ff40] mb P I16..4: 2.5% 5.9% 0.9% P16..4: 3.9% 2.0% 0.9% 0.0% 0.0% skip:83.9%
[libx264 @ 03c1ff40] mb B I16..4: 0.9% 2.5% 0.4% B16..8: 8.9% 2.6% 0.4% direct: 0.3% skip:84.0% L0:57.5% L1:40.4% BI: 2.1%
[libx264 @ 03c1ff40] 8x8 transform intra:62.0% inter:67.5%
[libx264 @ 03c1ff40] coded y,uvDC,uvAC intra: 16.0% 0.0% 0.0% inter: 2.0% 0.0% 0.0%
[libx264 @ 03c1ff40] i16 v,h,dc,p: 68% 27% 5% 0%
[libx264 @ 03c1ff40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 15% 61% 3% 1% 1% 1% 1% 1%
[libx264 @ 03c1ff40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 31% 29% 2% 2% 2% 2% 2% 2%
[libx264 @ 03c1ff40] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 @ 03c1ff40] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 03c1ff40] ref P L0: 59.6% 4.7% 17.0% 18.7%
[libx264 @ 03c1ff40] ref B L0: 64.9% 26.4% 8.7%
[libx264 @ 03c1ff40] ref B L1: 84.1% 15.9%
[libx264 @ 03c1ff40] kb/s:387.65
Alex@vid003 ~/Downloads/image
$ ffmpeg.exe -i 25.mp4 -f image2 image-%3d.jpeg
ffmpeg version N-63861-g958168d Copyright (c) 2000-2014 the FFmpeg developers
built on Jun 9 2014 22:02:00 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
libavutil 52. 89.100 / 52. 89.100
libavcodec 55. 66.100 / 55. 66.100
libavformat 55. 42.101 / 55. 42.101
libavdevice 55. 13.101 / 55. 13.101
libavfilter 4. 7.100 / 4. 7.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '25.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.42.101
Duration: 00:00:19.52, start: 0.480000, bitrate: 390 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 768x576 [SAR 1:1 DAR 4:3], 387 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
[swscaler @ 02a3f360] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'image-%3d.jpeg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.42.101
Stream #0:0(und): Video: mjpeg, yuvj420p, 768x576 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc55.66.100 mjpeg
Stream mapping:
Press [q] to stop, ? for help
frame= 488 fps=217 q=24.8 Lsize=N/A time=00:00:19.52 bitrate=N/A
video:5772kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Then we can see the img-001.jpeg is not the first frame we want
comment:4 by , 10 years ago
Reproduced by developer: | set |
---|---|
Status: | new → open |
Version: | unspecified → git-master |
The following shows the first frame (of the first gop):
$ ffmpeg -i out.mpg -vframes 1 out.jpg
The following commands output the first frame of the second gop:
$ ffmpeg -ss 0 -i out.mpg -vframes 1 out1.jpg ffmpeg version N-63912-g385a342 Copyright (c) 2000-2014 the FFmpeg developers built on Jun 12 2014 08:57:31 with gcc 4.7 (SUSE Linux) configuration: --enable-gpl libavutil 52. 89.100 / 52. 89.100 libavcodec 55. 66.100 / 55. 66.100 libavformat 55. 43.100 / 55. 43.100 libavdevice 55. 13.101 / 55. 13.101 libavfilter 4. 8.100 / 4. 8.100 libswscale 2. 6.100 / 2. 6.100 libswresample 0. 19.100 / 0. 19.100 libpostproc 52. 3.100 / 52. 3.100 Input #0, mpeg, from 'out.mpg': Duration: 00:00:19.96, start: 0.540000, bitrate: 524 kb/s Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 768x576 [SAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc [swscaler @ 0x3624380] deprecated pixel format used, make sure you did set range correctly Output #0, image2, to 'out1.jpg': Metadata: encoder : Lavf55.43.100 Stream #0:0: Video: mjpeg, yuvj420p, 768x576 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc Metadata: encoder : Lavc55.66.100 mjpeg Stream mapping: Stream #0:0 -> #0:0 (mpeg1video (native) -> mjpeg (mjpeg)) Press [q] to stop, [?] for help frame= 1 fps=0.0 q=7.3 Lsize=N/A time=00:00:00.52 bitrate=N/A video:15kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
$ ffmpeg -ss 0.01 -i out.mpg -vframes 1 out2.jpg ffmpeg version N-63912-g385a342 Copyright (c) 2000-2014 the FFmpeg developers built on Jun 12 2014 08:57:31 with gcc 4.7 (SUSE Linux) configuration: --enable-gpl libavutil 52. 89.100 / 52. 89.100 libavcodec 55. 66.100 / 55. 66.100 libavformat 55. 43.100 / 55. 43.100 libavdevice 55. 13.101 / 55. 13.101 libavfilter 4. 8.100 / 4. 8.100 libswscale 2. 6.100 / 2. 6.100 libswresample 0. 19.100 / 0. 19.100 libpostproc 52. 3.100 / 52. 3.100 Input #0, mpeg, from 'out.mpg': Duration: 00:00:19.96, start: 0.540000, bitrate: 524 kb/s Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv), 768x576 [SAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc [swscaler @ 0x33fc380] deprecated pixel format used, make sure you did set range correctly Output #0, image2, to 'out2.jpg': Metadata: encoder : Lavf55.43.100 Stream #0:0: Video: mjpeg, yuvj420p, 768x576 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc Metadata: encoder : Lavc55.66.100 mjpeg Stream mapping: Stream #0:0 -> #0:0 (mpeg1video (native) -> mjpeg (mjpeg)) Press [q] to stop, [?] for help frame= 1 fps=0.0 q=7.3 Lsize=N/A time=00:00:00.52 bitrate=N/A video:15kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
by , 10 years ago
comment:5 by , 10 years ago
Keywords: | regression added |
---|---|
Priority: | normal → important |
Looks like a regression since 3fa72de8 / 56ee3f9d
comment:6 by , 10 years ago
I think I am experiencing the same issue, with h.264 MP4 files that are recorded by a Panasonic LX100 camera.
I took a short example video file using the camera, taking a shot of a screen showing a millisecond counter for easier identification of individual frames (the display refresh rate is 60Hz, the video taken with 25fps, the clock display refreshed each 10ms, but the relevant result is that each frame shows a different number). You can download this (3.5 MB) video file here.
When replayed in the camera, the first frame shown shows time: 3685ms
on the display.
When replayed with software like mpv, avidemux, kdenlive or alike that uses ffmpeg as a library for video decoding, the first frames a not displayed, but instead the first frame shows time: 3768ms
- and that is actually the third frame.
I have looked at timestamp dump outputs of ffprobe and MP4Box, and it seems that while MP4Box shows reasonable DTS and CTS times, where the first frame is actually to be displayed, first, the ffprobe output shows implausible DTS and PTS timestamps - they are always the same, and that would mean to display a B-frame before the first I-frame is decoded!
For reference, I have uploaded the output of ffprobe and MP4Box for this example video:
ffprobe output
MP4Box output
comment:7 by , 9 years ago
The mpv developers have found a workaround for this bug, see:
https://github.com/mpv-player/mpv/issues/1341
Of course, instead of putting a workaround like this in every ffmpeg using software, it would be better to have it fixed in ffmpeg :-)
comment:8 by , 9 years ago
Component: | undetermined → ffmpeg |
---|---|
Resolution: | → fixed |
Status: | open → closed |
The issue originally described in this ticket was fixed in b0322e4a9e326f41e0214abb0083fe9eb7407460 - see also ticket #4554.
Please provide the command line that does not produce the expected output together with the complete, uncut console output to make this a valid ticket.