User Tools

Site Tools


ffmpeg:hardware_acceleration_using_gpu:amd_gpu

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ffmpeg:hardware_acceleration_using_gpu:amd_gpu [2024/02/19 11:30] peterffmpeg:hardware_acceleration_using_gpu:amd_gpu [2024/05/15 00:03] (current) peter
Line 1: Line 1:
 ====== ffmpeg - Hardware transcoding using GPUs - AMD GPU ====== ====== ffmpeg - Hardware transcoding using GPUs - AMD GPU ======
 +
 +===== Basic method =====
  
 <code bash> <code bash>
 +ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "input.mkv" -map 0:v -metadata:s:v:0 language=eng -map 0:a -metadata:s:a:0 language=eng -map 0:s? -metadata:s:s:0 language=eng -c:v hevc_vaapi -c:a copy -c:s copy -global_quality 28 "output.mkv"
 +
 +
 ffmpeg -i "input.mkv" -vaapi_device /dev/dri/renderD128 -vcodec hevc_vaapi -vf format='nv12|vaapi,hwupload' -map 0 -c:a copy -c:s copy -qp 23 "output.mkv" ffmpeg -i "input.mkv" -vaapi_device /dev/dri/renderD128 -vcodec hevc_vaapi -vf format='nv12|vaapi,hwupload' -map 0 -c:a copy -c:s copy -qp 23 "output.mkv"
 </code> </code>
- 
-<WRAP info> 
-**NOTE:** 
- 
-  * **-vaapi_device /dev/dri/renderD128**, which is a shortcut to **-init_hw_device vaapi=vaapi0:/dev/dri/renderD128 -filter_hw_device vaapi0**, initializes a new hardware device of type vaapi. 
- 
-  * **-vcodec hevc_vaapi**  
- 
-  * **-vf 'format=nv12,hwupload'** creates the filtergraph and uses it to filter the stream. 
-    * 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). 
-    * 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**. 
- 
-</WRAP> 
  
 ---- ----
  
-<WRAP info> +===== Step-by-step guide to the above mentioned method ===== 
-**NOTE:**  To figure out for which codecs GPU hardware video encoding acceleration can be used vainfo command provides some information:+ 
 +==== Determine which codecs can be used with GPU hardware video encoding acceleration ====
  
 <code bash> <code bash>
Line 59: Line 50:
 </code> </code>
  
-  * For all entries with a value of VAEntrypointEncSlice hardware encoding can be used.+<WRAP info> 
 +**NOTE:**  For all entries with a value of **VAEntrypointEncSlice** hardware encoding can be used. 
 + 
 +In this case this shows the following as able to hardware encode: <code> 
 +      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice 
 +      VAProfileH264Main               : VAEntrypointEncSlice 
 +      VAProfileH264High               : VAEntrypointEncSlice 
 +      VAProfileHEVCMain               : VAEntrypointEncSlice 
 +      VAProfileHEVCMain10             : VAEntrypointEncSlice 
 +      VAProfileAV1Profile0            : VAEntrypointEncSlice 
 +</code>
  
 </WRAP> </WRAP>
 +
 +----
 +
 +==== Check what vaapi encoders are supported by ffmpeg ====
 +
 +<code bash>
 +ffmpeg -encoders | grep vaapi
 +</code>
 +
 +returns:
 +
 +<code>
 +ffmpeg version N-113695-g32538dafca Copyright (c) 2000-2024 the FFmpeg developers
 +  built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04)
 +  configuration: --prefix=/home/peter/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/peter/ffmpeg_build/include --extra-ldflags=-L/home/peter/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/peter/bin --enable-gpl --enable-gnutls --enable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree --extra-libs=-lpthread
 +  libavutil      58. 39.100 / 58. 39.100
 +  libavcodec     60. 39.101 / 60. 39.101
 +  libavformat    60. 21.100 / 60. 21.100
 +  libavdevice    60.  4.100 / 60.  4.100
 +  libavfilter     9. 17.100 /  9. 17.100
 +  libswscale      7.  6.100 /  7.  6.100
 +  libswresample   4. 13.100 /  4. 13.100
 +  libpostproc    57.  4.100 / 57.  4.100
 + V....D av1_vaapi            AV1 (VAAPI) (codec av1)
 + V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)
 + V....D hevc_vaapi           H.265/HEVC (VAAPI) (codec hevc)
 + V....D mjpeg_vaapi          MJPEG (VAAPI) (codec mjpeg)
 + V....D mpeg2_vaapi          MPEG-2 (VAAPI) (codec mpeg2video)
 + V....D vp8_vaapi            VP8 (VAAPI) (codec vp8)
 + V....D vp9_vaapi            VP9 (VAAPI) (codec vp9)
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  This confirms that ffmpeg supports the following vaapi codecs:
 +
 +<code>
 + V....D av1_vaapi            AV1 (VAAPI) (codec av1)
 + V....D h264_vaapi           H.264/AVC (VAAPI) (codec h264)
 + V....D hevc_vaapi           H.265/HEVC (VAAPI) (codec hevc)
 + V....D mjpeg_vaapi          MJPEG (VAAPI) (codec mjpeg)
 + V....D mpeg2_vaapi          MPEG-2 (VAAPI) (codec mpeg2video)
 + V....D vp8_vaapi            VP8 (VAAPI) (codec vp8)
 + V....D vp9_vaapi            VP9 (VAAPI) (codec vp9)
 +</code>
 +
 +</WRAP>
 +
 +
 +----
 +
 +----
 +
 +
 +<code bash>
 +ffmpeg -i "input.mkv" -vaapi_device /dev/dri/renderD128 -vcodec hevc_vaapi -vf format='nv12|vaapi,hwupload' -map 0 -c:a copy -c:s copy -qp 23 "output.mkv"
 +</code>
 +
 +<WRAP info>
 +**NOTE:**
 +
 +  * **-vaapi_device /dev/dri/renderD128**, which is a shortcut to **-init_hw_device vaapi=vaapi0:/dev/dri/renderD128 -filter_hw_device vaapi0**, initializes a new hardware device of type vaapi.
 +
 +  * **-vcodec hevc_vaapi** 
 +
 +  * **-vf 'format=nv12,hwupload'** creates the filtergraph and uses it to filter the stream.
 +    * 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).
 +    * 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**.
 +
 +  * **-map 0 -c:a copy -c:s copy**:  This causes to copy the audio streams and sub without modification to the new file. 
 +  * **-map 0:a -c:a copy**: This causes to copy the audio streams without modification to the new file. 
 +
 +  * **-qp 23**:  The video quality.
 +    * The lower the value, the better will be the video quality, but also the files will be larger.
 +    * The default value is 25 which is fairly good.
 +    * For high-definition videos a value between 21-23 works best and produces good results.
 +
 +</WRAP>
 +
 +----
 +
  
  
Line 136: Line 219:
 ---- ----
  
 +===== References =====
  
 +  * [[https://en.wikipedia.org/wiki/Video_Acceleration_API|vaapi]]
ffmpeg/hardware_acceleration_using_gpu/amd_gpu.1708342211.txt.gz · Last modified: 2024/02/19 11:30 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki