Skip to main content

FFV1

Help Wanted

This section is in need of contributions. If you believe you can help, please see our Contribution Guide to get started as a contributor!

FFV1 (rfc9043) is a lossless intra-frame video codec designed for archival use and preservation. Created by Michael Niedermayer, it is part of the FFmpeg project. The codec supports a wide range of color spaces, works with YUV and RGB content including alpha channel of color depths ranging from 8 to 16 bits (only up to 14 in case of RGB). It has good parallelization support and achieves very high compression ratios compared to other lossless video encoders such as UT Video, albeit at the cost of being more resource-hungry.

History​

In 2003, the codec was merged into FFmpeg; however, the bitstream specification was frozen in 2006 (officially FFV1 version 0). Later, in 2009, version 1 came out, covering more video bit depths. Version 2 never got its release, existing only in experimental form.

The third bitstream version was frozen in 2013 and is still the latest as of 2024. It added multithreading support and frame integrity checking.

There is a fourth version coming which might bring better support for color spaces, compression improvements, and maybe proper inter-frame prediction.

Usage​

Fast, heavily multithreaded
ffmpeg -i input.mkv -c:v ffv1 -slices 16 out.mkv
Slow, highest compression
ffmpeg -i input.mkv -c:v ffv1 -g 60 -slices 4 -context 1 -coder 2 out.mkv
Recommended for archival purposes, high compression, multithreaded
ffmpeg -i input.mkv -c:v ffv1 -g 1 -slices 16 -slicecrc 1 -context 1 -coder 2 out.mkv

Options​

  • slices - Slices divide the frame into multiple parts that can be encoded and decoded in parallel. Can only be one of: [4, 6, 9, 12, 16, 24, 30], where 4 is the default.
  • slicecrc - Setting it to 1 will enable the decoder to detect errors in the bitstream. Must be enabled for archival use. Can be either 0 or 1.
  • context - Setting it to 1 will make the encoder use a larger context size, which usually leads to better compression. Can be either 0 or 1.
  • coder - Sets entropy coding method:
    • 0 - Golomb-Rice (faster, default)
    • 1 - Range Coder (used for higher bit depths and better compression)
    • 2 - Range Coder with custom state transition table (almost the same as 1)
  • g - Sets GOP size. Must be 1 for archival use. See below

Intra-frame only catch​

Intra-frame codecs do not use well known inter-frame video coding techniques such as motion compensation, reusing parts of surrounding frames or adapting encoding context based on them. Every frame is independent from one another. Common intra-frame codecs include Motion JPEG (Lossy), Motion JPEG 2000 (Both), and UT Video (Lossless).

If you're a careful reader, you might have noticed that setting GOP size isn't a common characteristic among intra-frame codecs.

In fact, FFV1 can be considered an intra-frame codec only if the GOP size is set to 1. When it's larger than that, its context model depends on other frames found within the GOP, which contradicts the definition of intra-frame video codec. That is why it's highly advised to set GOP size to 1 for archiving. This way, if a single frame gets damaged, you'll only lose that frame. If GOP size was large, you might lose much bigger part of the video.

References: