Opened 6 years ago

Closed 2 years ago

#7759 closed defect (fixed)

Wrong length/frames with VP9 when using yuva420p and lossless

Reported by: ChristianW Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: libvpx alpha
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

There will be wrong number of frames/length if VP9 and alpha with lossless is used.
If lossless is not used then it works ok.
If no alpha(yuv420p) is used it works ok.
Easies is to look at the time=00:00:07.16 versus the wrong time=00:00:6.52
So the video stopps before the last frame.
Very bad when a looping video is needed.

/Christian

Ok when running(180 frames of png with alpha) with alpha and without lossless:
ffmpeg -i Image%04d.png -c:v libvpx-vp9 -pix_fmt yuva420p output.webm
ffmpeg version N-93252-gf948082e5f Copyright (c) 2000-2019 the FFmpeg developers

built with gcc 8.2.1 (GCC) 20190212
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.102 / 58. 47.102
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100

Input #0, image2, from 'Image%04d.png':

Duration: 00:00:07.20, start: 0.000000, bitrate: N/A

Stream #0:0: Video: png, rgba(pc), 320x180 [SAR 2835:2835 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc

Stream mapping:

Stream #0:0 -> #0:0 (png (native) -> vp9 (libvpx-vp9))

Press [q] to stop, ? for help
[libvpx-vp9 @ 00000220f80fd5c0] v1.8.0-166-g2543f37a3
Output #0, webm, to 'output.webm':

Metadata:

encoder : Lavf58.26.101
Stream #0:0: Video: vp9 (libvpx-vp9), yuva420p, 320x180 [SAR 1:1 DAR 16:9], q=-1--1, 200 kb/s, 25 fps, 1k tbn, 25 tbc
Metadata:

encoder : Lavc58.47.102 libvpx-vp9

Side data:

cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

frame= 180 fps= 29 q=0.0 Lsize= 257kB time=00:00:07.16 bitrate= 293.5kbits/s speed=1.14x
video:158kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 62.363186%

Ok when running(180 frames of png with alpha) without alpha and with lossless:
ffmpeg -i Image%04d.png -c:v libvpx-vp9 -lossless 1 -pix_fmt yuv420p output.webm
ffmpeg version N-93252-gf948082e5f Copyright (c) 2000-2019 the FFmpeg developers

built with gcc 8.2.1 (GCC) 20190212
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.102 / 58. 47.102
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100

Input #0, image2, from 'Image%04d.png':

Duration: 00:00:07.20, start: 0.000000, bitrate: N/A

Stream #0:0: Video: png, rgba(pc), 320x180 [SAR 2835:2835 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc

Stream mapping:

Stream #0:0 -> #0:0 (png (native) -> vp9 (libvpx-vp9))

Press [q] to stop, ? for help
[libvpx-vp9 @ 0000025298b9cdc0] v1.8.0-166-g2543f37a3
Output #0, webm, to 'output.webm':

Metadata:

encoder : Lavf58.26.101
Stream #0:0: Video: vp9 (libvpx-vp9), yuv420p, 320x180 [SAR 1:1 DAR 16:9], q=-1--1, 200 kb/s, 25 fps, 1k tbn, 25 tbc
Metadata:

encoder : Lavc58.47.102 libvpx-vp9

Side data:

cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

frame= 180 fps= 52 q=0.0 Lsize= 1974kB time=00:00:07.16 bitrate=2258.1kbits/s speed=2.06x
video:1972kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.098054%

Not ok when running(180 frames of png with alpha) with alpha and with lossless:
ffmpeg -i Image%04d.png -c:v libvpx-vp9 -lossless 1 -pix_fmt yuva420p output.webm
ffmpeg version N-93252-gf948082e5f Copyright (c) 2000-2019 the FFmpeg developers

built with gcc 8.2.1 (GCC) 20190212
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.102 / 58. 47.102
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 6.101 / 58. 6.101
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100

Input #0, image2, from 'Image%04d.png':

Duration: 00:00:07.20, start: 0.000000, bitrate: N/A

Stream #0:0: Video: png, rgba(pc), 320x180 [SAR 2835:2835 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc

Stream mapping:

Stream #0:0 -> #0:0 (png (native) -> vp9 (libvpx-vp9))

Press [q] to stop, ? for help
[libvpx-vp9 @ 000001ae26efcdc0] v1.8.0-166-g2543f37a3
Output #0, webm, to 'output.webm':

Metadata:

encoder : Lavf58.26.101
Stream #0:0: Video: vp9 (libvpx-vp9), yuva420p, 320x180 [SAR 1:1 DAR 16:9], q=-1--1, 200 kb/s, 25 fps, 1k tbn, 25 tbc
Metadata:

encoder : Lavc58.47.102 libvpx-vp9

Side data:

cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

frame= 180 fps= 34 q=0.0 Lsize= 1986kB time=00:00:06.52 bitrate=2494.3kbits/s speed=1.24x
video:1797kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 10.490592%

Change History (7)

comment:1 by Carl Eugen Hoyos, 6 years ago

Component: ffmpegundetermined
Keywords: yuva420p lossless removed
Priority: criticalnormal

comment:2 by User, 5 years ago

lag-in-frames seems like it's the culprit; using the argument -lag-in-frames 0 fixes the issue. Works with both 1-pass and 2-pass encodes.

Although it's worth mentioning, in your example you're converting a png file, and that's not going to be truly lossless without a pixel format like yuv444p or gbrp (neither of which support alpha). libvpx-vp9 would need yuva444p or gbrap support, and right now the only pixel format with alpha that is supported is yuva420p.

Last edited 5 years ago by User (previous) (diff)

comment:3 by Carl Eugen Hoyos, 5 years ago

Component: undeterminedavcodec
Keywords: libvpx alpha added
Version: unspecifiedgit-master

comment:4 by Carl Eugen Hoyos, 5 years ago

Reproduced by developer: set
Status: newopen
$ ffmpeg -f lavfi -i testsrc2=d=2 -pix_fmt yuva420p -crf 0 -vcodec libvpx-vp9 out.mkv
ffmpeg version N-96910-gcfd9a65903 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (SUSE Linux)
  configuration: --enable-gpl --enable-gnutls --enable-libx264 --enable-libx265 --enable-libdav1d --enable-libaom --enable-libvpx --enable-libxml2
  libavutil      56. 42.100 / 56. 42.100
  libavcodec     58. 73.102 / 58. 73.102
  libavformat    58. 39.101 / 58. 39.101
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 77.100 /  7. 77.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, lavfi, from 'testsrc2=d=2':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0x365b500] v1.8.2
Output #0, matroska, to 'out.mkv':
  Metadata:
    encoder         : Lavf58.39.101
    Stream #0:0: Video: vp9 (libvpx-vp9) (VP90 / 0x30395056), yuva420p, 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.73.102 libvpx-vp9
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[Parsed_testsrc2_0 @ 0x3619e40] EOF timestamp not reliable
frame=   50 fps= 34 q=0.0 Lsize=     267kB time=00:00:01.80 bitrate=1214.0kbits/s speed=1.22x    
video:263kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.301801%

Output contains only 46 frames, independently of the used muxer.

comment:5 by Rob H, 5 years ago

Using info from my post to ffmpeg-user: http://ffmpeg.org/pipermail/ffmpeg-user/2020-April/048530.html

This also occurs for PNG-to-yuva420p encodes using libvpx-VP9 which are not lossless or crf 0.

Lossless versus crf 30 seem to drop differing numbers of frames. For my input 300 frames produced an output with 294 frames using -lossless 1 and 297 frames using -crf 30 -b:v 0. I have not yet tested the input with additional crf values.

Using -lag-in-frames 0 per previous comment produces the correct number of frames.

Additionally, I cannot reproduce Carl's testsrc2 example. On my machine it produces the correct number of frames in output for duration up to at least 200 (5000 frames). I am however using the Arch package as opposed to compiling from git.


Lossless:

$  ffmpeg -framerate 60 -f image2 -i 4frame%04d.png -c:v libvpx-vp9 -lossless 1 -pix_fmt yuva420p -an spacestinger5b.webm
ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.3.0 (Arch Linux 9.3.0-1)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, image2, from '4frame%04d.png':
  Duration: 00:00:05.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgba(pc), 1920x1080 [SAR 2835:2835 DAR 16:9], 60 fps, 60 tbr, 60 tbn, 60 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0x555782769d00] v1.8.2
Output #0, webm, to 'spacestinger5b.webm':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: vp9 (libvpx-vp9), yuva420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 200 kb/s, 60 fps, 1k tbn, 60 tbc
    Metadata:
      encoder         : Lavc58.54.100 libvpx-vp9
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=  300 fps=1.9 q=0.0 Lsize=  151542kB time=00:00:04.91 bitrate=252426.0kbits/s speed=0.0308x    
video:45087kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 236.109558%

Frames: 294; ffprobe DURATION: 00:00:04.934000000

CRF 30:

$ ffmpeg -framerate 60 -f image2 -i 4frame%04d.png -c:v libvpx-vp9 -pi
x_fmt yuva420p -an -crf 30 -b:v 0 spacestinger8.webm                                                                
ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers                                                
  built with gcc 9.3.0 (Arch Linux 9.3.0-1)                                                                        
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp
 --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d -
-enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enab
le-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-lib
openjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --ena
ble-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx
264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --
enable-shared --enable-version3                                                                                    
  libavutil      56. 31.100 / 56. 31.100                                                                            
  libavcodec     58. 54.100 / 58. 54.100                                                                            
  libavformat    58. 29.100 / 58. 29.100                                                                            
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, image2, from '4frame%04d.png':
  Duration: 00:00:05.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgba(pc), 1920x1080 [SAR 2835:2835 DAR 16:9], 60 fps, 60 tbr, 60 tbn, 60 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0x56298095a7c0] v1.8.2
Output #0, webm, to 'spacestinger8.webm':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: vp9 (libvpx-vp9), yuva420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 60 fps, 1k tbn, 60 tbc
    Metadata:
      encoder         : Lavc58.54.100 libvpx-vp9
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=  300 fps=0.8 q=0.0 Lsize=   36659kB time=00:00:04.93 bitrate=60864.8kbits/s speed=0.0132x    
video:1012kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3521.110596%

Frames: 297; ffprobe DURATION: 00:00:04.950000000

comment:6 by Balling, 3 years ago

Did not this happen because of 715f63232fc91f69b7505832437d3ef245fc6232? Please test.

comment:7 by Carl Eugen Hoyos, 2 years ago

Resolution: fixed
Status: openclosed
Note: See TracTickets for help on using tickets.