Skip to content
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

Open
wants to merge 8 commits into
base: 5.x
Choose a base branch
from

Conversation

gursimarsingh
Copy link

@gursimarsingh gursimarsingh commented Apr 5, 2024

Cleanup: #25006
Following videocapture cpp samples have been combined to videocapture_with_audio.cpp:

videocapture_basic.cpp
videocapture_audio.cpp
videocapture_microphone.cpp
videocapture_starter.cpp
videocapture_image_sequence.cpp
videocapture_camera.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

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@gursimarsingh gursimarsingh added category: samples cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code) OpenCV5 labels Apr 5, 2024
@gursimarsingh gursimarsingh self-assigned this Apr 5, 2024
@gursimarsingh gursimarsingh changed the title Videocapture samples cpp Videocapture samples cleanup cpp Apr 5, 2024
samples/cpp/videocapture_with_audio.cpp Outdated Show resolved Hide resolved
samples/cpp/videowriter.cpp Outdated Show resolved Hide resolved
samples/cpp/videowriter.cpp Outdated Show resolved Hide resolved
@asmorkalov
Copy link
Contributor

Still get "core dumped" after:

./bin/example_cpp_videocapture_with_audio --wt
Extracting audio samples from default device...
[ WARN:0@0.089] global cap_gstreamer.cpp:2840 handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0@0.091] global cap_gstreamer.cpp:1698 open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@0.091] global cap_gstreamer.cpp:1173 isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Audio Data Depth: <invalid depth>
Audio Samples Per Second: -1
Total Audio Channels: -1
Total Audio Streams: -1
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_default_append

@asmorkalov
Copy link
Contributor

@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);
Copy link
Contributor

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.

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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.

@mshabunin The sample is supposed to work with video which might have an audio. Please try /opencv_extra/testdata/highgui/videoVID00003-20100701-2204.avi

samples/cpp/videocapture_with_audio.cpp Outdated Show resolved Hide resolved
samples/cpp/videocapture_with_audio.cpp Outdated Show resolved Hide resolved
@asmorkalov asmorkalov added this to the 5.0 milestone Apr 19, 2024
@asmorkalov
Copy link
Contributor

@mshabunin Please take a look again.

}
} else {
// Open input file for both video and audio
cap.open(file, CAP_ANY, videoParams);
Copy link
Contributor

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).

Copy link
Author

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?

Copy link
Contributor

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

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: samples cleanup Code cleanup (e.g, drop legacy C-API, legacy unmaintained code) OpenCV5
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

3 participants