Skip to main content
Version: v5.9.0

ni_quadra_crop

The ni_quadra_crop filter provides cropping similar to the FFmpeg soft crop filter but uses the hardware to do the cropping. There are several applications for cropping. One is to handle the cropping specified in the bitstream (i.e. to remove padding added for hardware or codec alignment). The other is to apply cropping specified by the user for applications such as changing the aspect ratio of a picture, i.e. cropping a 16:9 widescreen image to 4:3.

Cropping information in a bitstream is typically added by the encoder, if it needs pads the input picture size to meet the height and width alignment requirements of the codec, for instance H.264 encodes in 16x16 pixel macroblocks.

Another application for cropping is when you need to change the aspect ratio of a video for example when changing a 16:9 widescreen image to the older 4:3 format, the right and left edges of the picture need to be cropped.

Another method of changing aspect ratio is to use scaling and add letterboxing to the top and bottom of the image. Letterboxing requires the pad filter which is described next. Sometimes a combination of both is used. The ni_quadra_crop filter is supported for yuv420p, yuv420p10le, nv12, p010le, rgba, argb, abgr, bgra, bgr0, nv16, yuyv422 and uyvy422.

note

The ni_quadra_crop filter only supports limited color range video (also known as “tv” range). While full range (or “PC” range) video is accepted by the filter, the ni_quadra_crop will clamp to limited color range video before processing. This will cause a slight color shift in the output video.

Parameters​

The following are the ni_quadra_crop parameters:

w, out_w​

The width of the output video. This expression is evaluated only once during the filter configuration, or when the ‘w’ or ‘out_w’ command is sent.

Supported ValuesIntegers from 2 to 8192
Defaultiw (input width)

 h, out_h

The height of the output video. This expression is evaluated only once during the filter configuration, or when the ‘h’ or ‘out_h’ command is sent.

Supported ValuesIntegers from 2 to 8192
Defaultih (input height)

x​

The horizontal position, in the input video, of the left edge of the output video. This expression is evaluated per-frame.

Supported ValuesIntegers from 2 to 8192
Default(in_w-out_w)/2

y​

The vertical position, in the input video, of the top edge of the output video. This expression is evaluated per-frame.

Supported ValuesIntegers from 2 to 8192
Default(in_h-out_h)/2

The out_w, out_h, x, y parameters are expressions containing the following constants:

  • x, y
    • The computed values for x and y. They are evaluated for each new frame.
  • in_w, in_h, iw, ih
    • The input width and height
  • out_w, out_hw, ow, oh
    • The output (cropped) width and height.
  • a
    • Same as iw/ih
  • sar
    • input sample aspect ratio
  • dar
    • input display aspect ratio, it is the same as (iw / ih) * sar
  • hsub, vsub
    • horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" hsub is 2 and vsub is 1.

keep_aspect​

Force the output display aspect ratio to be the same of the input, by changing the output sample aspect ratio.

Supported Values- 0: change aspect ratio
- 1: keep aspect ratio
Default0: change aspect ratio

is_p2p​

Specifies if output buffer of the filter is p2p buffer. When is_p2p is set to 1, the output buffer of the filter is set as p2p buffer and can be read out by p2p read. Else the output buffer is normal and cannot perform p2p.

Supported ValuesBool 0 and 1
Default0

keep_alive_timeout​

Specifies a session keep alive timeout value. This is a periodic request/response between libxcoder and XCoder firmware that when timed out terminates the session instance.

Supported ValuesInteger in the range 1 to 100
Default3

buffer_limit​

Whether to limit the number of output buffers. If enabled, the buffering count of the filter is its buffer pool size(default 4) plus encoding buffering count if its downstream is encoder. It’s enabled by default in FFmpeg-n6.1, FFmpeg-n7.1, FFmpeg 7.1.3, FFmpeg-n8.0.1 and FFmpeg-n8.1.

Supported ValuesInteger 0 and 1.
Default0

auto_skip​

Specifies if to skip the hardware crop when input is the same as the output. When auto-skip is set to 1, frames will pass through the scale filter and no hardware operations will be executed. When auto_skip is set to 0, hardware crop will always be executed regardless of whether the input is the same as the output.

note

auto-skip is only supported with ffmpeg version > 3.4.2. If ffmpeg version < 3.4.2 the hardware operation will always be skipped when the input is the same as output.

Supported ValuesBool 0 and 1
Default0

The following shows an example using ni_quadra_crop. The input is an 852x480 yuv420p frame that is uploaded as a hardware frame using ni_quadra_hwupload and then cropped to 640x480 starting at (0,0) and then encoded to H.265.

ffmpeg -hide_banner -f rawvideo -pix_fmt yuv420p -s:v 852x480 -r 60 -i input852x480.yuv -vf "format=yuv420p,ni_quadra_hwupload=0,ni_quadra_crop=640:480:0:0" -enc -1 -c:v h265_ni_quadra_enc -xcoder-params "RcEnable=1:bitrate=10000000" output640x480.265