Skip to content

Commit

Permalink
FFmpeg : improvements to ffmpeg::list() functions (davisking#2773)
Browse files Browse the repository at this point in the history
* added a couple more audio examples

* statically initialize all list_() functions where possible.

---------

Co-authored-by: pf <pf@me>
  • Loading branch information
pfeatherstone and pf authored Apr 15, 2023
1 parent b1fe026 commit 5f7026a
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 188 deletions.
58 changes: 38 additions & 20 deletions dlib/media/ffmpeg_abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,55 +296,73 @@ namespace dlib
{
/*!
WHAT THIS OBJECT REPRESENTS
This object informs on available devices provided by the installation of ffmpeg dlib is linked against.
This object informs on available device types provided by the installation of ffmpeg dlib is linked against.
!*/

struct instance
{
std::string name;
std::string description;
};

std::string device_type;
std::vector<instance> devices;
bool is_audio_type{false};
bool is_video_type{false};
};

std::vector<std::string> list_protocols();
struct device_instance
{
/*!
WHAT THIS OBJECT REPRESENTS
This object informs on the currently available device instances readable by ffmpeg.
!*/

std::string name;
std::string description;
};

const std::vector<std::string>& list_protocols();
/*!
ensures
- returns a list of all registered ffmpeg protocols
- returns a list of all available ffmpeg protocols
!*/

std::vector<std::string> list_demuxers();
const std::vector<std::string>& list_demuxers();
/*!
ensures
- returns a list of all registered ffmpeg demuxers
- returns a list of all available ffmpeg demuxers
!*/

std::vector<muxer_details> list_muxers();
const std::vector<muxer_details>& list_muxers();
/*!
ensures
- returns a list of all registered ffmpeg muxers
- returns a list of all available ffmpeg muxers
!*/

std::vector<codec_details> list_codecs();
const std::vector<codec_details>& list_codecs();
/*!
ensures
- returns a list of all registered ffmpeg codecs with information on whether decoding and/or encoding is supported.
- returns a list of all available ffmpeg codecs with information on whether decoding and/or encoding is supported.
Note that not all codecs support encoding, unless your installation of ffmpeg is built with third party library
dependencies like libx264, libx265, etc.
!*/

std::vector<device_details> list_input_devices();
const std::vector<device_details>& list_input_device_types();
/*!
ensures
- returns a list of all available ffmpeg input device types (e.g. alsa, v4l2, etc)
!*/

const std::vector<device_details>& list_output_device_types();
/*!
ensures
- returns a list of all available ffmpeg output device types (e.g. alsa, v4l2, etc)
!*/

std::vector<device_instance> list_input_device_instances(const std::string& device_type);
/*!
ensures
- returns a list of all registered ffmpeg input devices and available instances of those devices
- returns a list of all available ffmpeg input device instances for device type *device_type (e.g. hw:0,0, /dev/video0, etc)
!*/

std::vector<device_details> list_output_devices();
std::vector<device_instance> list_output_device_instances(const std::string& device_type);
/*!
ensures
- returns a list of all registered ffmpeg output devices and available instances of those devices
- returns a list of all available ffmpeg output device instances for device type *device_type (e.g. hw:0,0, /dev/video0, etc)
!*/

// ---------------------------------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions dlib/media/ffmpeg_muxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,6 @@ namespace dlib
if (!st.args_.enable_audio && !st.args_.enable_image)
return fail(*st.log, "You need to set at least one of `enable_audio` or `enable_image`");

static const auto all_codecs = list_codecs();

{
st.connecting_time = system_clock::now();
st.connected_time = system_clock::time_point::max();
Expand Down Expand Up @@ -723,7 +721,7 @@ namespace dlib
};

// Before we create the encoder, check the codec is supported by this muxer
const auto supported_codecs = list_codecs_for_muxer(st.pFormatCtx->oformat, all_codecs);
const auto supported_codecs = list_codecs_for_muxer(st.pFormatCtx->oformat);

if (std::find_if(begin(supported_codecs), end(supported_codecs), [&](const auto& supported) {
return args.args_codec.codec != AV_CODEC_ID_NONE ?
Expand Down
Loading

0 comments on commit 5f7026a

Please sign in to comment.