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

command-line-tools.mddocs/

Command-Line Tools

Direct access to ffmpeg and ffprobe executables for complex operations and external processing workflows.

Capabilities

FFmpeg Executable Access

Process Execution

/**
 * Load ffmpeg executable path
 * Uses Loader.load() to extract and return path to ffmpeg binary
 */
String ffmpegPath = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);

/**
 * Load ffprobe executable path  
 * Uses Loader.load() to extract and return path to ffprobe binary
 */
String ffprobePath = Loader.load(org.bytedeco.ffmpeg.ffprobe.class);

Usage Example:

import org.bytedeco.ffmpeg.ffmpeg;
import org.bytedeco.ffmpeg.ffprobe;
import org.bytedeco.javacpp.Loader;
import java.io.IOException;

// Get executable paths
String ffmpegPath = Loader.load(ffmpeg.class);
String ffprobePath = Loader.load(ffprobe.class);

// Transcode video using ffmpeg
ProcessBuilder pb = new ProcessBuilder(
    ffmpegPath,
    "-i", "input.mp4",
    "-c:v", "libx264",
    "-c:a", "aac", 
    "-b:v", "1000k",
    "-b:a", "128k",
    "output.mp4"
);

pb.inheritIO(); // Show output in console
try {
    Process process = pb.start();
    int exitCode = process.waitFor();
    System.out.println("FFmpeg finished with exit code: " + exitCode);
} catch (IOException | InterruptedException e) {
    e.printStackTrace();
}

// Analyze video using ffprobe
ProcessBuilder probePb = new ProcessBuilder(
    ffprobePath,
    "-v", "quiet",
    "-print_format", "json", 
    "-show_format",
    "-show_streams",
    "input.mp4"
);

try {
    Process process = probePb.start();
    // Read JSON output from process.getInputStream()
    int exitCode = process.waitFor();
} catch (IOException | InterruptedException e) {
    e.printStackTrace();
}

Common FFmpeg Operations

Video Operations

// Video transcoding
String[] transcodeArgs = {
    ffmpegPath, "-i", "input.mp4",
    "-c:v", "libx264", "-preset", "medium",
    "-crf", "23", "-c:a", "aac", "output.mp4"
};

// Video scaling
String[] scaleArgs = {
    ffmpegPath, "-i", "input.mp4", 
    "-vf", "scale=1280:720",
    "output_720p.mp4"
};

// Extract frames
String[] framesArgs = {
    ffmpegPath, "-i", "input.mp4",
    "-vf", "fps=1", "frame_%03d.png"
};

// Create video from images
String[] imagesArgs = {
    ffmpegPath, "-framerate", "30",
    "-i", "frame_%03d.png",
    "-c:v", "libx264", "output.mp4"
};

Audio Operations

// Audio extraction
String[] extractAudioArgs = {
    ffmpegPath, "-i", "input.mp4",
    "-vn", "-c:a", "copy", "audio.aac"
};

// Audio conversion
String[] convertAudioArgs = {
    ffmpegPath, "-i", "input.wav",
    "-c:a", "libmp3lame", "-b:a", "192k", "output.mp3"
};

// Audio mixing
String[] mixArgs = {
    ffmpegPath, "-i", "music.mp3", "-i", "voice.wav",
    "-filter_complex", "amix=inputs=2:duration=first",
    "mixed.mp3"
};

FFprobe Operations

Media Analysis

// Get media information as JSON
String[] probeJsonArgs = {
    ffprobePath, "-v", "quiet",
    "-print_format", "json",
    "-show_format", "-show_streams",
    "input.mp4"
};

// Get specific stream information  
String[] probeStreamArgs = {
    ffprobePath, "-v", "error",
    "-select_streams", "v:0",
    "-show_entries", "stream=width,height,duration",
    "-of", "csv=p=0", "input.mp4"
};

// Get frame information
String[] probeFramesArgs = {
    ffprobePath, "-v", "error",
    "-show_frames", "-select_streams", "v:0", 
    "-print_format", "json", "input.mp4"
};

Process Management

Advanced Process Handling

import java.io.*;
import java.util.concurrent.TimeUnit;

public class FFmpegProcess {
    
    public static ProcessResult runFFmpeg(String[] command, int timeoutMinutes) {
        ProcessBuilder pb = new ProcessBuilder(command);
        pb.redirectErrorStream(true);
        
        try {
            Process process = pb.start();
            
            // Capture output
            StringBuilder output = new StringBuilder();
            try (BufferedReader reader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    output.append(line).append("\n");
                }
            }
            
            // Wait with timeout
            boolean finished = process.waitFor(timeoutMinutes, TimeUnit.MINUTES);
            if (!finished) {
                process.destroyForcibly();
                return new ProcessResult(-1, "Process timed out", true);
            }
            
            return new ProcessResult(process.exitValue(), output.toString(), false);
            
        } catch (IOException | InterruptedException e) {
            return new ProcessResult(-1, "Process error: " + e.getMessage(), true);
        }
    }
    
    public static class ProcessResult {
        public final int exitCode;
        public final String output;
        public final boolean error;
        
        public ProcessResult(int exitCode, String output, boolean error) {
            this.exitCode = exitCode;
            this.output = output;
            this.error = error;
        }
        
        public boolean success() {
            return exitCode == 0 && !error;
        }
    }
}

// Usage
String[] command = {ffmpegPath, "-i", "input.mp4", "output.mp4"};
FFmpegProcess.ProcessResult result = FFmpegProcess.runFFmpeg(command, 10);

if (result.success()) {
    System.out.println("Conversion successful");
} else {
    System.err.println("Conversion failed: " + result.output);
}

Platform-Specific Considerations

Executable Distribution

The JavaCPP loader automatically extracts platform-specific binaries:

  • Windows: ffmpeg.exe, ffprobe.exe
  • Linux: ffmpeg, ffprobe
  • macOS: ffmpeg, ffprobe

Binaries are extracted to temporary directory and path returned by Loader.load().

GPU Acceleration

Platform-specific hardware acceleration can be enabled via command-line options:

// NVIDIA NVENC (Windows/Linux)
String[] nvencArgs = {
    ffmpegPath, "-hwaccel", "cuda",
    "-i", "input.mp4",
    "-c:v", "h264_nvenc", "output.mp4"
};

// Intel Quick Sync (Windows/Linux)
String[] qsvArgs = {
    ffmpegPath, "-hwaccel", "qsv", 
    "-i", "input.mp4",
    "-c:v", "h264_qsv", "output.mp4"
};

// VideoToolbox (macOS)
String[] vtArgs = {
    ffmpegPath, "-hwaccel", "videotoolbox",
    "-i", "input.mp4", 
    "-c:v", "h264_videotoolbox", "output.mp4"
};

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