VFR-maniac / L-SMASH-Works

Works based on L-SMASH project
98 stars 48 forks source link

FFV1 clips are shifted earlier by one frame #39

Closed fvisagie closed 9 years ago

fvisagie commented 9 years ago

Problem description

Copy of: http://forum.doom9.org/showthread.php?p=1738580#post1738580

When decoding FFV1 generated by ffmpeg, LWLibavVideoSource() reports the correct number of frames, but the clip is shifted earlier by one frame. The first frame is lost and an additional frame is added towards the end. What is actually displayed towards the end depends on scrolling: sometimes a green frame is added at the end, sometimes the actual last frame appears twice in succession, sometimes the actual penultimate frame appears twice in succession. Scrolling backwards and forwards may cause any of the last three frames to display differently from before.

Other applications like MPC-HC and ffplay open the FFV1 clips correctly.

Results are the same for clips encoded with the latest ffmpeg version (with FFV1 version 3.4), and with an older 2013 version (with an FFV1 version reported by ffprobe as 0). L-SMASH-Works_r708-gc7cc104 is used.

Some examples below.

clip.avs:

fps = 25
length = 2*500
AudioDub(BlankClip(length=fps*length, width=1280, height=720, pixel_type="YV12", fps=25.0), Tone(length=length)).ShowFrameNumber()

ffmpeg:

ffmpeg -y -i clip.avs -c:v ffv1 -c:a copy clip.avi ffmpeg version N-75275-gd13a2df Copyright (c) 2000-2015 the FFmpeg developers built with gcc 4.9.3 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en able-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-lzma --ena ble-decklink --enable-zlib libavutil 55. 2.100 / 55. 2.100 libavcodec 57. 1.100 / 57. 1.100 libavformat 57. 0.100 / 57. 0.100 libavdevice 57. 0.100 / 57. 0.100 libavfilter 6. 3.100 / 6. 3.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.100 / 2. 0.100 libpostproc 54. 0.100 / 54. 0.100 Guessed Channel Layout for Input Stream #0.1 : stereo Input #0, avisynth, from 'clip.avs': Duration: 00:16:40.00, start: 0.000000, bitrate: 0 kb/s Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720, 25 fps, 25 tbr, 25 tbn, 25 tbc Stream #0:1: Audio: pcm_f32le, 48000 Hz, 2 channels, flt, 3072 kb/s Output #0, avi, to 'clip.avi': Metadata: ISFT : Lavf57.0.100 Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 1280x720, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc Metadata: encoder : Lavc57.1.100 ffv1 Stream #0:1: Audio: pcm_f32le ([3][0][0][0] / 0x0003), 48000 Hz, stereo, 3072 kb/s Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> ffv1 (native)) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame=25000 fps= 40 q=-0.0 Lsize= 1140802kB time=00:16:40.00 bitrate=9345.4kbits/s video:764277kB audio:375000kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.133785%

LWLibavVideoSource() correctly reports a total of 25000 frames. The first frame displayed is frame 00001, and the last three frames display as described above.

clip.avs:

fps = 25
length = 2
AudioDub(BlankClip(length=fps*length, width=1280, height=720, pixel_type="YV12", fps=25.0), Tone(length=length)).ShowFrameNumber()

ffmpeg:

ffmpeg -y -i clip.avs -c:v ffv1 -c:a copy clip.avi ffmpeg version N-75275-gd13a2df Copyright (c) 2000-2015 the FFmpeg developers built with gcc 4.9.3 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en able-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-lzma --ena ble-decklink --enable-zlib libavutil 55. 2.100 / 55. 2.100 libavcodec 57. 1.100 / 57. 1.100 libavformat 57. 0.100 / 57. 0.100 libavdevice 57. 0.100 / 57. 0.100 libavfilter 6. 3.100 / 6. 3.100 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.100 / 2. 0.100 libpostproc 54. 0.100 / 54. 0.100 Guessed Channel Layout for Input Stream #0.1 : stereo Input #0, avisynth, from 'clip.avs': Duration: 00:00:02.00, start: 0.000000, bitrate: 0 kb/s Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720, 25 fps, 25 tbr, 25 tbn, 25 tbc Stream #0:1: Audio: pcm_f32le, 48000 Hz, 2 channels, flt, 3072 kb/s Output #0, avi, to 'clip.avi': Metadata: ISFT : Lavf57.0.100 Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 1280x720, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc Metadata: encoder : Lavc57.1.100 ffv1 Stream #0:1: Audio: pcm_f32le ([3][0][0][0] / 0x0003), 48000 Hz, stereo, 3072 kb/s Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> ffv1 (native)) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help frame= 50 fps= 40 q=-0.0 Lsize= 2312kB time=00:00:02.00 bitrate=9469.0kbits/s video:1550kB audio:750kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.526660%

LWLibavVideoSource() correctly reports a total of 50 frames. The first frame displayed is frame 00001, and the last three frames display as described above.

Work-around

As reported at http://forum.doom9.org/showthread.php?p=1738582#post1738582:

Deleting the index and using threads=1

VFR-maniac commented 9 years ago

Should be fixed at aa127250538b70eb70209f070ca680619eb8b6cd .

fvisagie commented 9 years ago

Thanks for looking into this.