ffmpeg:encoding:gpu_encoding
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ffmpeg:encoding:gpu_encoding [2024/05/18 16:26] – peter | ffmpeg:encoding:gpu_encoding [2025/02/17 15:23] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== ffmpeg - Encoding - GPU Encoding ====== | ====== ffmpeg - Encoding - GPU Encoding ====== | ||
+ | |||
+ | [[ffmpeg: | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <code bash> | ||
+ | ffmpeg -i " | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
===== Convert videos to H.265 / HEVC using ffmpeg and GPU hardware encoding ===== | ===== Convert videos to H.265 / HEVC using ffmpeg and GPU hardware encoding ===== | ||
Line 5: | Line 16: | ||
<code bash> | <code bash> | ||
ffmpeg -i " | ffmpeg -i " | ||
+ | |||
+ | ffmpeg -i " | ||
+ | |||
+ | |||
+ | # This is hardware decoding and software encoding. | ||
+ | ffmpeg -hwaccel vaapi -hwaccel_device / | ||
</ | </ | ||
Line 33: | Line 50: | ||
**NOTE:** | **NOTE:** | ||
- | * **-vaapi_device / | ||
* **-i " | * **-i " | ||
- | * **-vf ' | + | |
+ | | ||
* The encoders only accept input as VAAPI surfaces. If the input is in normal memory, it will need to be uploaded before giving the frames to the encoder - in the ffmpeg utility, the hwupload filter can be used for this. | * The encoders only accept input as VAAPI surfaces. If the input is in normal memory, it will need to be uploaded before giving the frames to the encoder - in the ffmpeg utility, the hwupload filter can be used for this. | ||
* It will upload to a surface with the same layout as the software frame, so it may be necessary to add a format filter immediately before to get the input into the right format (hardware generally wants the nv12 layout). | * It will upload to a surface with the same layout as the software frame, so it may be necessary to add a format filter immediately before to get the input into the right format (hardware generally wants the nv12 layout). | ||
* The **hwupload** filter also requires a device to upload to, which needs to be defined before the filter graph is created which is done with **-vaapi_device**. | * The **hwupload** filter also requires a device to upload to, which needs to be defined before the filter graph is created which is done with **-vaapi_device**. | ||
* The **scale_vaapi=w=1920: | * The **scale_vaapi=w=1920: | ||
- | * Use **-vf ' | + | * Use **-vf ' |
- | * **-map 0:v** selects the Video streams from the inputs | + | * Use **-vf ' |
+ | * See further below for other pixel formats.. | ||
+ | * **-map 0:v** selects the Video streams from the inputs | ||
* **-metadata: | * **-metadata: | ||
- | * **-map 0:a** selects the Audio streams from the inputs will will go into the output. | + | * **-map 0:a** selects the Audio streams from the inputs |
+ | * **-map 0:s?** selects the Sub-Title streams from the inputs which will go into the output. | ||
+ | * The "?" | ||
* **-c:v hevc_vaapi** converts the input file to H.265 in the destination file. | * **-c:v hevc_vaapi** converts the input file to H.265 in the destination file. | ||
* **hevc_vaapi** means H.265 / MPEG-H part 2 (HEVC). | * **hevc_vaapi** means H.265 / MPEG-H part 2 (HEVC). | ||
Line 76: | Line 97: | ||
* **-c:a copy** copies the Audio streams without modification to the output. | * **-c:a copy** copies the Audio streams without modification to the output. | ||
* **-c:s copy** copies the Subtitle streams without modification to the output. | * **-c:s copy** copies the Subtitle streams without modification to the output. | ||
- | * **-rc_mode CQP** sets the rate control mode to COP. | + | * **-rc_mode CQP** sets the rate control mode to CQP. |
- | * COP works well. | + | * CQP works well. |
* < | * < | ||
Run the following to see all possible modes: <code bash> | Run the following to see all possible modes: <code bash> | ||
Line 110: | Line 131: | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Using other pixel formats ===== | ||
+ | |||
+ | Check which pixel formats are supported: | ||
+ | |||
+ | <code bash> | ||
+ | ffmpeg -pix_fmts | ||
+ | </ | ||
+ | |||
+ | returns | ||
+ | |||
+ | < | ||
+ | Pixel formats: | ||
+ | I.... = Supported Input format for conversion | ||
+ | .O... = Supported Output format for conversion | ||
+ | ..H.. = Hardware accelerated format | ||
+ | ...P. = Paletted format | ||
+ | ....B = Bitstream format | ||
+ | FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL BIT_DEPTHS | ||
+ | ----- | ||
+ | IO... yuv420p | ||
+ | IO... yuyv422 | ||
+ | ... | ||
+ | ... | ||
+ | IO... nv12 | ||
+ | IO... p010le | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE:** When using a different pixel format, usually the following options will need to be set: | ||
+ | |||
+ | * -vf ' | ||
+ | * -vf ' | ||
+ | * -vf ' | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Encode with 8-bit ==== | ||
+ | |||
+ | ^Format^Chroma sampling^Packed or planar^Bits per channel^ | ||
+ | |NV12|4: | ||
+ | |||
+ | <code bash> | ||
+ | ffmpeg -i " | ||
+ | |||
+ | ffmpeg -i " | ||
+ | </ | ||
+ | |||
+ | ==== Encode with 10-bit ==== | ||
+ | |||
+ | ^Format^Chroma sampling^Packed or planar^Bits per channel^ | ||
+ | |P010|4: | ||
+ | |||
+ | <code bash> | ||
+ | ffmpeg -i " | ||
+ | |||
+ | ffmpeg -i " | ||
+ | </ | ||
+ | |||
+ | ==== Encode with 16-bit ==== | ||
+ | |||
+ | ^Format^Chroma sampling^Packed or planar^Bits per channel^ | ||
+ | |P010|4: | ||
+ | |||
+ | <code bash> | ||
+ | ffmpeg -i " | ||
+ | |||
+ | ffmpeg -i " | ||
+ | </ | ||
ffmpeg/encoding/gpu_encoding.1716049571.txt.gz · Last modified: 2024/05/18 16:26 by peter