From 77a7a2b3dcaab84089a411a15c89410ef97537c5 Mon Sep 17 00:00:00 2001 From: Alex Garnett Date: Sun, 22 Nov 2020 10:28:41 -0800 Subject: [PATCH 1/4] 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 From 87314cef7608f4464fafb1d5d3e3de00765ebc20 Mon Sep 17 00:00:00 2001 From: Alex Garnett Date: Sun, 22 Nov 2020 10:42:18 -0800 Subject: [PATCH 2/4] fix preset command --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 2d3401e..a093b2f 100644 --- a/index.html +++ b/index.html @@ -348,7 +348,7 @@
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.
+
-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.
From bc0edae2689785cc7c327de9cce6544dc2a78a89 Mon Sep 17 00:00:00 2001 From: Alex Garnett Date: Sun, 22 Nov 2020 10:46:23 -0800 Subject: [PATCH 3/4] add separate hevc recipe --- recipes.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/recipes.txt b/recipes.txt index f68a8a7..1f15c78 100644 --- a/recipes.txt +++ b/recipes.txt @@ -16,8 +16,10 @@ 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 +# Transcode to H.264 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 H.265 using the GPU +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 copy output_file # Transcode to an Ogg Theora ffmpeg -i input_file -acodec libvorbis -b:v 690k output_file # Convert WAV to MP3 From ca86a0eca49e3b532a5ea8b0de4d87875cb197cb Mon Sep 17 00:00:00 2001 From: Alex Garnett Date: Sun, 22 Nov 2020 10:50:43 -0800 Subject: [PATCH 4/4] fix hevc profile in separate example --- index.html | 3 ++- recipes.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index a093b2f..f6800d5 100644 --- a/index.html +++ b/index.html @@ -357,10 +357,11 @@
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

+

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 main10 -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.
+
-profile:v main10
declares the "main10" profile for working with HEVC; one of the primary advantages of this codec is better support for 10-bit video, enabling consumer HDR.
-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 1f15c78..be48802 100644 --- a/recipes.txt +++ b/recipes.txt @@ -19,7 +19,7 @@ ffmpeg -i input_file -c:v libx265 -pix_fmt yuv420p -c:a copy output_file # Transcode to H.264 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 H.265 using the GPU -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 copy output_file +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 main10 -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