[FFmpeg-user] vaapi crop and video size filters

Mark Thompson sw at jkqxz.net
Wed Jan 20 14:47:57 EET 2021

On 20/01/2021 03:06, owen s wrote:
> with software libx264 using crop filter
> crop=width:heigh:x:y, i could crop around a specific point. using
> h264_vaapi and -vf crop=width:height
> doesn't control the crop location.
> also with libx264 -video_size=widthxheight worked, but with h264_vaapi, the
> video resolution comes out to be the max size of the video framebuffer
> 65535x65535 in my case.
> Can I set where the h264_vaapi crop x,y position and how do I control the
> resolution after using h264_vaapi?
> log file: http://0x0.st/-ifF.txt

This crops your 2560x1440 input to 2560x1440 so it is unsurprising that nothing happens.

More generally, cropping is supported by VAAPI filters but not by the encoder (due to internal API constraints which probably derive from actual hardware constraints).

Therefore, you should crop either before upload (if you are uploading) or before applying a filter (when staying in VAAPI surfaces).  If you aren't filtering at all (pure decode->encode), then you need to insert a null scale before the encode (which is an extra copy, but can't be avoided when the encoder doesn't support that input).


ffmpeg -i ... -vf crop=...,format=nv12,hwupload -c:v h264_vaapi ...

ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i ... -vf crop=...,scale_vaapi=... -c:v h264_vaapi ...

- Mark

More information about the ffmpeg-user mailing list