Configure GOP and Context in FFV1 with FFmpeg

This guide explains how to configure the Group of Pictures (GOP) size and context model settings for the FFV1 lossless video encoder in FFmpeg. By adjusting these two parameters, you can optimize your lossless video files for either maximum compression efficiency, faster decoding speeds, or precise frame-by-frame seeking during video editing and archiving.

Configuring the GOP (Group of Pictures) Size

In FFV1, the GOP option determines the distance between keyframes (intra-frames). Unlike lossy codecs, FFV1 only uses intra-frames (I-frames) and non-keyframes that reference previous frames within the same GOP.

You can set the GOP size using the -g flag in your FFmpeg command.

Intra-only Mode (GOP = 1)

Setting the GOP to 1 forces every frame to be a keyframe. This is ideal for video editing and preservation because it allows for instantaneous seeking and editing at any frame.

ffmpeg -i input.mp4 -c:v ffv1 -g 1 output.mkv

Non-Intra Mode (GOP > 1)

Setting a GOP value greater than 1 allows FFV1 to compress subsequent frames by referencing previous ones, which significantly reduces file size. A common GOP size for archiving is between 24 and 100.

ffmpeg -i input.mp4 -c:v ffv1 -g 48 output.mkv

Configuring the Context Model

The -context option in FFV1 determines the complexity of the range coder’s context model. This setting directly affects the compression ratio and the CPU resources required to encode and decode the video.

FFV1 supports two context model sizes:

Example using Small Context (Speed Optimized)

ffmpeg -i input.mp4 -c:v ffv1 -context 0 output.mkv

Example using Large Context (Size Optimized)

ffmpeg -i input.mp4 -c:v ffv1 -context 1 output.mkv

Combining GOP and Context for Common Use Cases

Depending on your workflow, you should combine these settings to achieve the best balance of speed, file size, and playability.

1. Archiving and Long-Term Storage (Max Compression)

If your goal is to save as much disk space as possible and you do not need to edit the file frequently, use a large GOP and the large context model:

ffmpeg -i input.mp4 -c:v ffv1 -g 100 -context 1 output.mkv

2. Post-Production and Video Editing (Max Performance)

If you need to import the FFV1 file into a Non-Linear Editor (NLE) and require smooth scrubbing and fast decoding, use intra-only frames and the basic context model:

ffmpeg -i input.mp4 -c:v ffv1 -g 1 -context 0 output.mkv