Skip to content

Instantly share code, notes, and snippets.

@danpawlik
Last active May 14, 2025 12:12
Show Gist options
  • Save danpawlik/d1ddd34e01e19d68fdc5890f1d343b95 to your computer and use it in GitHub Desktop.
Save danpawlik/d1ddd34e01e19d68fdc5890f1d343b95 to your computer and use it in GitHub Desktop.
Some notes about ffmpeg encoding with hardware acceleration

Install ffmpeg on Centos

sudo dnf install -y https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-9.noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-9.noarch.rpm sudo dnf install -y ffmpeg

Check available codecs

ffmpeg -codecs

Simply encoding:

ffmpeg -i test.mp4 -c:v libx265 -c:a copy name.mp4

Encoding with CPU HW acceleration - h265 + h264

  ffmpeg -i mysource.mp4 -c:v hevc_qsv -c:a copy output.mp4
  ffmpeg -i mysource.mp4 -c:v h264_qsv -c:a copy output.mp4

Enabling GPU HW acceleration - for Intel:

sudo dnf install -y intel-media-driver libva libva-utils gstreamer1-vaapi ffmpeg intel-gpu-tools mesa-dri-drivers mpv && sudo dracut -f ; reboot

Simply enconding(transcoding) commands:

ffmpeg -v verbose -hwaccel vaapi -i mysource.mp4 -vf 'format=nv12,hwupload' -c:v hevc_vaapi output.mp4
# when the input may or may not be hardware decodable
ffmpeg -v verbose -hwaccel vaapi -i mysource.mp4 -vf 'format=nv12|vaapi,hwupload' -c:v hevc_vaapi output.mp4

HW Encoding h265(hevc) with small improvements:

ffmpeg -vaapi_device /dev/dri/renderD128 -i mysource.mp4 -vf 'format=nv12,hwupload' -map 0:0 -c:v hevc_vaapi -map 0:a -c:a copy -rc_mode CQP -global_quality 25 -profile:v main -v verbose output.mp4

Encode with 10-bit H.265 at 15Mbps VBR (recent hardware required - Kaby Lake or later Intel):

ffmpeg -hwaccel vaapi -i mysource.mp4 -vf 'format=p010,hwupload' -c:v hevc_vaapi -b:v 15M -profile 2 output.mp4

where:

   <int>        E..V...... Set rate control mode (from 0 to 6) (default auto)
   0            E..V...... Choose mode automatically based on other parameters
   1            E..V...... Constant-quality
   2            E..V...... Constant-bitrate
   3            E..V...... Variable-bitrate
   4            E..V...... Intelligent constant-quality
   5            E..V...... Quality-defined variable-bitrate
   6            E..V...... Average variable-bitrate

More advanced encoding (not recommended at all):

ffmpeg -vaapi_device /dev/dri/renderD128 -i mysource.mp4  -tune film -vf eq=gamma=3:gamma_weight=0.48:contrast=1.13:saturation=1.1,format=nv12,hwupload -c:v hevc_vaapi -qp 18 -c:a copy output.mp4

or

ffmpeg -init_hw_device vaapi=intel:/dev/dri/renderD128 -i mysource.mp4 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device intel -filter_hw_device intel -vf 'scale_vaapi,hwmap=derive_device=qsv,format=qsv' -c:v hevc_qsv -f mp4 output.mp4

Transcoding video and upscaling resolution 2x:

ffmpeg -i mysource -vf 'scale=iw*2:ih*2' -c:v h264_qsv -c:a copy output.mp4
ffmpeg -i mysource -vf 'scale=iw*2:ih*2' -c:v hevc_qsv -c:a copy output.mp4

Transcoding video and downscaling resolution 2x:

ffmpeg -i mysource -vf 'scale=iw/2:ih/2' -c:v h264_qsv -c:a copy output.mp4
ffmpeg -i mysource -vf 'scale=iw/2:ih/2' -c:v hevc_qsv -c:a copy output.mp4

Useful links:

https://fedoraproject.org/wiki/Firefox_Hardware_acceleration https://www.reddit.com/r/ffmpeg/comments/10usxki/trying_to_get_ffmpeg_to_use_intel_gpu_when/ https://stackoverflow.com/questions/73208088/how-to-check-ffmpeg-hardware-acceleration-status https://www.tauceti.blog/posts/linux-ffmpeg-amd-5700xt-hardware-video-encoding-hevc-h265-vaapi/ https://x265.readthedocs.io/en/master/cli.html#profile-level-tier https://stackoverflow.com/a/76128676/1966658 https://write.corbpie.com/upscaling-and-downscaling-video-with-ffmpeg/ https://write.corbpie.com/a-guide-to-upscaling-or-downscaling-video-with-ffmpeg/ https://trac.ffmpeg.org/wiki/HWAccelIntro https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video#Hardware_decoding_and_encoding

@darknebular
Copy link

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment