Skip to content

Instantly share code, notes, and snippets.

@riturajborpujari
Created December 6, 2025 13:15
Show Gist options
  • Select an option

  • Save riturajborpujari/17d192aa462841a1398371856170d253 to your computer and use it in GitHub Desktop.

Select an option

Save riturajborpujari/17d192aa462841a1398371856170d253 to your computer and use it in GitHub Desktop.
FFMPEG on AMD GPU

FFMPEG usage guide

Hardware (VAAPI) accelerated video format conversion

Conversion

Using FFMPEG CLI for converting videos

Example command

ffmpeg \
    -hwaccel vaapi -vaapi_device /dev/dri/renderD128
    -i input.mp4 \
    -vf 'format=nv12,hwupload,scale_vaapi=w=2560:h=1440' \
    -c:v h264_vaapi \
    -q:v 21 \
    output.mp4

This asks ffmpeg

  • -hwaccel vaapi : to use vaapi hardware accel device

  • -vaapi_device DEVICE : where to find the device

  • format=nv12 : to first format as nv12

  • hwupload : to upload to GPU

    VAAPI understands nv12, and hence the conversion beforehand

  • scale_vaapi=DIMENSIONS : tells ffmpeg to scale the VAAPI buffer

  • -c:v h264_vaapi : asks ffmpeg to encode the output using h264_vaapi in GPU

    Use -c:v libx264 for slower, but better quality encoding in CPU

  • -q:v 21 : sets the video Quality Param to 21

    See Quality Param section below

Quality Param

With VAAPI

  • QP 18–22: good quality
  • QP 24–30: visible artifacts
  • QP 12–16: very high quality / large files

Changing container formats

FFMPEG can be used to change container formats (.mp4, .mkv, .webm)

Example command

ffmpeg \
    -i input.mp4 \
    -c:v copy \
    -c:a copy \
    output.mkv

This asks ffmpeg

  • c:v copy : copy the video stream without decoding
  • c:a copy : copy the audio stream without decoding

This might cause issue when for example trying to copy an Opus audio stream into a .mp4 container. MP4 won't accept that, in which case you'd have to use another codec to encode the Opus stream to another format

Changing audio format

ffmpeg \
    -i input.mp4 \
    -c:v copy \
    -c:a aac -b:a 192k \
    output.mp4

This asks ffmpeg

  • -c:a aac : encode to aac format
  • -b:a 192k : use 192khz bit-rate for the audio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment