Hardware (VAAPI) accelerated video format conversion
Using FFMPEG CLI for converting videos
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.mp4This asks ffmpeg
-
-hwaccel vaapi: to use vaapi hardware accel device -
-vaapi_device DEVICE: where to find the device -
format=nv12: to first format asnv12 -
hwupload: to upload to GPUVAAPI 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 GPUUse
-c:v libx264for slower, but better quality encoding in CPU -
-q:v 21: sets the video Quality Param to 21See Quality Param section below
With VAAPI
- QP 18–22: good quality
- QP 24–30: visible artifacts
- QP 12–16: very high quality / large files
FFMPEG can be used to change container formats (.mp4, .mkv, .webm)
ffmpeg \
-i input.mp4 \
-c:v copy \
-c:a copy \
output.mkvThis asks ffmpeg
c:v copy: copy the video stream without decodingc: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
ffmpeg \
-i input.mp4 \
-c:v copy \
-c:a aac -b:a 192k \
output.mp4This asks ffmpeg
-c:a aac: encode to aac format-b:a 192k: use 192khz bit-rate for the audio