Dlib's equivalent to cv::VideoCapture, but better #2718
Replies: 15 comments 55 replies
-
Future PRs will include
|
Beta Was this translation helpful? Give feedback.
-
currently experiencing build errors with examples in ffmpeg code. This is on ubuntu 22.04.2 LTS seems to be some misplaced const declarations in media/ffmpeg*.h here is an error output during compile: In file included from /home/rfg/w/dlib/dlib/../dlib/media.h:13, /home/rfg/w/dlib/dlib/../dlib/media/ffmpeg_demuxer.h: In lambda function: Ross |
Beta Was this translation helpful? Give feedback.
-
FFmpeg 6.0 is out. So more compatibility layer PRs coming |
Beta Was this translation helpful? Give feedback.
-
Just tested with ffmpeg 5.1.2 and 5.1.3 ... looks much better! I'll let you know how it goes with ffmpeg 6.0. Thanks all, Ross |
Beta Was this translation helpful? Give feedback.
-
Does anybody care about python bindings for this ? I don't personally but I can oblige. |
Beta Was this translation helpful? Give feedback.
-
Some benchmarks against OpenCV:
using
On my machine, I get:
|
Beta Was this translation helpful? Give feedback.
-
I am still reading through the examples and they're really nice! |
Beta Was this translation helpful? Give feedback.
-
I was thinking that maybe we should add a global function to dlib that does something like this: template <typename image_type>
void load_image(image_type& image, const std::string& file_name)
{
ffmpeg::demuxer reader(file_name);
ffmpeg::frame frame;
if (!(reader.is_open() && reader.read(frame)))
throw image_load_error("Error reading from " + file_name);
ffmpeg::convert(frame, image);
} Then, we would never have to add extra image codecs support in dlib. I have a half-baked branch with JPEG XL, but I don't think it's meaningful unless we need JPEG XL specific features. What do you think? |
Beta Was this translation helpful? Give feedback.
-
FYI, all of:
are in master! |
Beta Was this translation helpful? Give feedback.
-
FYI, |
Beta Was this translation helpful? Give feedback.
-
A few more things to do before release:
Most importantly, this could do with some trials. So users, please stress test and submit issues if there are any. |
Beta Was this translation helpful? Give feedback.
-
At some point we can consider adding FFmpeg as an ExternalProject to cmake so users can optionally build FFmpeg from source if not found on the system. I've mentioned this before I think. This would be great if you don't want the full FFmpeg installation, but just want to enable precisely what you need. It also means you can use the absolute latest release of FFmpeg. This is not easily done with OpenCV. |
Beta Was this translation helpful? Give feedback.
-
Quick example of how one might use the new decoding/demuxing API. This reads frames from a video, encodes them, then directly decodes them using callbacks.
|
Beta Was this translation helpful? Give feedback.
-
Just did some more benchmarking against OpenCV. I was confused why Opencv was nearly 4X faster than vanilla ffmpeg. It turns out, by default, OpenCV will use half your cores. So on an 8-core CPU, it will use 4 threads. By default, ffmpeg, and therefore dlib, will use 1 thread. |
Beta Was this translation helpful? Give feedback.
-
I've finally had the time to try this out, and it works like a charm. I tested most of the examples, and in particular, made a comparison with OpenCV using There are still a couple of scenarios that I'm not sure if it's possible to use this, maybe it is with some modifications.
|
Beta Was this translation helpful? Give feedback.
-
A fresh PR has landed in dlib which includes:
dlib::ffmpeg::decoder
dlib::ffmpeg::demuxer
which you can find by adding
to your code. These are lightweight wrappers of libavformat and libavcodec, the underlying C libraries used by ffmpeg.
You will need to build dlib with
-DDLIB_USE_FFMPEG=ON
. By default, if an installation off ffmpeg (libavformat, libavcodec) is found on your system, then this will be done automatically.dlib::ffmpeg::demuxer
is similar to OpenCV'scv::VideoCapture
except it can do far more! It can read:ffmpeg -i <>
dlib::ffmpeg::decoder
is an object used to decode and extract frames (images or audio) from RAW data.If you are interested, please read the documentation in
dlib/media/ffmpeg_abstract.h
and look at the new examples which start withffmpeg_
in the filename.I would be very keen for people to try it out. If they have any issues, please submit github issues using the template and a reproducible example, ideally with a main.cpp file and CMakeLists.txt file.
The more people use it, the more quickly potential issues get ironed out, the more robust it gets. Though I already expect it to be fairly mature, you never know. Eventually, hopefully some time soon, it will be part of the next dlib release.
Beta Was this translation helpful? Give feedback.
All reactions