From 77a7a2b3dcaab84089a411a15c89410ef97537c5 Mon Sep 17 00:00:00 2001 From: Alex Garnett Date: Sun, 22 Nov 2020 10:28:41 -0800 Subject: [PATCH] add hardware encoding examples --- index.html | 31 +++++++++++++++++++++++++++++++ recipes.txt | 2 ++ 2 files changed, 33 insertions(+) diff --git a/index.html b/index.html index 056a30b..2d3401e 100644 --- a/index.html +++ b/index.html @@ -337,6 +337,37 @@ + + + +
+
Transcode to H.264/H.265 using the GPU
+

ffmpeg -i input_file -c:v h264_nvenc -preset llhq -rc:v vbr_hq -cq:v 19 -b:v 8000k -maxrate:v 12000k -profile:v high -c:a copy output_file

+

This command takes an input file and transcodes it to H.264 using the encoding functionality of an Nvidia GPU (without transcoding the audio). If you're using H.264 with AAC or AC3 audio, you can output to an .mp4 file; if you're using HEVC and/or more exotic audio, you should output to .mkv. While Nvidia's fixed-function hardware can be 10x as performant as encoding on the CPU, it requires a few more parameters in order to optimize quality at lower bitrates.

+
+
ffmpeg
starts the command
+
-i input_file
path, name and extension of the input file
+
-c:v h264_nvenc
tells FFmpeg to encode the video stream as H.264 using Nvidia's encoder.
+
--preset llhq
uses the "low latency, high quality" encoding preset, a good default when working with nvenc.
+
-rc:v vbr_hq
means "variable bitrate, high quality," allowing you to set a minimum and maximum bitrate for the encode.
+
-cq:v 19
is the same as the CRF quality level specified using x264 or other CPU-based encoders, where 0 is lossless, 51 is the worst possible quality, and values from 18-23 are typical.
+
-b:v 8000k -maxrate:v 12000k
corresponds to a minimum bitrate of 8 megabits (8000k) per second, and a maximum of 12 megabits per second. nvenc is not as good at estimating bitrates as CPU-based encoders, and without this data, will occasionally choose a visibly lower bitrate. The 8-12 mbit range is generally a good one for high-quality 1080p h264.
+
-profile:v high
uses the "high quality" profile of h264, something that's been baked in to the spec for a long time so that older players can declare compatibility; almost all h264 video now uses high.
+
-c:a copy
will skip reencoding the audio stream, and copy the audio from the source file.
+
output_file
path, name and extension of the output file
+
+

In order to encode to HEVC instead, and optionally transcode the audio, you can try changing the command like this:

+

ffmpeg -i input_file -c:v hevc_nvenc -preset llhq -rc:v vbr_hq -cq:v 19 -b:v 5000k -maxrate:v 8000k -profile:v high -c:a aac output_file

+
+
-c:v hevc_nvenc
encodes to HEVC (also called H.265), a more efficient codec supported on GPUs from approximately 2015 and newer.
+
-b:v 5000k -maxrate:v 8000k
specifies a slightly lower bitrate than when using h264, per HEVC's greater efficiency.
+
-c:a aac
reencodes the audio to AAC with default parameters, a very common and widely supported format for access copies.
+
+

Much of the information in this entry was taken from this superuser.com post provided by an Nvidia developer, one of the best sources of information on the ffmpeg Nvidia encoders.

+ +
+ + diff --git a/recipes.txt b/recipes.txt index 8e55e03..f68a8a7 100644 --- a/recipes.txt +++ b/recipes.txt @@ -16,6 +16,8 @@ ffmpeg -i input_file -map 0 -dn -c:v ffv1 -level 3 -g 1 -slicecrc 1 -slices 16 - ffmpeg -i concat:input_file_1\|input_file_2\|input_file_3 -c:v libx264 -c:a aac output_file.mp4 # Transcode to an H.265/HEVC MP4 ffmpeg -i input_file -c:v libx265 -pix_fmt yuv420p -c:a copy output_file +# Transcode to H.264/H.265 using the GPU +ffmpeg -i input_file -c:v h264_nvenc -preset llhq -rc:v vbr_hq -cq:v 19 -b:v 8000k -maxrate:v 12000k -profile:v high -c:a copy output_file # Transcode to an Ogg Theora ffmpeg -i input_file -acodec libvorbis -b:v 690k output_file # Convert WAV to MP3