FFmpeg - Encode VP9: Difference between revisions

From PiRho Knowledgebase
Jump to navigationJump to search
Created page with "Category:FFmpeg Category:VP9 Two-pass is the recommended encoding method for libvpx-vp9 as some quality-enhancing encoder features are only available in 2-pass mode.<br/> Constant quality 2-pass is invoked by setting <code>-b:v</code> to <code>zero</code> and specifying a quality level using the <code>-crf</code> switch:<br/> <pre> ffmpeg -i <input.file> -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null /dev/null && \ ffmpeg -i <input.file> -c:v libvpx-vp9 -b:v..."
 
Dex (talk | contribs)
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[Category:FFmpeg]]
[[Category:FFmpeg]]
[[Category:VP9]]
[[Category:VP9]]
Two-pass is the recommended encoding method for libvpx-vp9 as some quality-enhancing encoder features are only available in 2-pass mode.<br/>
VP9 is Google’s open, royalty‑free video codec designed to deliver high compression efficiency and excellent visual quality at lower bitrates. When encoding VP9 with FFmpeg’s libvpx-vp9 encoder, two-pass encoding is generally recommended. Some of VP9’s quality‑enhancing features are only available in multi-pass mode, and two-pass encoding allows the encoder to make better bitrate allocation decisions across the entire file.
Constant quality 2-pass is invoked by setting <code>-b:v</code> to <code>zero</code> and specifying a quality level using the <code>-crf</code> switch:<br/>
 
== Why Two-Pass Encoding? ==
Two-pass encoding provides FFmpeg with full knowledge of the input before performing the final encode. This enables:
* Better quality at a target size
* Access to quality-enhancing algorithms
* More predictable output quality
 
== Constant Quality Mode (CRF) ==
Unlike constant bitrate encoding, CRF mode prioritises visual quality. To invoke CRF mode in VP9:
* Set -b:v 0
* Select a CRF value (lower = higher quality)
 
Typical CRF ranges:
{| class="wikitable"
! CRF !! Quality Level !! Typical Use
|-
| 15–25 || High quality || Archival, production masters
|-
| 28–32 || Good quality || General-purpose encoding, streaming
|-
| 33–40 || Low bitrate || Mobile, constrained bandwidth
|}
 
== Two-Pass VP9 Encoding (CRF + Bitrate 0) ==
=== Linux / macOS ===
<pre>
<pre>
ffmpeg -i <input.file> -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null /dev/null && \
ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null /dev/null && ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -c:a libopus output.webm
ffmpeg -i <input.file> -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -c:a libopus <output.file>
</pre>
</pre>
Note: Windows users should use <code>NUL</code> instead of <code>/dev/null</code> and <code>^</code> instead of <code>\</code>.
 
Reference: [[https://trac.ffmpeg.org/wiki/Encode/VP9 FFmpeg: FFmpeg and VP9 Encoding Guide]]
=== Windows ===
<pre>
ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an ^
    -f null NUL ^
    && ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 ^
    -c:a libopus output.webm
</pre>
 
== Audio Encoding ==
Recommended:
<pre>
-c:a libopus -b:a 96k
</pre>
 
== Recommended Additional Options ==
{| class="wikitable"
! Option !! Meaning
|-
| -row-mt 1 || Enables row-based multi-threading
|-
| -tile-columns 2 || Enables parallel decode paths
|-
| -tile-rows 1 || Further decode parallelism
|-
| -g 240 || GOP size
|}
 
== Encoding Time vs Quality ==
VP9 is CPU-intensive. Raising -speed can reduce encoding time:
* -speed 1 — best quality
* -speed 2 — faster
* -speed 3 — acceptable for many workflows
 
== Troubleshooting ==
=== Low CPU Usage ===
Check:
<pre>
-row-mt 1
-threads N
</pre>
 
=== Output File Is Very Large ===
Increase CRF:
<pre>
-crf 32
</pre>
 
=== Audio Missing After First Pass ===
Expected. Audio is encoded only in pass 2.
 
== References ==
* https://trac.ffmpeg.org/wiki/Encode/VP9

Latest revision as of 15:55, 14 March 2026

VP9 is Google’s open, royalty‑free video codec designed to deliver high compression efficiency and excellent visual quality at lower bitrates. When encoding VP9 with FFmpeg’s libvpx-vp9 encoder, two-pass encoding is generally recommended. Some of VP9’s quality‑enhancing features are only available in multi-pass mode, and two-pass encoding allows the encoder to make better bitrate allocation decisions across the entire file.

Why Two-Pass Encoding?

Two-pass encoding provides FFmpeg with full knowledge of the input before performing the final encode. This enables:

  • Better quality at a target size
  • Access to quality-enhancing algorithms
  • More predictable output quality

Constant Quality Mode (CRF)

Unlike constant bitrate encoding, CRF mode prioritises visual quality. To invoke CRF mode in VP9:

  • Set -b:v 0
  • Select a CRF value (lower = higher quality)

Typical CRF ranges:

CRF Quality Level Typical Use
15–25 High quality Archival, production masters
28–32 Good quality General-purpose encoding, streaming
33–40 Low bitrate Mobile, constrained bandwidth

Two-Pass VP9 Encoding (CRF + Bitrate 0)

Linux / macOS

ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null /dev/null && ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -c:a libopus output.webm

Windows

ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an ^
    -f null NUL ^
    && ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 ^
    -c:a libopus output.webm

Audio Encoding

Recommended:

-c:a libopus -b:a 96k

Recommended Additional Options

Option Meaning
-row-mt 1 Enables row-based multi-threading
-tile-columns 2 Enables parallel decode paths
-tile-rows 1 Further decode parallelism
-g 240 GOP size

Encoding Time vs Quality

VP9 is CPU-intensive. Raising -speed can reduce encoding time:

  • -speed 1 — best quality
  • -speed 2 — faster
  • -speed 3 — acceptable for many workflows

Troubleshooting

Low CPU Usage

Check:

-row-mt 1
-threads N

Output File Is Very Large

Increase CRF:

-crf 32

Audio Missing After First Pass

Expected. Audio is encoded only in pass 2.

References