You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dlib/examples/ffmpeg_video_encoding_ex.cpp

117 lines
3.9 KiB

FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This is an example illustrating the use of the ffmpeg wrappers, in this case the encding API.
This is a pretty simple example. It loads a video file, extracts the images and
re-encodes them into a raw buffer using a user-specified codec.
Please see the following examples on how to decode, demux, and get information on your installation of ffmpeg:
- ffmpeg_info_ex.cpp
- ffmpeg_video_decoding_ex.cpp
[FFmpeg] decoding and demuxing improvements (#2784) * typo * - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio. - created resizing_args and resampling_args * smaller videos for unit tests * shorter videos for unit tests * - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read() - added templated read() function - simplified load_frame() * inherit from resizing_args and resampling_args * reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible * much more basic example * demxing examples split * examples * fixing examples * wip * Fix load_frame() * added frame - specific tests * - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird. * notes on defaults and good pairings * Update ffmpeg_demuxer.h Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled. * Update ffmpeg_details.h * Update ffmpeg_muxer.h * WIP * WIP * - simplified details::resizer - added frame::set_params() - added frame::clear() - forward packet directly into correct queue * pick best codec if not specified * added image data * warn when we're choosing an appropriate codec * test load_frame() * - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this. - you can move freshly decoded frames directly out. * callback passed to push() * I think it's prettier this way * WIP * full callback API for decoder * updated tests * updated example * check the template parameter is callable and has 1 argument first before getting it's first argument * Potential bug fix * - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares - guard push() with a boolean which asserts when recursion is detected * pre-conditions on callbacks: no recursion --------- Co-authored-by: pf <pf@me> Co-authored-by: Your name <you@example.com>
1 year ago
- ffmpeg_video_decoding2_ex.cpp
FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
- ffmpeg_video_demuxing_ex.cpp
[FFmpeg] decoding and demuxing improvements (#2784) * typo * - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio. - created resizing_args and resampling_args * smaller videos for unit tests * shorter videos for unit tests * - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read() - added templated read() function - simplified load_frame() * inherit from resizing_args and resampling_args * reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible * much more basic example * demxing examples split * examples * fixing examples * wip * Fix load_frame() * added frame - specific tests * - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird. * notes on defaults and good pairings * Update ffmpeg_demuxer.h Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled. * Update ffmpeg_details.h * Update ffmpeg_muxer.h * WIP * WIP * - simplified details::resizer - added frame::set_params() - added frame::clear() - forward packet directly into correct queue * pick best codec if not specified * added image data * warn when we're choosing an appropriate codec * test load_frame() * - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this. - you can move freshly decoded frames directly out. * callback passed to push() * I think it's prettier this way * WIP * full callback API for decoder * updated tests * updated example * check the template parameter is callable and has 1 argument first before getting it's first argument * Potential bug fix * - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares - guard push() with a boolean which asserts when recursion is detected * pre-conditions on callbacks: no recursion --------- Co-authored-by: pf <pf@me> Co-authored-by: Your name <you@example.com>
1 year ago
- ffmpeg_video_demuxing2_ex.cpp
FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
*/
#include <cstdio>
#include <dlib/media.h>
#include <dlib/cmd_line_parser.h>
using namespace std;
using namespace dlib;
using namespace dlib::ffmpeg;
int main(const int argc, const char** argv)
try
{
command_line_parser parser;
parser.add_option("i", "input video", 1);
parser.add_option("codec", "codec name. e.g. h264. Defaults to mpeg4", 1);
parser.add_option("height", "height of encoded stream. Defaults to whatever is in the video file", 1);
parser.add_option("width", "width of encoded stream. Defaults to whatever is in the video file", 1);
parser.set_group_name("Help Options");
parser.add_option("h", "alias of --help");
parser.add_option("help", "display this message and exit");
parser.parse(argc, argv);
const char* one_time_opts[] = {"i", "codec", "height", "width"};
parser.check_one_time_options(one_time_opts);
if (parser.option("h") || parser.option("help"))
{
parser.print_options();
return 0;
}
const std::string filepath = parser.option("i").argument();
// Load input video.
// Note, this uses a convenient constructor which (dis)enables audio and/or video.
demuxer cap({filepath, video_enabled, audio_disabled});
if (!cap.is_open() || !cap.video_enabled())
{
cout << "Failed to open " << filepath << endl;
return EXIT_FAILURE;
}
// This is a small functor that creates an encoder using the command line arguments
// and different types of output buffers using the convenient sink() overload.
[FFmpeg] decoding and demuxing improvements (#2784) * typo * - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio. - created resizing_args and resampling_args * smaller videos for unit tests * shorter videos for unit tests * - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read() - added templated read() function - simplified load_frame() * inherit from resizing_args and resampling_args * reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible * much more basic example * demxing examples split * examples * fixing examples * wip * Fix load_frame() * added frame - specific tests * - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird. * notes on defaults and good pairings * Update ffmpeg_demuxer.h Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled. * Update ffmpeg_details.h * Update ffmpeg_muxer.h * WIP * WIP * - simplified details::resizer - added frame::set_params() - added frame::clear() - forward packet directly into correct queue * pick best codec if not specified * added image data * warn when we're choosing an appropriate codec * test load_frame() * - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this. - you can move freshly decoded frames directly out. * callback passed to push() * I think it's prettier this way * WIP * full callback API for decoder * updated tests * updated example * check the template parameter is callable and has 1 argument first before getting it's first argument * Potential bug fix * - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares - guard push() with a boolean which asserts when recursion is detected * pre-conditions on callbacks: no recursion --------- Co-authored-by: pf <pf@me> Co-authored-by: Your name <you@example.com>
1 year ago
const auto make_encoder = [&]
FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
{
return encoder([&] {
encoder::args args;
args.args_codec.codec_name = get_option(parser, "codec", "mpeg4");
args.args_image.h = get_option(parser, "height", cap.height());
args.args_image.w = get_option(parser, "width", cap.width());
[FFmpeg] decoding and demuxing improvements (#2784) * typo * - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio. - created resizing_args and resampling_args * smaller videos for unit tests * shorter videos for unit tests * - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read() - added templated read() function - simplified load_frame() * inherit from resizing_args and resampling_args * reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible * much more basic example * demxing examples split * examples * fixing examples * wip * Fix load_frame() * added frame - specific tests * - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird. * notes on defaults and good pairings * Update ffmpeg_demuxer.h Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled. * Update ffmpeg_details.h * Update ffmpeg_muxer.h * WIP * WIP * - simplified details::resizer - added frame::set_params() - added frame::clear() - forward packet directly into correct queue * pick best codec if not specified * added image data * warn when we're choosing an appropriate codec * test load_frame() * - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this. - you can move freshly decoded frames directly out. * callback passed to push() * I think it's prettier this way * WIP * full callback API for decoder * updated tests * updated example * check the template parameter is callable and has 1 argument first before getting it's first argument * Potential bug fix * - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares - guard push() with a boolean which asserts when recursion is detected * pre-conditions on callbacks: no recursion --------- Co-authored-by: pf <pf@me> Co-authored-by: Your name <you@example.com>
1 year ago
args.args_image.fmt = cap.pixel_fmt();
FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
args.args_image.framerate = cap.fps();
return args;
[FFmpeg] decoding and demuxing improvements (#2784) * typo * - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio. - created resizing_args and resampling_args * smaller videos for unit tests * shorter videos for unit tests * - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read() - added templated read() function - simplified load_frame() * inherit from resizing_args and resampling_args * reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible * much more basic example * demxing examples split * examples * fixing examples * wip * Fix load_frame() * added frame - specific tests * - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird. * notes on defaults and good pairings * Update ffmpeg_demuxer.h Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled. * Update ffmpeg_details.h * Update ffmpeg_muxer.h * WIP * WIP * - simplified details::resizer - added frame::set_params() - added frame::clear() - forward packet directly into correct queue * pick best codec if not specified * added image data * warn when we're choosing an appropriate codec * test load_frame() * - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this. - you can move freshly decoded frames directly out. * callback passed to push() * I think it's prettier this way * WIP * full callback API for decoder * updated tests * updated example * check the template parameter is callable and has 1 argument first before getting it's first argument * Potential bug fix * - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares - guard push() with a boolean which asserts when recursion is detected * pre-conditions on callbacks: no recursion --------- Co-authored-by: pf <pf@me> Co-authored-by: Your name <you@example.com>
1 year ago
}());
FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
};
// Encode to multiple different types of buffers.
std::vector<char> buf1;
std::vector<int8_t> buf2;
std::vector<uint8_t> buf3;
std::ostringstream buf4;
std::ofstream buf5("encoded.dat", std::ios::binary);
// Different encoders for different buffers
[FFmpeg] decoding and demuxing improvements (#2784) * typo * - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio. - created resizing_args and resampling_args * smaller videos for unit tests * shorter videos for unit tests * - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read() - added templated read() function - simplified load_frame() * inherit from resizing_args and resampling_args * reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible * much more basic example * demxing examples split * examples * fixing examples * wip * Fix load_frame() * added frame - specific tests * - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird. * notes on defaults and good pairings * Update ffmpeg_demuxer.h Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled. * Update ffmpeg_details.h * Update ffmpeg_muxer.h * WIP * WIP * - simplified details::resizer - added frame::set_params() - added frame::clear() - forward packet directly into correct queue * pick best codec if not specified * added image data * warn when we're choosing an appropriate codec * test load_frame() * - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this. - you can move freshly decoded frames directly out. * callback passed to push() * I think it's prettier this way * WIP * full callback API for decoder * updated tests * updated example * check the template parameter is callable and has 1 argument first before getting it's first argument * Potential bug fix * - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares - guard push() with a boolean which asserts when recursion is detected * pre-conditions on callbacks: no recursion --------- Co-authored-by: pf <pf@me> Co-authored-by: Your name <you@example.com>
1 year ago
auto enc1 = make_encoder();
auto enc2 = make_encoder();
auto enc3 = make_encoder();
auto enc4 = make_encoder();
auto enc5 = make_encoder();
FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
frame f;
while (cap.read(f))
{
[FFmpeg] decoding and demuxing improvements (#2784) * typo * - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio. - created resizing_args and resampling_args * smaller videos for unit tests * shorter videos for unit tests * - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read() - added templated read() function - simplified load_frame() * inherit from resizing_args and resampling_args * reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible * much more basic example * demxing examples split * examples * fixing examples * wip * Fix load_frame() * added frame - specific tests * - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird. * notes on defaults and good pairings * Update ffmpeg_demuxer.h Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled. * Update ffmpeg_details.h * Update ffmpeg_muxer.h * WIP * WIP * - simplified details::resizer - added frame::set_params() - added frame::clear() - forward packet directly into correct queue * pick best codec if not specified * added image data * warn when we're choosing an appropriate codec * test load_frame() * - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this. - you can move freshly decoded frames directly out. * callback passed to push() * I think it's prettier this way * WIP * full callback API for decoder * updated tests * updated example * check the template parameter is callable and has 1 argument first before getting it's first argument * Potential bug fix * - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares - guard push() with a boolean which asserts when recursion is detected * pre-conditions on callbacks: no recursion --------- Co-authored-by: pf <pf@me> Co-authored-by: Your name <you@example.com>
1 year ago
enc1.push(f, sink(buf1));
enc2.push(f, sink(buf2));
enc3.push(f, sink(buf3));
enc4.push(f, sink(buf4));
enc5.push(f, sink(buf5));
FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
}
[FFmpeg] decoding and demuxing improvements (#2784) * typo * - added compile time information to audio object. Not convinced this is needed actually. I'm perfectly happy just using the ffmpeg::frame object. I'm pretty sure I'm the only user who cares about audio. - created resizing_args and resampling_args * smaller videos for unit tests * shorter videos for unit tests * - decoder and demuxer: you now resize or resample at the time of read. therefore you don't set resizing or resampling parameters in constructor, but you pass them to read() - added templated read() function - simplified load_frame() * inherit from resizing_args and resampling_args * reorganised the tests to segragate decoding, demuxing, encoding and muxing as much as possible * much more basic example * demxing examples split * examples * fixing examples * wip * Fix load_frame() * added frame - specific tests * - makes sense to have a set_params() method rather than constructing a new object and moving. I mean, it works and it absolutely does the right thing, and in fact the same thing as calling set_params() now, but it can look a bit weird. * notes on defaults and good pairings * Update ffmpeg_demuxer.h Watch out for `DLIB_ASSERT` statements. Maybe one of the unit tests should build with asserts enabled. * Update ffmpeg_details.h * Update ffmpeg_muxer.h * WIP * WIP * - simplified details::resizer - added frame::set_params() - added frame::clear() - forward packet directly into correct queue * pick best codec if not specified * added image data * warn when we're choosing an appropriate codec * test load_frame() * - for some reason, you sometimes get warning messages about too many b-frames. Resetting pict_type suppresses this. - you can move freshly decoded frames directly out. * callback passed to push() * I think it's prettier this way * WIP * full callback API for decoder * updated tests * updated example * check the template parameter is callable and has 1 argument first before getting it's first argument * Potential bug fix * - write out the enable_if's explictly. It's fine. I think it's clear what's going on if someone cares - guard push() with a boolean which asserts when recursion is detected * pre-conditions on callbacks: no recursion --------- Co-authored-by: pf <pf@me> Co-authored-by: Your name <you@example.com>
1 year ago
enc1.flush(sink(buf1));
enc2.flush(sink(buf2));
enc3.flush(sink(buf3));
enc4.flush(sink(buf4));
enc5.flush(sink(buf5));
FFmpeg : encoding (#2754) * docs * callbacks for encoder * shorter video * shorter video * added is_byte type trait * leave muxer for next PR * added overloads for set_layout() and get_layout() in details namespace * unit test * example * build * overloads for ffmpeg < 5 * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * as per suggestion * remove requires clause * Update examples/ffmpeg_video_encoding_ex.cpp Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_abstract.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * use dlib::logger * oops * Update dlib/media/ffmpeg_muxer.h Co-authored-by: Davis E. King <davis685@gmail.com> * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_demuxer.h * Update dlib/media/ffmpeg_abstract.h --------- Co-authored-by: pf <pf@me> Co-authored-by: Davis E. King <davis685@gmail.com> Co-authored-by: Adrià Arrufat <1671644+arrufat@users.noreply.github.com>
1 year ago
cout << "vector<char> size " << buf1.size() << endl;
cout << "vector<int8_t> size " << buf2.size() << endl;
cout << "vector<uint8_t> size " << buf3.size() << endl;
cout << "ostringstream size " << buf4.tellp() << endl;
cout << "ofstream size " << buf5.tellp() << endl;
return EXIT_SUCCESS;
}
catch (const std::exception& e)
{
cout << e.what() << endl;
return EXIT_FAILURE;
}