2023-01-30 09:17:34 +08:00
|
|
|
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
|
|
|
|
/*
|
|
|
|
|
|
|
|
This is an example illustrating some of the functional ffmpeg wrapper APIs.
|
|
|
|
It demonstrates how to list the supported codecs, muxers, demuxers and protocols
|
|
|
|
in your installation of ffmpeg (or the one dlib built against).
|
|
|
|
|
|
|
|
It also demonstrates how to check ffmpeg library versions programmatically.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <dlib/media/ffmpeg_utils.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace dlib;
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// List all codecs supported by this installation of ffmpeg libraries
|
|
|
|
const auto codecs = ffmpeg::list_codecs();
|
|
|
|
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << "Supported codecs:\n";
|
2023-01-30 09:17:34 +08:00
|
|
|
for (const auto& codec : codecs)
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << " name : " << left << setw(20) << codec.codec_name << " id : " << codec.codec_id << " : encoding supported " << codec.supports_encoding << " decoding supported " << codec.supports_decoding << '\n';
|
|
|
|
cout << '\n';
|
2023-01-30 09:17:34 +08:00
|
|
|
|
|
|
|
// List all demuxers supported by this installation of ffmpeg libraries
|
|
|
|
const auto demuxers = ffmpeg::list_demuxers();
|
|
|
|
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << "Supported demuxers:\n";
|
2023-01-30 09:17:34 +08:00
|
|
|
for (const auto& demuxer : demuxers)
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << " name : " << demuxer << '\n';
|
|
|
|
cout << '\n';
|
2023-01-30 09:17:34 +08:00
|
|
|
|
|
|
|
// List all muxers supported by this installation of ffmpeg libraries
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << "Supported muxers:\n";
|
|
|
|
for (const auto& muxer : ffmpeg::list_muxers())
|
|
|
|
{
|
|
|
|
cout << " name : " << muxer.name << '\n';
|
|
|
|
if (!muxer.supported_codecs.empty())
|
|
|
|
{
|
|
|
|
cout << " supported codecs:\n";
|
|
|
|
for (const auto& codec : muxer.supported_codecs)
|
|
|
|
cout << " " << codec.codec_name << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cout << '\n';
|
2023-01-30 09:17:34 +08:00
|
|
|
|
|
|
|
// List all input devices supported by this installation of ffmpeg libraries
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << "Supported input devices:\n";
|
2023-04-15 21:28:38 +08:00
|
|
|
for (const auto& device : ffmpeg::list_input_device_types())
|
2023-01-30 09:17:34 +08:00
|
|
|
{
|
2023-04-15 21:28:38 +08:00
|
|
|
cout << " device type : `" << device.device_type << "` is audio " << device.is_audio_type << " is video " << device.is_video_type << '\n';
|
|
|
|
|
|
|
|
const auto instances = ffmpeg::list_input_device_instances(device.device_type);
|
|
|
|
if (!instances.empty())
|
2023-01-30 09:17:34 +08:00
|
|
|
{
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << " instances :\n";
|
2023-04-15 21:28:38 +08:00
|
|
|
for (const auto& instance : instances)
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << " name : " << left << setw(32) << instance.name << ", description : " << instance.description << '\n';
|
2023-01-30 09:17:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << '\n';
|
2023-01-30 09:17:34 +08:00
|
|
|
|
|
|
|
// List all input devices supported by this installation of ffmpeg libraries
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << "Supported output devices:\n";
|
2023-04-15 21:28:38 +08:00
|
|
|
for (const auto& device : ffmpeg::list_output_device_types())
|
2023-01-30 09:17:34 +08:00
|
|
|
{
|
2023-04-15 21:28:38 +08:00
|
|
|
cout << " device type : `" << device.device_type << "` is audio " << device.is_audio_type << " is video " << device.is_video_type << '\n';
|
|
|
|
|
|
|
|
const auto instances = ffmpeg::list_output_device_instances(device.device_type);
|
|
|
|
if (!instances.empty())
|
2023-01-30 09:17:34 +08:00
|
|
|
{
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << " instances :\n";
|
2023-04-15 21:28:38 +08:00
|
|
|
for (const auto& instance : instances)
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << " name : " << left << setw(32) << instance.name << ", description : " << instance.description << '\n';
|
2023-01-30 09:17:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << '\n';
|
2023-01-30 09:17:34 +08:00
|
|
|
|
|
|
|
const bool mp4_available =
|
|
|
|
std::find_if(begin(demuxers),
|
|
|
|
end(demuxers),
|
|
|
|
[](const auto& demux) {return demux.find("mp4") != std::string::npos;}) != demuxers.end();
|
|
|
|
|
|
|
|
const bool h264_available =
|
|
|
|
std::find_if(begin(codecs),
|
|
|
|
end(codecs),
|
|
|
|
[](const auto& codec) {return codec.codec_name == "h264" && codec.supports_decoding;}) != codecs.end();
|
|
|
|
|
2023-03-30 10:12:47 +08:00
|
|
|
cout << "Can read MP4 file with H264 encoded video stream? " << (mp4_available && h264_available) << '\n';
|
2023-01-30 09:17:34 +08:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2023-03-30 10:12:47 +08:00
|
|
|
}
|