Skip to content

Instantly share code, notes, and snippets.

@porjo
Last active July 16, 2020 04:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save porjo/b7f4e4e8110ec97fcb7727c0351fb9d9 to your computer and use it in GitHub Desktop.
Save porjo/b7f4e4e8110ec97fcb7727c0351fb9d9 to your computer and use it in GitHub Desktop.
Hardware accelerated video encoding with ffmpeg

Using ffmpeg-3.1.6-1.fc25.x86_64 on Fedora 25, available from rpmfusion-free repo. It has been built with va-api support.

The following ffmpeg invocation works for me.

ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 \
   -i input.mkv -vf 'format=nv12,hwupload' -map 0:0 -map 0:1 -threads 4 \
   -acodec copy -vcodec h264_vaapi -qp:v 23 \
   output.mp4

Using -vcodec hevc_vaapi instead of -vcodec h264_vaapi produces h265 output. There was a bug that made output jerky, fixed with -bf 0 flag (remove B-frames)

Credit to: @Brainiarc7 https://gist.github.com/Brainiarc7/95c9338a737aa36d9bb2931bed379219

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