ThuanNguyen.NET – Kỷ nguyên của kết nối và kiến tạo

[Google VP9] Recommended Settings for VOD

[Google VP9] Recommended Settings for VOD

  • Tháng Mười Một 8, 2019
Bình chọn

VP9 is a next-generation video compression format developed by the WebM Project. VP9 supports the full range of web and mobile use cases from low bitrate compression to high-quality ultra-HD, with additional support for 10/12-bit encoding and HDR.

VP9 can reduce video bit rates by as much as 50% compared with other known codecs. It is supported for adaptive streaming and is used by YouTube as well as other leading web video providers.

VP9 decoding is supported on over 2 billion end points including Chrome, Opera, Edge, Firefox and Android devices, as well as millions of smart TVs.

Purpose

This section provides recommendations for VP9 encode settings when performing file-based encoding (i.e. not live).

These recommendations are designed for the following goals:

  • A balance between quality and encoding speed
  • The minimal bit rate to achieve reasonable quality
  • Settings to accommodate a wide range of content types

These recommendations do not:

  • Address live encoding
  • Optimize for specific content types (e.g. high-motion sports footage)
  • Configure settings for specific device or network requirements

Single Resolution Encoding

VP9 supports a range of frame sizes, from tiny resolutions through 4K. Larger frame sizes give higher quality but they require more bandwidth to deliver, and more processing power to decode.

If you are creating a single resolution, 640×480 is a safe bet for a broad range of web and mobile devices. The following FFmpeg command-line parameters allow you to create a single-resolution file at 750kbps.

-vf scale=640x480 -b:v 750k -quality good -speed 0 -crf 33 \
  -c:v libvpx-vp9 -c:a libopus output.webm

Multi-Resolution Encoding

If you plan on targeting multiple resolutions, or if your delivery network has varying bandwidth, it is recommended to create multiple resolutions. Your player can then control which resolution is being sent to the viewer.

Multi-resolution video encodes are often used in adaptive bitrate streaming, where the video player switches between resolutions in real-time based upon the user’s bandwidth. For example, Shaka Player allows you to play back multi-resolution encodes, where each VP9 encode is in a separate file and a DASH manifest provides information about each encode.

For more information about packaging video in adaptive streaming formats please see the Shaka Packager. This guide will focus upon the encode settings for VP9 across multiple resolutions.

All settings below can be used for individual files at various resolutions, combined they provide a comprehensive set suitable for adaptive streaming. Note that the 640×480 version has two versions, one low quality (LQ) and the other medium quality (MQ).

Bitrate

Constrained Quality (CQ) mode is recommended when encoding VP9 files for on-demand viewing. This encoding mode allows you to specify a target average bit rate, while controlling both the maximum quality of the video as well as minimum and maximum bitrate.

The following bitrates are suggested as baselines for web and mobile distribution. These suggestions minimize bitrate which achieving video quality suitable for consumer web and mobile distribution; think of them as a ‘low’ bit rate recommendation that can still achieve reasonable quality.

For the examples above, it is recommended that minimum bitrate be set at 50% of target bitrate, and maximum at 145% of target.

Frame Size/Frame RateTarget Bitrate (VOD, kbps)Min Bitrate (50%)Max Bitrate (145%)
320x240p @ 24,25,3015075218
640x360p @ 24,25,30276138400
640x480p @ 24,25,30512 (LQ), 750 (MQ)256 (LQ) 375 (MQ)742 (LQ) 1088 (MQ)
1280x720p @ 24,25,3010245121485
1280x720p @ 50,6018009002610
1920x1080p @ 24,25,3018009002610
1920x1080p @ 50,60300015004350
2560x1440p @ 24,25,30600030008700
2560x1440p @ 50,609000450013050
3840x2160p @ 24,25,3012000600017400
3840x2160p @ 50,6018000900026100
Tìm hiểu thêm:  Hướng dẫn cài đặt WowzaStreamingEngine trên CentOS

Figure 2a: Recommended VOD bitrates

In FFmpeg, bit rate is controlled with the following commands:

FFmpeg
-b:v <arg>Sets bitrate (e.g. 500k)
-minrate <arg>
-maxrate <arg>
Sets minimum and maximum bitrate.

For example, when encoding 640×480 content you could use the command-line -b:v 750k -minrate 375 -maxrate 1088.

Quality

In CQ mode, you will also set the maximum quality level. The following quality levels are recommended for file-based VP9 encoding:

Frame HeightTarget Quality (CQ)
24037
36036
48034 (LQ) or 33 (MQ)
72032
108031
144024
216015

In FFmpeg, quality is set with the -crf command. For example, to set the quality to 33 you would use the command -crf 33

Multi-pass encoding and Encoding Speed

File-based encoding allows you flexibility in speed. You can also perform multiple passes on the same material to increase quality, and choose speeds for each one.

When encoding VP9 files in FFmpeg, it is recommend to set the -quality parameter to good and then set the speed of the first and second pass according to the table below with the -speed parameter. This gives a good balance between encoding time and the quality of the output.

Frame HeightSpeed (First Pass)Speed (Second Pass)
24041
36041
48041
72042
108042
144042
216042

For example, a first pass encode string in FFmpeg might include -quality good -speed 4.

Keyframe Spacing

It is recommended to allow up to 240 frames of video between keyframes (8 seconds for 30fps content). Keyframes are video frames which are self- sufficient; they don’t rely upon any other frames to render but they tend to be larger than other frame types. For web and mobile playback, generous spacing between keyframes allows the encoder to choose the best placement of keyframes to maximize quality.

In FFmpeg keyframe spacing is controlled with the -g command, indicating the number of frames. For 240 frames this would be -g 240.

Tiling and Threading Recommendations

Tiling splits the video frame into multiple columns, which slightly reduces quality but speeds up encoding performance. Tiles must be at least 256 pixels wide, so there is a limit to how many tiles can be used.

Depending upon the number of tiles and the resolution of the output frame, more CPU threads may be useful. Generally speaking, there is limited value to multiple threads when the output frame size is very small.

The following settings are recommended for tiling and threading at various resolutions.

Frame SizeNumber of tile-columnsNumber of threads
320×2401 (-tile-columns 0)2
640×3602 (-tile-columns 1)4
640×4802 (-tile-columns 1)4
1280×7204 (-tile-columns 2)8
1920×10804 (-tile-columns 2)8
2560×14408 (-tile-columns 3)16
3840×21608 (-tile-columns 3)16

In FFmpeg, the number of tiles is controlled with the -tile-columns parameter and the number of threads by -threads. For example, a 640×480 encode would use the command-line -tile-columns 2 -threads 4.

FFmpeg Command Lines

Bringing the above recommendations together, the following FFmpeg commands may be used to encode VP9 content.

Tìm hiểu thêm:  Cố định Bitrate khi transcode live bằng FFMPEG

Note that the first-pass and second-pass commands are chained together. The -y argument in the second-pass command answers “Yes” when FFmpeg asks to overwrite the first-pass statistics file with the output video.

Also note that a 1080p source is used for encodes targeting up to 1280×720 output. A 4k source is used for larger output.

320×240 (24, 25 or 30 frames per second)

ffmpeg -i tears_of_steel_1080p.webm -vf scale=320x240 -b:v 150k \
  -minrate 75k -maxrate 218k -tile-columns 0 -g 240 -threads 2 \
  -quality good -crf 37 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-320x240.webm && \
ffmpeg -i tears_of_steel_1080p.webm -vf scale=320x240 -b:v 150k \
  -minrate 75k -maxrate 218k -tile-columns 0 -g 240 -threads 2 \
  -quality good -crf 37 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 1 -y tos-320x240.webm

640×360 (24, 25 or 30 frames per second)

ffmpeg -i tears_of_steel_1080p.webm -vf scale=640x360 -b:v 276k \
  -minrate 138k -maxrate 400k -tile-columns 1 -g 240 -threads 4 \
  -quality good -crf 36 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-640x360.webm && \
ffmpeg -i tears_of_steel_1080p.webm -vf scale=640x360 -b:v 276k \
  -minrate 138k -maxrate 400k -tile-columns 1 -g 240 -threads 4 \
  -quality good -crf 36 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-640x360.webm

640×480 (Low Quality, 24, 25 or 30 frames per second)

ffmpeg -i tears_of_steel_1080p.webm -vf scale=640x480 -b:v 512k \
  -minrate 256k -maxrate 742k -tile-columns 1 -g 240 -threads 4 \
  -quality good -crf 34 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-640x360-low.webm && \
ffmpeg -i tears_of_steel_1080p.webm -vf scale=640x480 -b:v 512k \
  -minrate 256k -maxrate 742k -tile-columns 1 -g 240 -threads 4 \
  -quality good -crf 34 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-640x480-low.webm

640×480 (Medium Quality, 24, 25 or 30 frames per second)

ffmpeg -i tears_of_steel_1080p.webm -vf scale=640x480 -b:v 750k \
  -minrate 375k -maxrate 1088k -tile-columns 1 -g 240 -threads 4 \
  -quality good -crf 33 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-640x360-medium.webm && \
ffmpeg -i tears_of_steel_1080p.webm -vf scale=640x480 -b:v 750k \
  -minrate 375k -maxrate 1088k -tile-columns 1 -g 240 -threads 4 \
  -quality good -crf 33 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-640x480-medium.webm

1280×720 (24, 25 or 30 frames per second)

ffmpeg -i tears_of_steel_1080p.webm -vf scale=1280x720 -b:v 1024k \
  -minrate 512k -maxrate 1485k -tile-columns 2 -g 240 -threads 8 \
  -quality good -crf 32 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-1280x720-24-30fps.webm && \
ffmpeg -i tears_of_steel_1080p.webm -vf scale=1280x720 -b:v 1024k \
  -minrate 512k -maxrate 1485k -tile-columns 2 -g 240 -threads 8 \
  -quality good -crf 32 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-1280x720-24-30fps.webm

1280×720 (50 or 60 frames per second)

ffmpeg -i tears_of_steel_1080p.webm -vf scale=1280x720 -b:v 1800k \
  -minrate 900k -maxrate 2610k -tile-columns 2 -g 240 -threads 8 \
  -quality good -crf 32 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-1280x720-50-60fps.webm && \
ffmpeg -i tears_of_steel_1080p.webm -vf scale=1280x720 -b:v 1800k \
  -minrate 900k -maxrate 2610k -tile-columns 2 -g 240 -threads 8 \
  -quality good -crf 32 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4-y tos-1280x720-50-60fps.webm

1920×1080 (24, 25 or 30 frames per second)

ffmpeg -i tearsofsteel_4k.mov -vf scale=1920x1080 -b:v 1800k \
  -minrate 900k -maxrate 2610k -tile-columns 2 -g 240 -threads 8 \
  -quality good -crf 31 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-1920x1080-24-30fps.webm && \
ffmpeg -i tearsofsteel_4k.mov -vf scale=1920x1080 -b:v 1800k \
  -minrate 900k -maxrate 2610k -tile-columns 3 -g 240 -threads 8 \
  -quality good -crf 31 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-1920x1080-24-30fps.webm

1920×1080 (50 or 60 frames per second)

ffmpeg -i tearsofsteel_4k.mov -vf scale=1920x1080 -b:v 3000k \
  -minrate 1500k -maxrate 4350k -tile-columns 2 -g 240 -threads 8 \
  -quality good -crf 31 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-1920x1080-50-60fps.webm && \
ffmpeg -i tearsofsteel_4k.mov -vf scale=1920x1080 -b:v 3000k \
  -minrate 1500k -maxrate 4350k -tile-columns 3 -g 240 -threads 8 \
  -quality good -crf 31 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-1920x1080-50-60fps.webm

2560×1440 (24, 25 or 30 frames per second)

ffmpeg -i tearsofsteel_4k.mov -vf scale=2560x1440 -b:v 6000k \
  -minrate 3000k -maxrate 8700k -tile-columns 3 -g 240 -threads 16 \
  -quality good -crf 24 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-2560x1440-24-30fps.webm && \
ffmpeg -i tearsofsteel_4k.mov -vf scale=2560x1440 -b:v 6000k \
  -minrate 3000k -maxrate 8700k -tile-columns 3 -g 240 -threads 16 \
  -quality good -crf 24 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-2560x1440-24-30fps.webm

2560×1440 (50 or 60 frames per second)

ffmpeg -i tearsofsteel_4k.mov -vf scale=2560x1440 -b:v 9000k \
  -minrate 4500k -maxrate 13050k -tile-columns 3 -g 240 -threads 16 \
  -quality good -crf 24 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-2560x1440-50-60fps.webm && \
ffmpeg -i tearsofsteel_4k.mov -vf scale=2560x1440 -b:v 9000k \
  -minrate 4500k -maxrate 13050k -tile-columns 3 -g 240 -threads 16 \
  -quality good -crf 24 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-2560x1440-50-60fps.webm

3840×2160 (24, 25 or 30 frames per second)

ffmpeg -i tearsofsteel_4k.mov -vf scale=3840x2160 -b:v 12000k \
  -minrate 6000k -maxrate 17400k -tile-columns 3 -g 240 -threads 24 \
  -quality good -crf 15 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-3840x2160-24-30fps.webm && \
ffmpeg -i tearsofsteel_4k.mov -vf scale=3840x2160 -b:v 12000k \
  -minrate 6000k -maxrate 17400k -tile-columns 3 -g 240 -threads 24 \
  -quality good -crf 15 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -speed 4 -y tos-3840x2160-24-30fps.webm

3840×2160 (50 or 60 frames per second)

ffmpeg -i tearsofsteel_4k.mov -vf scale=3840x2160 -b:v 18000k \
  -minrate 9000k -maxrate 26100k -tile-columns 3 -g 240 -threads 24 \
  -quality good -crf 15 -c:v libvpx-vp9 -c:a libopus \
  -pass 1 -speed 4 tos-3840x2160-50-60fps.webm && \
ffmpeg -i tearsofsteel_4k.mov -vf scale=3840x2160 -b:v 18000k \
  -minrate 9000k -maxrate 26100k -tile-columns 3 -g 240 -threads 24 \
  -quality good -speed 4 -crf 15 -c:v libvpx-vp9 -c:a libopus \
  -pass 2 -y tos-3840x2160-50-60fps.webm
Index