Skip to content

node-av / lib / avImageCrop

Function: avImageCrop()

avImageCrop(dstBuffer, srcBuffer, pixFmt, srcWidth, srcHeight, cropX, cropY, cropWidth, cropHeight): number

Defined in: src/lib/utilities.ts:833

Image crop function.

Crops an image region from source buffer to destination buffer.

Parameters

dstBuffer

Buffer

Destination buffer (must be pre-allocated)

srcBuffer

Buffer

Source buffer containing the image

pixFmt

AVPixelFormat

Pixel format

srcWidth

number

Source image width

srcHeight

number

Source image height

cropX

number

X coordinate of crop region (left)

cropY

number

Y coordinate of crop region (top)

cropWidth

number

Width of crop region

cropHeight

number

Height of crop region

Returns

number

Number of bytes copied

Example

typescript
import { AV_PIX_FMT_NV12 } from 'node-av/constants';

const dstSize = avImageGetBufferSize(AV_PIX_FMT_NV12, 100, 100, 1);
const dstBuffer = Buffer.alloc(dstSize);

const bytesCopied = avImageCrop(
  dstBuffer, srcBuffer,
  AV_PIX_FMT_NV12,
  320, 180,  // source dimensions
  10, 10,    // crop position
  100, 100   // crop size
);