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

device-io.mddocs/

0

# Device I/O

1

2

Device enumeration and access for cameras, microphones, and other multimedia input/output devices across platforms using FFmpeg's libavdevice.

3

4

## Capabilities

5

6

### Device Enumeration

7

8

#### Device Discovery

9

10

```java { .api }

11

/**

12

* List devices for input format

13

* @param s Format context

14

* @param device_list Pointer to receive device list

15

* @return >= 0 on success

16

*/

17

int avdevice_list_devices(AVFormatContext s, AVDeviceInfoList device_list);

18

19

/**

20

* List input sources for device

21

* @param device Input format

22

* @param device_name Device name (optional)

23

* @param device_options Device options (optional)

24

* @param device_list Pointer to receive device list

25

* @return >= 0 on success

26

*/

27

int avdevice_list_input_sources(AVInputFormat device, String device_name,

28

AVDictionary device_options, AVDeviceInfoList device_list);

29

30

/**

31

* List output sinks for device

32

* @param device Output format

33

* @param device_name Device name (optional)

34

* @param device_options Device options (optional)

35

* @param device_list Pointer to receive device list

36

* @return >= 0 on success

37

*/

38

int avdevice_list_output_sinks(AVOutputFormat device, String device_name,

39

AVDictionary device_options, AVDeviceInfoList device_list);

40

41

/**

42

* Free device list

43

* @param device_list Device list to free

44

*/

45

void avdevice_free_list_devices(AVDeviceInfoList device_list);

46

```

47

48

**Usage Example:**

49

50

```java

51

import org.bytedeco.ffmpeg.avdevice.*;

52

import org.bytedeco.ffmpeg.avformat.*;

53

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

54

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

55

56

// Initialize device library

57

avdevice_register_all();

58

59

// Find video4linux2 input format (Linux)

60

AVInputFormat v4l2Format = av_find_input_format("v4l2");

61

if (v4l2Format != null) {

62

AVDeviceInfoList deviceList = new AVDeviceInfoList();

63

int result = avdevice_list_input_sources(v4l2Format, null, null, deviceList);

64

65

if (result >= 0) {

66

System.out.println("Found " + deviceList.nb_devices() + " video devices:");

67

for (int i = 0; i < deviceList.nb_devices(); i++) {

68

AVDeviceInfo device = deviceList.devices(i);

69

System.out.println("Device: " + device.device_name().getString());

70

System.out.println("Description: " + device.device_description().getString());

71

}

72

avdevice_free_list_devices(deviceList);

73

}

74

}

75

```

76

77

### Device Opening

78

79

#### Device Access

80

81

```java { .api }

82

/**

83

* Register all device formats

84

*/

85

void avdevice_register_all();

86

87

/**

88

* Send control message to device

89

* @param s Format context

90

* @param type Message type

91

* @param data Message data

92

* @param data_size Data size

93

* @return >= 0 on success

94

*/

95

int avdevice_dev_to_app_control_message(AVFormatContext s, int type, Pointer data, long data_size);

96

97

/**

98

* Receive control message from device

99

* @param s Format context

100

* @param type Message type

101

* @param data Message data

102

* @param data_size Data size

103

* @return >= 0 on success

104

*/

105

int avdevice_app_to_dev_control_message(AVFormatContext s, int type, Pointer data, long data_size);

106

```

107

108

### Platform-Specific Devices

109

110

#### Common Device Names

111

112

```java { .api }

113

// Linux (Video4Linux2)

114

"v4l2" // Video capture devices

115

"alsa" // Audio capture/playback

116

"pulse" // PulseAudio

117

118

// Windows

119

"dshow" // DirectShow devices

120

"gdigrab" // Screen capture

121

"wasapi" // Windows Audio Session API

122

123

// macOS

124

"avfoundation" // AVFoundation devices

125

"qtkit" // QuickTime Kit (deprecated)

126

127

// Cross-platform

128

"lavfi" // Libavfilter virtual devices

129

"sdl" // SDL output

130

```

131

132

## Data Structures

133

134

### Device Information

135

136

```java { .api }

137

/**

138

* Device information structure

139

*/

140

class AVDeviceInfo extends Pointer {

141

/** Device name/identifier */

142

BytePointer device_name();

143

144

/** Human-readable description */

145

BytePointer device_description();

146

147

/** Media types supported */

148

IntPointer media_types();

149

150

/** Number of media types */

151

int nb_media_types();

152

}

153

154

/**

155

* List of devices

156

*/

157

class AVDeviceInfoList extends Pointer {

158

/** Array of device info */

159

PointerPointer devices();

160

161

/** Number of devices */

162

int nb_devices();

163

164

/** Default device index */

165

int default_device();

166

}

167

```

168

169

## Constants

170

171

### Device Types

172

173

```java { .api }

174

// Media types for devices

175

int AVMEDIA_TYPE_VIDEO = 0; // Video devices

176

int AVMEDIA_TYPE_AUDIO = 1; // Audio devices

177

int AVMEDIA_TYPE_DATA = 2; // Data devices

178

```