So start with, let's set some context regarding libav (ffmpeg):
Yes, I'm aware that this is a 'per backend' thing, and for some (eg. avfoundation) although it includes the code to enumerate these options, can only output them as error messages when you pass an invalid combination of input parameters and attempt to open a device.
Other implementations, eg. the v4l2 driver implements list_formats that can be seen using:
ffmpeg -f v4l2 -list_formats all -i "/dev/video0"
However, the implementation of this function also just logs out the formats.
Now, I'm well aware that you can trigger the these functions (depending on the backend) by forming some combination of options in an AVDictionary
and passing the result to av_find_input_format
.
So, not possible right?
However, as per c++ how to use lambdas to set ffmpeg's av_log_set_callback() to a member function? you can rebind the logging function in libav to capture this output.
Right... so now this is where I'm stuck. In theory I can use vsprintf
to convert the log callback (ie. char *fmt, va_list args
into a string, and collect the result.
However, I can't figure out how to actually implement something that does the following:
- build a valid AVDictionary with the required properties
- set the log callback
- av_find_input_format / avf_read_header / whatever
- get the output of the log <--- how do I do this?
- clear the log callback
How can I capture the log output?
Please, no vague hand waving, post actual code. There's a basic example of how to do this which already does all the steps except the log capture.
Note that the answer to the SO post linked about about using lambdas is answered with "You can't use a capturing lambda, use a global in the log callback function", however, I'm posting this question because that answer lacks detail about specifically how to do that in a thread safe way, given that the documentation specifically states:
The callback must be thread safe, even if the application does not use threads itself as some codecs are multithreaded.