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

media-filtering.mddocs/

0

# Media Filtering

1

2

Comprehensive audio and video filtering pipeline for effects, transformations, format conversions, and complex processing graphs using FFmpeg's libavfilter.

3

4

## Capabilities

5

6

### Filter Graph Management

7

8

#### Graph Operations

9

10

```java { .api }

11

/**

12

* Allocate a filter graph

13

* @return Allocated filter graph or null on failure

14

*/

15

AVFilterGraph avfilter_graph_alloc();

16

17

/**

18

* Free filter graph and all filters in it

19

* @param graph Pointer to filter graph to free

20

*/

21

void avfilter_graph_free(AVFilterGraph graph);

22

23

/**

24

* Check and configure filter graph

25

* @param graphctx Filter graph to configure

26

* @param log_ctx Logging context

27

* @return >= 0 on success

28

*/

29

int avfilter_graph_config(AVFilterGraph graphctx, Pointer log_ctx);

30

31

/**

32

* Create filter instance in graph

33

* @param filt_ctx Pointer to receive filter context

34

* @param filt Filter definition

35

* @param name Instance name

36

* @param args Filter arguments

37

* @param opaque User data

38

* @param graph_ctx Parent graph

39

* @return >= 0 on success

40

*/

41

int avfilter_graph_create_filter(AVFilterContext filt_ctx, AVFilter filt,

42

String name, String args, Pointer opaque, AVFilterGraph graph_ctx);

43

```

44

45

### Filter Discovery

46

47

#### Finding Filters

48

49

```java { .api }

50

/**

51

* Get filter by name

52

* @param name Filter name

53

* @return Filter definition or null if not found

54

*/

55

AVFilter avfilter_get_by_name(String name);

56

57

/**

58

* Iterate over all registered filters

59

* @param opaque Iterator state

60

* @return Next filter or null when done

61

*/

62

AVFilter av_filter_iterate(Pointer opaque);

63

```

64

65

### Filter Linking

66

67

#### Connecting Filters

68

69

```java { .api }

70

/**

71

* Link two filters together

72

* @param src Source filter context

73

* @param srcpad Source pad index

74

* @param dst Destination filter context

75

* @param dstpad Destination pad index

76

* @return >= 0 on success

77

*/

78

int avfilter_link(AVFilterContext src, int srcpad, AVFilterContext dst, int dstpad);

79

80

/**

81

* Add frame to filter input

82

* @param link Filter link

83

* @param frame Frame to add

84

* @return >= 0 on success

85

*/

86

int av_buffersrc_add_frame(AVFilterContext ctx, AVFrame frame);

87

88

/**

89

* Get frame from filter output

90

* @param link Filter link

91

* @param frame Frame to receive data

92

* @return >= 0 on success

93

*/

94

int av_buffersink_get_frame(AVFilterContext ctx, AVFrame frame);

95

```

96

97

**Usage Example:**

98

99

```java

100

import org.bytedeco.ffmpeg.avfilter.*;

101

import static org.bytedeco.ffmpeg.global.avfilter.*;

102

103

// Create filter graph

104

AVFilterGraph filterGraph = avfilter_graph_alloc();

105

106

// Create buffer source (input)

107

AVFilter bufferSrc = avfilter_get_by_name("buffer");

108

AVFilterContext bufferCtx = new AVFilterContext(null);

109

String args = String.format("width=%d:height=%d:pix_fmt=%d:time_base=1/30:pixel_aspect=1/1",

110

1920, 1080, AV_PIX_FMT_YUV420P);

111

avfilter_graph_create_filter(bufferCtx, bufferSrc, "in", args, null, filterGraph);

112

113

// Create scale filter

114

AVFilter scaleFilter = avfilter_get_by_name("scale");

115

AVFilterContext scaleCtx = new AVFilterContext(null);

116

avfilter_graph_create_filter(scaleCtx, scaleFilter, "scale", "640:480", null, filterGraph);

117

118

// Create buffer sink (output)

119

AVFilter bufferSink = avfilter_get_by_name("buffersink");

120

AVFilterContext sinkCtx = new AVFilterContext(null);

121

avfilter_graph_create_filter(sinkCtx, bufferSink, "out", null, null, filterGraph);

122

123

// Link filters: input -> scale -> output

124

avfilter_link(bufferCtx, 0, scaleCtx, 0);

125

avfilter_link(scaleCtx, 0, sinkCtx, 0);

126

127

// Configure graph

128

avfilter_graph_config(filterGraph, null);

129

130

// Process frames

131

AVFrame inputFrame = av_frame_alloc();

132

AVFrame outputFrame = av_frame_alloc();

133

134

// Add input frame

135

av_buffersrc_add_frame(bufferCtx, inputFrame);

136

137

// Get output frame

138

while (av_buffersink_get_frame(sinkCtx, outputFrame) >= 0) {

139

// Process output frame

140

System.out.println("Filtered frame: " + outputFrame.width() + "x" + outputFrame.height());

141

av_frame_unref(outputFrame);

142

}

143

144

// Cleanup

145

av_frame_free(inputFrame);

146

av_frame_free(outputFrame);

147

avfilter_graph_free(filterGraph);

148

```

149

150

### Common Filters

151

152

#### Video Filters

153

154

```java { .api }

155

// Scale filter - resize video

156

"scale=width:height[:flags]"

157

158

// Crop filter - crop video to region

159

"crop=width:height:x:y"

160

161

// Overlay filter - overlay one video on another

162

"overlay=x:y[:options]"

163

164

// Rotate filter - rotate video

165

"rotate=angle*PI/180"

166

167

// Blur filter - apply blur effect

168

"boxblur=luma_radius:luma_power:chroma_radius:chroma_power"

169

170

// Color adjustment

171

"eq=brightness:contrast:saturation:gamma"

172

```

173

174

#### Audio Filters

175

176

```java { .api }

177

// Volume filter - adjust audio volume

178

"volume=volume[:precision]"

179

180

// Audio resample - change sample rate

181

"aresample=sample_rate"

182

183

// Audio format - change audio format

184

"aformat=sample_fmts:sample_rates:channel_layouts"

185

186

// Audio mix - mix multiple audio streams

187

"amix=inputs:duration:dropout_transition"

188

189

// Audio delay

190

"adelay=delays:all"

191

```

192

193

### Filter Context Information

194

195

#### Filter Properties

196

197

```java { .api }

198

/**

199

* Filter context representing filter instance

200

*/

201

class AVFilterContext extends Pointer {

202

/** Filter definition */

203

AVFilter filter();

204

205

/** Instance name */

206

BytePointer name();

207

208

/** Number of input pads */

209

int nb_inputs();

210

211

/** Number of output pads */

212

int nb_outputs();

213

214

/** Input pads */

215

AVFilterPad input_pads();

216

217

/** Output pads */

218

AVFilterPad output_pads();

219

}

220

221

/**

222

* Filter definition

223

*/

224

class AVFilter extends Pointer {

225

/** Filter name */

226

BytePointer name();

227

228

/** Filter description */

229

BytePointer description();

230

231

/** Input pad descriptors */

232

AVFilterPad inputs();

233

234

/** Output pad descriptors */

235

AVFilterPad outputs();

236

237

/** Filter flags */

238

int flags();

239

}

240

```

241

242

## Constants

243

244

### Filter Flags

245

246

```java { .api }

247

// Filter capability flags

248

int AVFILTER_FLAG_DYNAMIC_INPUTS = 1; // Number of inputs can change

249

int AVFILTER_FLAG_DYNAMIC_OUTPUTS = 2; // Number of outputs can change

250

int AVFILTER_FLAG_SLICE_THREADS = 4; // Filter supports slice threading

251

int AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC = 16; // Filter supports timeline

252

int AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL = 32; // Filter supports internal timeline

253

```