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
Videocapture samples cleanup cpp #25349
base: 5.x
Are you sure you want to change the base?
Conversation
…h argument in videowriter
Still get "core dumped" after:
|
@mshabunin could you take a look on audio part? |
} else { | ||
// Open input file for both video and audio | ||
vector<int> fileParams{ CAP_PROP_AUDIO_STREAM, 0, CAP_PROP_VIDEO_STREAM, 0, CAP_PROP_AUDIO_DATA_DEPTH, CV_16S }; | ||
cap.open(file, CAP_ANY, fileParams); |
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.
Original example used CAP_MSMF
, this one doesn't. For example on Linux with GStreamer it seems to hang or works veery slow.
I ran it like this:
./bin/example_cpp_videocapture_with_audio -i=../opencv_extra/testdata/highgui/audio/test_audio.wav --with_audio
Maybe it should be somehow adapted to another backend? On what platform did you test it?
audio_spectrogram
example seem to be working with the same file.
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.
@mshabunin It works with a video file but fails when initialized using a camera device in GStreamer backend when run like this
./bin/example_cpp_videocapture_with_audio --wt
It works on windows with MSMF backend
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.
I still don't understand why audio_spectrogram works with files on Linux with GStreamer, but your application doesn't.
Since this part of the application doesn't work properly on all platforms and complicates the example I propose removing audio support from this sample and leave only audio_spectorgram.
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.
@mshabunin The comparison to the audio_spectogram
sample is not one-to-one because in this sample, we are trying to extract both video frames and audio, whereas in the audio_spectogram
sample, we are only extracting audio. This sample is not a replacement to audio_spectogram
sample.
So test needs to be done with a video file that also has an audio. I test on Linux and Windows like this and it works:
./bin/example_cpp_videocapture_with_audio -i=../opencv_extra/testdata/highgui/video/VID00003-20100701-2204.avi --with_audio
The case where this sample does not work with CAP_ANY, CAP_MSMF or CAP_GSTREAMER is this:
./bin/example_cpp_videocapture_with_audio --with_audio
i.e. when we try to extract video and audio from a camera device.
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.
More infromation:
vector<int> micParams{ CAP_PROP_AUDIO_STREAM, 0, CAP_PROP_VIDEO_STREAM, 0, CAP_PROP_AUDIO_DATA_DEPTH, CV_16S };
cap.open(0, CAP_ANY, micParams);
The above configuration does not work on linux with gstreamer.
However, if I try gstreamer directly using the following pipeline it is able to get frames and audio both
gst-launch-1.0 autovideosrc ! videoconvert ! autovideosink autoaudiosrc ! audioconvert ! autoaudiosink
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.
Yes, and since capturing both audio and video works only with MSMF backend we should somehow reflect this in the sample (explicitly set backend, show messages, etc.) or drop it completely to avoid user confusion.
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.
@mshabunin The comparison to the
audio_spectogram
sample is not one-to-one because in this sample, we are trying to extract both video frames and audio, whereas in theaudio_spectogram
sample, we are only extracting audio. This sample is not a replacement toaudio_spectogram
sample.So test needs to be done with a video file that also has an audio. I test on Linux and Windows like this and it works:
./bin/example_cpp_videocapture_with_audio -i=../opencv_extra/testdata/highgui/video/VID00003-20100701-2204.avi --with_audio
The case where this sample does not work with CAP_ANY, CAP_MSMF or CAP_GSTREAMER is this:
./bin/example_cpp_videocapture_with_audio --with_audio
i.e. when we try to extract video and audio from a camera device.
@mshabunin The sample is supposed to work with video which might have an audio. Please try /opencv_extra/testdata/highgui/videoVID00003-20100701-2204.avi
@mshabunin Please take a look again. |
} | ||
} else { | ||
// Open input file for both video and audio | ||
cap.open(file, CAP_ANY, videoParams); |
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.
The sample doesn't work with audio files with GStreamer backend (or any backend other than MSMF).
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.
@mshabunin how are you testing?
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.
Ubuntu 22.04 with base/good/bad/ugly plugins GStreamer plugins installed.
./bin/example_cpp_videocapture_with_audio \
-i=../opencv_extra/testdata/highgui/audio/test_audio.wav \
--with_audio
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.
@mshabunin The sample is supposed to work with video which might have an audio. Please try with
./bin/example_cpp_videocapture_with_audio \
-i=../opencv_extra/testdata/highgui/videoVID00003-20100701-2204.avi \
--with_audio
Cleanup: #25006
Following videocapture cpp samples have been combined to videocapture_with_audio.cpp:
videocapture_basic.cpp has been moved snippets folder and references in documentation have been updated accordingly
videowriter_basic.cpp has been renamed to videowriter.cpp, with new options to specify codec, fps and resolution for the user
Pull Request Readiness Checklist
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.