or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

audio-processing.mdcodec-operations.mdcommand-line-tools.mdconstants-enums.mdcryptographic-security.mddevice-io.mdformat-handling.mdhardware-acceleration.mdindex.mdmedia-filtering.mdpostproc.mdscaling-conversion.md

command-line-tools.mddocs/

0

# Command-Line Tools

1

2

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

3

4

## Capabilities

5

6

### FFmpeg Executable Access

7

8

#### Process Execution

9

10

```java { .api }

11

/**

12

* Load ffmpeg executable path

13

* Uses Loader.load() to extract and return path to ffmpeg binary

14

*/

15

String ffmpegPath = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);

16

17

/**

18

* Load ffprobe executable path

19

* Uses Loader.load() to extract and return path to ffprobe binary

20

*/

21

String ffprobePath = Loader.load(org.bytedeco.ffmpeg.ffprobe.class);

22

```

23

24

**Usage Example:**

25

26

```java

27

import org.bytedeco.ffmpeg.ffmpeg;

28

import org.bytedeco.ffmpeg.ffprobe;

29

import org.bytedeco.javacpp.Loader;

30

import java.io.IOException;

31

32

// Get executable paths

33

String ffmpegPath = Loader.load(ffmpeg.class);

34

String ffprobePath = Loader.load(ffprobe.class);

35

36

// Transcode video using ffmpeg

37

ProcessBuilder pb = new ProcessBuilder(

38

ffmpegPath,

39

"-i", "input.mp4",

40

"-c:v", "libx264",

41

"-c:a", "aac",

42

"-b:v", "1000k",

43

"-b:a", "128k",

44

"output.mp4"

45

);

46

47

pb.inheritIO(); // Show output in console

48

try {

49

Process process = pb.start();

50

int exitCode = process.waitFor();

51

System.out.println("FFmpeg finished with exit code: " + exitCode);

52

} catch (IOException | InterruptedException e) {

53

e.printStackTrace();

54

}

55

56

// Analyze video using ffprobe

57

ProcessBuilder probePb = new ProcessBuilder(

58

ffprobePath,

59

"-v", "quiet",

60

"-print_format", "json",

61

"-show_format",

62

"-show_streams",

63

"input.mp4"

64

);

65

66

try {

67

Process process = probePb.start();

68

// Read JSON output from process.getInputStream()

69

int exitCode = process.waitFor();

70

} catch (IOException | InterruptedException e) {

71

e.printStackTrace();

72

}

73

```

74

75

### Common FFmpeg Operations

76

77

#### Video Operations

78

79

```java { .api }

80

// Video transcoding

81

String[] transcodeArgs = {

82

ffmpegPath, "-i", "input.mp4",

83

"-c:v", "libx264", "-preset", "medium",

84

"-crf", "23", "-c:a", "aac", "output.mp4"

85

};

86

87

// Video scaling

88

String[] scaleArgs = {

89

ffmpegPath, "-i", "input.mp4",

90

"-vf", "scale=1280:720",

91

"output_720p.mp4"

92

};

93

94

// Extract frames

95

String[] framesArgs = {

96

ffmpegPath, "-i", "input.mp4",

97

"-vf", "fps=1", "frame_%03d.png"

98

};

99

100

// Create video from images

101

String[] imagesArgs = {

102

ffmpegPath, "-framerate", "30",

103

"-i", "frame_%03d.png",

104

"-c:v", "libx264", "output.mp4"

105

};

106

```

107

108

#### Audio Operations

109

110

```java { .api }

111

// Audio extraction

112

String[] extractAudioArgs = {

113

ffmpegPath, "-i", "input.mp4",

114

"-vn", "-c:a", "copy", "audio.aac"

115

};

116

117

// Audio conversion

118

String[] convertAudioArgs = {

119

ffmpegPath, "-i", "input.wav",

120

"-c:a", "libmp3lame", "-b:a", "192k", "output.mp3"

121

};

122

123

// Audio mixing

124

String[] mixArgs = {

125

ffmpegPath, "-i", "music.mp3", "-i", "voice.wav",

126

"-filter_complex", "amix=inputs=2:duration=first",

127

"mixed.mp3"

128

};

129

```

130

131

### FFprobe Operations

132

133

#### Media Analysis

134

135

```java { .api }

136

// Get media information as JSON

137

String[] probeJsonArgs = {

138

ffprobePath, "-v", "quiet",

139

"-print_format", "json",

140

"-show_format", "-show_streams",

141

"input.mp4"

142

};

143

144

// Get specific stream information

145

String[] probeStreamArgs = {

146

ffprobePath, "-v", "error",

147

"-select_streams", "v:0",

148

"-show_entries", "stream=width,height,duration",

149

"-of", "csv=p=0", "input.mp4"

150

};

151

152

// Get frame information

153

String[] probeFramesArgs = {

154

ffprobePath, "-v", "error",

155

"-show_frames", "-select_streams", "v:0",

156

"-print_format", "json", "input.mp4"

157

};

158

```

159

160

### Process Management

161

162

#### Advanced Process Handling

163

164

```java

165

import java.io.*;

166

import java.util.concurrent.TimeUnit;

167

168

public class FFmpegProcess {

169

170

public static ProcessResult runFFmpeg(String[] command, int timeoutMinutes) {

171

ProcessBuilder pb = new ProcessBuilder(command);

172

pb.redirectErrorStream(true);

173

174

try {

175

Process process = pb.start();

176

177

// Capture output

178

StringBuilder output = new StringBuilder();

179

try (BufferedReader reader = new BufferedReader(

180

new InputStreamReader(process.getInputStream()))) {

181

String line;

182

while ((line = reader.readLine()) != null) {

183

output.append(line).append("\n");

184

}

185

}

186

187

// Wait with timeout

188

boolean finished = process.waitFor(timeoutMinutes, TimeUnit.MINUTES);

189

if (!finished) {

190

process.destroyForcibly();

191

return new ProcessResult(-1, "Process timed out", true);

192

}

193

194

return new ProcessResult(process.exitValue(), output.toString(), false);

195

196

} catch (IOException | InterruptedException e) {

197

return new ProcessResult(-1, "Process error: " + e.getMessage(), true);

198

}

199

}

200

201

public static class ProcessResult {

202

public final int exitCode;

203

public final String output;

204

public final boolean error;

205

206

public ProcessResult(int exitCode, String output, boolean error) {

207

this.exitCode = exitCode;

208

this.output = output;

209

this.error = error;

210

}

211

212

public boolean success() {

213

return exitCode == 0 && !error;

214

}

215

}

216

}

217

218

// Usage

219

String[] command = {ffmpegPath, "-i", "input.mp4", "output.mp4"};

220

FFmpegProcess.ProcessResult result = FFmpegProcess.runFFmpeg(command, 10);

221

222

if (result.success()) {

223

System.out.println("Conversion successful");

224

} else {

225

System.err.println("Conversion failed: " + result.output);

226

}

227

```

228

229

## Platform-Specific Considerations

230

231

### Executable Distribution

232

233

The JavaCPP loader automatically extracts platform-specific binaries:

234

235

- **Windows**: `ffmpeg.exe`, `ffprobe.exe`

236

- **Linux**: `ffmpeg`, `ffprobe`

237

- **macOS**: `ffmpeg`, `ffprobe`

238

239

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

240

241

### GPU Acceleration

242

243

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

244

245

```java

246

// NVIDIA NVENC (Windows/Linux)

247

String[] nvencArgs = {

248

ffmpegPath, "-hwaccel", "cuda",

249

"-i", "input.mp4",

250

"-c:v", "h264_nvenc", "output.mp4"

251

};

252

253

// Intel Quick Sync (Windows/Linux)

254

String[] qsvArgs = {

255

ffmpegPath, "-hwaccel", "qsv",

256

"-i", "input.mp4",

257

"-c:v", "h264_qsv", "output.mp4"

258

};

259

260

// VideoToolbox (macOS)

261

String[] vtArgs = {

262

ffmpegPath, "-hwaccel", "videotoolbox",

263

"-i", "input.mp4",

264

"-c:v", "h264_videotoolbox", "output.mp4"

265

};

266

```