Video Encoding VP9 Lossless

Yes, I’m putting this here for future reference in case anyone was curious about lossless encoding using VP9 and ffmpeg… :smile:

ffmpeg -framerate 23.976 -i %04d.png -pix_fmt yuv420p -c:v libvpx-vp9 -profile:v 0 -qmin 0 -qmax 0 -lossless 1 -an -r 23.976 charlie.webm

  • -framerate 23.976 - Need to specify input framerate for image sequences (defaults to 25fps).
  • -i %04d.png - input sequential images
  • -pix_fmt yuv420p - convert pixel from from RGB to YUV420p (not sure if this can be left off).
  • -c:v libvpx-vp9 - use the vp9 encoder
  • -qmin 0 -qmax 0 -lossless 1 - make the encode lossless
  • -an - no sound in my example
  • -r 23.976 - set output framerate to 23.976
ffmpeg version N-76347-gdd36749 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 5.2.0 (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-libbs2b --enable-libcaca --enable-libdcadec 
--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-lzma --enable-decklink --enable-zlib
  libavutil      55.  5.100 / 55.  5.100
  libavcodec     57. 12.100 / 57. 12.100
  libavformat    57. 11.100 / 57. 11.100
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 14.101 /  6. 14.101
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.100 /  2.  0.100
  libpostproc    54.  0.100 / 54.  0.100

I thought VP9 would allow yuv444p (I did not test with ffmpeg), because technically chroma subsampling introduces losses. Depends of course on the purpose of “lossless” encoding, but reading your title I thought i can leave my 0,02 € here ;-).

Best regards

Chris

1 Like

That’s a good point. I’ll have to try it with the yuv444p.

Here is a link on various recommended options for the VP9 encoding with ffmpeg (libvpx), which I’ve been following with some adjustments for my 4K movies VP9 Encoding Guide - wiki

I would also recommend to install the MKVToolnix, which is a set of tools to create, alter and inspect Matroska/WebM files, including the VP9-encoded ones. mkvmerge is particularly useful in this respect, since it allows to take the input from several media files and joins their streams (all of them or just a selection) into a WebM compliant file without necessity to re-encode them.

1 Like