| | 274 | The Advanced Media Framework (AMF) SDK provides developers with easy access to AMD GPUs for multimedia processing. |
| | 275 | |
| | 276 | AMF is effectively supported by FFmpeg to significantly speed up video encoding, decoding, and transcoding via AMD GPUs. |
| | 277 | == Encoding == |
| | 278 | Currently AMF encoder supports H.264/AVC, H.265/HEVC, AV1 encoder. FFmpeg uses `_amf` as the postfix for the AMF encoder names. The command lines shown below may use `h264_amf`, and should be replaced by `hevc_amf` for H.265/HEVC encoder and `av1_amf` for AV1 encoder. |
| | 279 | |
| | 280 | {{{ |
| | 281 | ffmpeg -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v h264_amf output.mp4 |
| | 282 | |
| | 283 | ffmpeg -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v hevc_amf output.mp4 |
| | 284 | |
| | 285 | ffmpeg -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v av1_amf output.mp4 |
| | 286 | }}} |
| | 287 | |
| | 288 | == Transcode == |
| | 289 | |
| | 290 | There are two possible methods for transcoding: hardware decoding and hardware encoding, or software decoding and hardware encoding. |
| | 291 | |
| | 292 | **Hardware Decode and Hardware Encode** |
| | 293 | |
| | 294 | Use DX9 hardware decoder |
| | 295 | |
| | 296 | {{{ |
| | 297 | ffmpeg -hwaccel dxva2 -hwaccel_output_format dxva2_vld -i input.mkv -c:v av1_amf output.mp4 |
| | 298 | }}} |
| | 299 | |
| | 300 | Use DX11 hardware decoder |
| | 301 | |
| | 302 | {{{ |
| | 303 | ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.mkv -c:v hevc_amf output.mp4 |
| | 304 | }}} |
| | 305 | |
| | 306 | The parameter `hwaccel_output_format` will specify the raw data (YUV) format after decoding. |
| | 307 | |
| | 308 | To avoid raw data copy between GPU memory and system memory, use `-hwaccel_output_format dxva2_vld` when using DX9 and use `-hwaccel_output_format d3d11` when using DX11. This will improve transcoding speed greatly. **This is the best setting we recommend for transcoding.** |
| | 309 | |
| | 310 | **Software Decode and Hardware Encode** |
| | 311 | |
| | 312 | Use the CPU to decode the input bitstream, and the GPU to encode the output stream. |
| | 313 | |
| | 314 | {{{ |
| | 315 | ffmpeg -i input.mkv -c:v av1_amf output.mp4 |
| | 316 | }}} |
| | 317 | |
| | 318 | The default software decoder corresponding to the elementary video stream will be used as the decoder. |
| | 319 | |
| | 320 | == Transcode with Scaling == |
| | 321 | |
| | 322 | Scaling is a very common operation in transcoding. It is done through video filter in FFmpeg. |
| | 323 | |
| | 324 | **Hardware decode and hardware encode with scaling** |
| | 325 | |
| | 326 | {{{ |
| | 327 | ffmpeg -hwaccel d3d11va -i input.mkv -vf scale=1280x720 -c:v h264_amf output.mp4 |
| | 328 | }}} |
| | 329 | |
| | 330 | If filter parameters are used in transcoding, users can’t set `hwaccel_output_format` parameters. In fact, the filter processing is finished in the CPU in the above example. |
| | 331 | |
| | 332 | **Software decode and hardware encode with scaling** |
| | 333 | |
| | 334 | In the following command line, both decoding and scaling are done via the CPU, and encoding is done via the GPU. |
| | 335 | |
| | 336 | {{{ |
| | 337 | ffmpeg -i input.mkv -vf scale=1280x720 -c:v h264_amf output.mp4 |
| | 338 | }}} |