MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open_device()

bool MayaFlux::IO::FFmpegDemuxContext::open_device ( const std::string &  device_name,
const std::string &  format_name,
AVDictionary **  options = nullptr 
)

Open an FFmpeg device input (camera, screen capture, etc.).

Calls av_find_input_format() then avformat_open_input() with the supplied options dict. avdevice_register_all() must have been called before this method.

Parameters
device_namePlatform device string (e.g. "/dev/video0").
format_nameFFmpeg input format name (e.g. "v4l2", "avfoundation").
optionsAVDictionary of format options; consumed and freed on return.
Returns
True on success.

Definition at line 64 of file FFmpegDemuxContext.cpp.

67{
68 close();
70
71 const AVInputFormat* fmt = av_find_input_format(format_name.c_str());
72 if (!fmt) {
73 m_last_error = "av_find_input_format failed for: " + format_name;
74 return false;
75 }
76
77 int ret = avformat_open_input(&format_context,
78 device_name.c_str(), fmt, options);
79 if (ret < 0) {
80 char errbuf[AV_ERROR_MAX_STRING_SIZE];
81 av_strerror(ret, errbuf, sizeof(errbuf));
82 m_last_error = "avformat_open_input failed for device: "
83 + device_name + " (" + errbuf + ")";
84 return false;
85 }
86
87 if (avformat_find_stream_info(format_context, nullptr) < 0) {
88 avformat_close_input(&format_context);
89 m_last_error = "avformat_find_stream_info failed for device: " + device_name;
90 return false;
91 }
92
93 return true;
94}
AVFormatContext * format_context
Owned; freed in destructor.
void close()
Close the format context and release all demux resources.
static void init_ffmpeg()
Initialise FFmpeg logging level once per process.

References close(), format_context, init_ffmpeg(), and m_last_error.

+ Here is the call graph for this function: