CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Open VideoCapture from data stream #25584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2bd1a39
to
023eeb5
Compare
4dace6c
to
b71844d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugin support is necessary - it is mandatory for FFmpeg support on Windows.
ec90def
to
eeae54d
Compare
Discussed on OpenCV weekly sync about potential improvements:
|
We have something similar in cudacodec module:
Following example in the test decodes key frames (if I understand corretly): https://github.com/opencv/opencv_contrib/blob/b236c71c2f8d983403c35a0cea8bec0432a4b0fe/modules/cudacodec/test/test_video.cpp#L178-L209 |
Hello, what is left to complete this work? Would anyone be able to complete this work by any chance? |
@gdippolito, I can complete this one once I can figure out which API is better. Last time we discussed in the team, more generic is to introduce kind of streaming API which returns chunks of video buffer. |
eeae54d
to
175f070
Compare
214cd8a
to
62cd53a
Compare
Hey @dkurt thanks for your work on this PR. Do you think this is ready for some testing? |
@gdippolito, thanks! Yes, it's ready and any feedback is welcome. |
Totally fine to keep stream notation everywhere. There is just a conflict in public API with filename (getStreamBackends) |
modules/videoio/src/cap_ffmpeg.cpp
Outdated
try | ||
{ | ||
cv::VideoCaptureParameters parameters(params, n_params); | ||
cap = new CvCapture_FFMPEG_proxy(makePtr<ReadStreamPluginProvider>(opaque, read, seek), parameters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makePtr<ReadStreamPluginProvider>(opaque, read, seek)
Released right after this call because it is not saved anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a workaround, readStream = stream
for now
ffb04fd
to
ad2b7b3
Compare
ad2b7b3
to
64a7d96
Compare
@@ -719,6 +719,25 @@ enum VideoCaptureOBSensorProperties{ | |||
|
|||
//! @} videoio_flags_others | |||
|
|||
/** @brief Read data stream interface | |||
*/ | |||
class CV_EXPORTS_W IReadStream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@opencv-alalek, @asmorkalov , need your opinion on naming as we ready to move it to the public API. There are VideoCapture
, IStreamSource , VideoReader, VideoWriter. So does it make sense to keep the order and name it IStreamReader
? Moreover, it matches PyTorch's naming: https://pytorch.org/audio/main/generated/torchaudio.io.StreamReader.html#streamreader
IReadStream -> IStreamReader ReadStreamPluginProvider -> PluginStreamReader PythonReadStream -> PythonStreamReader BufferBackend -> StreamBufferedBackend
BTW, there is leftover with Python typing generator (map to |
2a02297
to
cfed93c
Compare
There is problem with iOS/Swift bindings:
Error message is not very clear to me |
Looks like fix works: https://github.com/opencv/opencv/actions/runs/12491953263/job/34858615536?pr=25584 @dkurt Feel free to push your changes. |
@opencv-alalek no pending changes left |
/** @brief Sets the stream position | ||
* | ||
* @param offset Seek offset | ||
* @param origin SEEK_SET / SEEK_END / SEEK_CUR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to completely avoid C/C++ constants in public interface and introduce our own?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FFmpeg (basically) and Python use them too (with same values).
IMHO, it is not necessary to introduce extra conversions to/from own values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, we can add such enum but potential user will still cast to integer or introduce long if/else/switch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern was that user would be required to include <stdio.h>
/<cstdio>
in order to use this seemingly unrelated class. Though perhaps it's fine.
Open VideoCapture from data stream opencv#25584 ### Pull Request Readiness Checklist Add VideoCapture option to read a raw binary video data from `std::streambuf`. There are multiple motivations: 1. Avoid disk file creation in case of video already in memory (received by network or from database). 2. Streaming mode. Frames decoding starts during sequential file transfer by chunks. Suppoted backends: * FFmpeg * MSMF (no streaming mode) Supporter interfaces: * C++ (std::streambuf) * Python (io.BufferedIOBase) resolves opencv#24400 - [x] test h264 - [x] test IP camera like approach with no metadata but key frame only? - [x] C API plugin See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Open VideoCapture from data stream opencv#25584 ### Pull Request Readiness Checklist Add VideoCapture option to read a raw binary video data from `std::streambuf`. There are multiple motivations: 1. Avoid disk file creation in case of video already in memory (received by network or from database). 2. Streaming mode. Frames decoding starts during sequential file transfer by chunks. Suppoted backends: * FFmpeg * MSMF (no streaming mode) Supporter interfaces: * C++ (std::streambuf) * Python (io.BufferedIOBase) resolves opencv#24400 - [x] test h264 - [x] test IP camera like approach with no metadata but key frame only? - [x] C API plugin See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Pull Request Readiness Checklist
Add VideoCapture option to read a raw binary video data from
std::streambuf
.There are multiple motivations:
Suppoted backends:
Supporter interfaces:
resolves #24400
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.