CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-bytedeco--ffmpeg

JavaCPP bindings for FFmpeg multimedia framework providing comprehensive Java access to audio/video encoding, decoding, filtering, and format conversion

Pending
Overview
Eval results
Files

scaling-conversion.mddocs/

Scaling and Format Conversion

Video scaling, pixel format conversion, and color space transformations using FFmpeg's libswscale with optimized implementations for performance.

Capabilities

Scaling Context Management

Context Operations

/**
 * Allocate and initialize scaling context
 * @param srcW Source width
 * @param srcH Source height  
 * @param srcFormat Source pixel format
 * @param dstW Destination width
 * @param dstH Destination height
 * @param dstFormat Destination pixel format
 * @param flags Scaling algorithm flags
 * @param srcFilter Source filter (optional)
 * @param dstFilter Destination filter (optional)
 * @param param Additional parameters (optional)
 * @return Scaling context or null on failure
 */
SwsContext sws_getContext(int srcW, int srcH, int srcFormat,
    int dstW, int dstH, int dstFormat, int flags,
    SwsFilter srcFilter, SwsFilter dstFilter, DoublePointer param);

/**
 * Free scaling context
 * @param swsContext Context to free
 */
void sws_freeContext(SwsContext swsContext);

/**
 * Scale image data
 * @param c Scaling context
 * @param srcSlice Source image planes
 * @param srcStride Source line strides
 * @param srcSliceY Starting Y position
 * @param srcSliceH Height to process
 * @param dst Destination image planes
 * @param dstStride Destination line strides
 * @return Height of output slice
 */
int sws_scale(SwsContext c, PointerPointer srcSlice, IntPointer srcStride,
    int srcSliceY, int srcSliceH, PointerPointer dst, IntPointer dstStride);

Usage Example:

import org.bytedeco.ffmpeg.swscale.*;
import static org.bytedeco.ffmpeg.global.swscale.*;
import static org.bytedeco.ffmpeg.global.avutil.*;

// Create scaling context: 1920x1080 -> 640x480, YUV420P -> RGB24
SwsContext swsContext = sws_getContext(
    1920, 1080, AV_PIX_FMT_YUV420P,    // Source
    640, 480, AV_PIX_FMT_RGB24,        // Destination  
    SWS_BILINEAR,                       // Scaling algorithm
    null, null, (DoublePointer)null     // Optional filters/params
);

if (swsContext == null) {
    throw new RuntimeException("Cannot create scaling context");
}

// Allocate destination frame
AVFrame dstFrame = av_frame_alloc();
dstFrame.width(640);
dstFrame.height(480);
dstFrame.format(AV_PIX_FMT_RGB24);
av_frame_get_buffer(dstFrame, 32);

// Scale source frame to destination
AVFrame srcFrame = /* ... source frame ... */;
int result = sws_scale(
    swsContext,
    srcFrame.data(), srcFrame.linesize(),
    0, srcFrame.height(),
    dstFrame.data(), dstFrame.linesize()
);

System.out.println("Scaled " + result + " lines");

// Cleanup
av_frame_free(dstFrame);
sws_freeContext(swsContext);

Advanced Scaling

Cached Context Operations

/**
 * Scale with cached context (allocates if needed)
 * @param context Pointer to context (null initially)
 * @param srcW Source width
 * @param srcH Source height
 * @param srcFormat Source format
 * @param dstW Destination width
 * @param dstH Destination height
 * @param dstFormat Destination format
 * @param flags Scaling flags
 * @param srcFilter Source filter
 * @param dstFilter Destination filter
 * @param param Parameters
 * @return Scaling context
 */
SwsContext sws_getCachedContext(SwsContext context,
    int srcW, int srcH, int srcFormat,
    int dstW, int dstH, int dstFormat, int flags,
    SwsFilter srcFilter, SwsFilter dstFilter, DoublePointer param);

/**
 * Check if scaling is supported
 * @param pix_fmt Pixel format
 * @return 1 if supported for input, 2 if supported for output
 */
int sws_isSupportedInput(int pix_fmt);
int sws_isSupportedOutput(int pix_fmt);

Vector Operations

SIMD Optimizations

/**
 * Get CPU flags for optimization
 * @return CPU capability flags
 */
int av_get_cpu_flags();

/**
 * Initialize scaling context with CPU optimizations
 * @param c Scaling context
 * @param srcFilter Source filter
 * @param dstFilter Destination filter
 * @return 0 on success
 */
int sws_init_context(SwsContext c, SwsFilter srcFilter, SwsFilter dstFilter);

Color Space Operations

Color Space Information

/**
 * Get coefficients for color space conversion
 * @param colorspace Color space (BT.709, BT.601, etc.)
 * @return Color space coefficients
 */
IntPointer sws_getCoefficients(int colorspace);

/**
 * Set color space conversion parameters
 * @param c Scaling context
 * @param inv_table Inverse color table
 * @param fullRange Full range flag
 * @param table Color conversion table
 * @param srcRange Source range
 * @param dstRange Destination range
 * @param brightness Brightness adjustment
 * @param contrast Contrast adjustment
 * @param saturation Saturation adjustment
 * @return 0 on success
 */
int sws_setColorspaceDetails(SwsContext c, IntPointer inv_table, int fullRange,
    IntPointer table, int srcRange, int dstRange, int brightness, int contrast, int saturation);

Constants

Scaling Algorithms

// Scaling algorithm flags
int SWS_FAST_BILINEAR = 1;      // Fast bilinear
int SWS_BILINEAR = 2;           // Bilinear
int SWS_BICUBIC = 4;            // Bicubic  
int SWS_X = 8;                  // Experimental
int SWS_POINT = 0x10;           // Nearest neighbor
int SWS_AREA = 0x20;            // Area averaging
int SWS_BICUBLIN = 0x40;        // Bicubic for luma, bilinear for chroma
int SWS_GAUSS = 0x80;           // Gaussian
int SWS_SINC = 0x100;           // Sinc
int SWS_LANCZOS = 0x200;        // Lanczos
int SWS_SPLINE = 0x400;         // Spline

Pixel Formats

// Common pixel formats for scaling
int AV_PIX_FMT_YUV420P = 0;     // Planar YUV 4:2:0
int AV_PIX_FMT_RGB24 = 2;       // Packed RGB 8:8:8
int AV_PIX_FMT_BGR24 = 3;       // Packed BGR 8:8:8
int AV_PIX_FMT_YUV422P = 4;     // Planar YUV 4:2:2
int AV_PIX_FMT_YUV444P = 5;     // Planar YUV 4:4:4
int AV_PIX_FMT_RGBA = 26;       // Packed RGBA 8:8:8:8
int AV_PIX_FMT_BGRA = 27;       // Packed BGRA 8:8:8:8
int AV_PIX_FMT_NV12 = 23;       // Semi-planar YUV 4:2:0
int AV_PIX_FMT_NV21 = 24;       // Semi-planar YUV 4:2:0

Color Space Constants

// Color space standards
int SWS_CS_ITU709 = 1;          // ITU-R BT.709
int SWS_CS_FCC = 4;             // FCC
int SWS_CS_ITU601 = 5;          // ITU-R BT.601
int SWS_CS_SMPTE170M = 6;       // SMPTE-170M
int SWS_CS_SMPTE240M = 7;       // SMPTE-240M
int SWS_CS_DEFAULT = 5;         // Default (BT.601)

Install with Tessl CLI

npx tessl i tessl/maven-org-bytedeco--ffmpeg

docs

audio-processing.md

codec-operations.md

command-line-tools.md

constants-enums.md

cryptographic-security.md

device-io.md

format-handling.md

hardware-acceleration.md

index.md

media-filtering.md

postproc.md

scaling-conversion.md

tile.json