JavaCPP bindings for FFmpeg multimedia framework providing comprehensive Java access to audio/video encoding, decoding, filtering, and format conversion
—
Device enumeration and access for cameras, microphones, and other multimedia input/output devices across platforms using FFmpeg's libavdevice.
/**
* List devices for input format
* @param s Format context
* @param device_list Pointer to receive device list
* @return >= 0 on success
*/
int avdevice_list_devices(AVFormatContext s, AVDeviceInfoList device_list);
/**
* List input sources for device
* @param device Input format
* @param device_name Device name (optional)
* @param device_options Device options (optional)
* @param device_list Pointer to receive device list
* @return >= 0 on success
*/
int avdevice_list_input_sources(AVInputFormat device, String device_name,
AVDictionary device_options, AVDeviceInfoList device_list);
/**
* List output sinks for device
* @param device Output format
* @param device_name Device name (optional)
* @param device_options Device options (optional)
* @param device_list Pointer to receive device list
* @return >= 0 on success
*/
int avdevice_list_output_sinks(AVOutputFormat device, String device_name,
AVDictionary device_options, AVDeviceInfoList device_list);
/**
* Free device list
* @param device_list Device list to free
*/
void avdevice_free_list_devices(AVDeviceInfoList device_list);Usage Example:
import org.bytedeco.ffmpeg.avdevice.*;
import org.bytedeco.ffmpeg.avformat.*;
import static org.bytedeco.ffmpeg.global.avdevice.*;
import static org.bytedeco.ffmpeg.global.avformat.*;
// Initialize device library
avdevice_register_all();
// Find video4linux2 input format (Linux)
AVInputFormat v4l2Format = av_find_input_format("v4l2");
if (v4l2Format != null) {
AVDeviceInfoList deviceList = new AVDeviceInfoList();
int result = avdevice_list_input_sources(v4l2Format, null, null, deviceList);
if (result >= 0) {
System.out.println("Found " + deviceList.nb_devices() + " video devices:");
for (int i = 0; i < deviceList.nb_devices(); i++) {
AVDeviceInfo device = deviceList.devices(i);
System.out.println("Device: " + device.device_name().getString());
System.out.println("Description: " + device.device_description().getString());
}
avdevice_free_list_devices(deviceList);
}
}/**
* Register all device formats
*/
void avdevice_register_all();
/**
* Send control message to device
* @param s Format context
* @param type Message type
* @param data Message data
* @param data_size Data size
* @return >= 0 on success
*/
int avdevice_dev_to_app_control_message(AVFormatContext s, int type, Pointer data, long data_size);
/**
* Receive control message from device
* @param s Format context
* @param type Message type
* @param data Message data
* @param data_size Data size
* @return >= 0 on success
*/
int avdevice_app_to_dev_control_message(AVFormatContext s, int type, Pointer data, long data_size);// Linux (Video4Linux2)
"v4l2" // Video capture devices
"alsa" // Audio capture/playback
"pulse" // PulseAudio
// Windows
"dshow" // DirectShow devices
"gdigrab" // Screen capture
"wasapi" // Windows Audio Session API
// macOS
"avfoundation" // AVFoundation devices
"qtkit" // QuickTime Kit (deprecated)
// Cross-platform
"lavfi" // Libavfilter virtual devices
"sdl" // SDL output/**
* Device information structure
*/
class AVDeviceInfo extends Pointer {
/** Device name/identifier */
BytePointer device_name();
/** Human-readable description */
BytePointer device_description();
/** Media types supported */
IntPointer media_types();
/** Number of media types */
int nb_media_types();
}
/**
* List of devices
*/
class AVDeviceInfoList extends Pointer {
/** Array of device info */
PointerPointer devices();
/** Number of devices */
int nb_devices();
/** Default device index */
int default_device();
}// Media types for devices
int AVMEDIA_TYPE_VIDEO = 0; // Video devices
int AVMEDIA_TYPE_AUDIO = 1; // Audio devices
int AVMEDIA_TYPE_DATA = 2; // Data devicesInstall with Tessl CLI
npx tessl i tessl/maven-org-bytedeco--ffmpeg