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

audio-processing.mddocs/

Audio Processing

Audio resampling, channel layout conversion, and sample format transformations using FFmpeg's libswresample for comprehensive audio processing.

Capabilities

Resampling Context Management

Context Operations

/**
 * Allocate SwrContext
 * @return Allocated context or null on failure
 */
SwrContext swr_alloc();

/**
 * Initialize context after setting parameters
 * @param s Resampling context
 * @return >= 0 on success
 */
int swr_init(SwrContext s);

/**
 * Free resampling context
 * @param s Pointer to context to free
 */
void swr_free(SwrContext s);

/**
 * Convert audio samples
 * @param s Resampling context
 * @param out Output buffer pointers
 * @param out_count Maximum output samples per channel
 * @param in Input buffer pointers
 * @param in_count Input samples per channel
 * @return Number of output samples per channel, negative on error
 */
int swr_convert(SwrContext s, PointerPointer out, int out_count,
    PointerPointer in, int in_count);

Usage Example:

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

// Create resampling context
SwrContext swrContext = swr_alloc();

// Set input parameters
av_opt_set_int(swrContext, "in_channel_layout", AV_CH_LAYOUT_STEREO, 0);
av_opt_set_int(swrContext, "in_sample_rate", 44100, 0);
av_opt_set_sample_fmt(swrContext, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);

// Set output parameters  
av_opt_set_int(swrContext, "out_channel_layout", AV_CH_LAYOUT_MONO, 0);
av_opt_set_int(swrContext, "out_sample_rate", 22050, 0);
av_opt_set_sample_fmt(swrContext, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);

// Initialize
int result = swr_init(swrContext);
if (result < 0) {
    throw new RuntimeException("Cannot initialize resampler");
}

// Convert audio
PointerPointer inputData = /* ... input audio data ... */;
PointerPointer outputData = /* ... output buffer ... */;
int outputSamples = swr_convert(swrContext, outputData, 1024, inputData, 2048);

System.out.println("Converted " + outputSamples + " samples");

// Cleanup
swr_free(swrContext);

Channel Layout Operations

Channel Management

/**
 * Get default channel layout for given number of channels
 * @param nb_channels Number of channels
 * @return Channel layout
 */
long av_get_default_channel_layout(int nb_channels);

/**
 * Get number of channels in layout
 * @param channel_layout Channel layout
 * @return Number of channels
 */
int av_get_channel_layout_nb_channels(long channel_layout);

/**
 * Get channel layout string
 * @param buf Buffer for result
 * @param buf_size Buffer size
 * @param nb_channels Number of channels
 * @param channel_layout Channel layout
 * @return 0 on success
 */
int av_get_channel_layout_string(BytePointer buf, int buf_size, int nb_channels, long channel_layout);

Constants

Channel Layouts

// Standard channel layouts
long AV_CH_LAYOUT_MONO = 0x4;           // Center
long AV_CH_LAYOUT_STEREO = 0x3;         // Left + Right
long AV_CH_LAYOUT_2POINT1 = 0x103;      // Stereo + LFE
long AV_CH_LAYOUT_SURROUND = 0x7;       // Stereo + Center
long AV_CH_LAYOUT_4POINT0 = 0x107;      // Surround + Back Center
long AV_CH_LAYOUT_5POINT0 = 0x607;      // 4.0 + Side Left/Right
long AV_CH_LAYOUT_5POINT1 = 0x70F;      // 5.0 + LFE
long AV_CH_LAYOUT_7POINT1 = 0x1C07;     // 5.1 + Back Left/Right

Sample Formats

// Audio sample formats
int AV_SAMPLE_FMT_U8 = 0;          // Unsigned 8-bit
int AV_SAMPLE_FMT_S16 = 1;         // Signed 16-bit
int AV_SAMPLE_FMT_S32 = 2;         // Signed 32-bit
int AV_SAMPLE_FMT_FLT = 3;         // Float
int AV_SAMPLE_FMT_DBL = 4;         // Double
int AV_SAMPLE_FMT_U8P = 5;         // Unsigned 8-bit planar
int AV_SAMPLE_FMT_S16P = 6;        // Signed 16-bit planar
int AV_SAMPLE_FMT_S32P = 7;        // Signed 32-bit planar
int AV_SAMPLE_FMT_FLTP = 8;        // Float planar
int AV_SAMPLE_FMT_DBLP = 9;        // Double planar

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