2018-03-21 23:01:47 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
2021-02-24 16:40:42 +08:00
|
|
|
namespace opencv_test { namespace {
|
2018-04-16 20:59:25 +08:00
|
|
|
|
2018-03-21 23:01:47 +08:00
|
|
|
typedef tuple< string, Size, Size, int > Param;
|
2019-01-14 18:33:38 +08:00
|
|
|
typedef testing::TestWithParam< Param > videoio_gstreamer;
|
2018-03-21 23:01:47 +08:00
|
|
|
|
2021-02-24 16:40:42 +08:00
|
|
|
TEST_P(videoio_gstreamer, read_check)
|
2018-03-21 23:01:47 +08:00
|
|
|
{
|
2019-01-14 18:33:38 +08:00
|
|
|
if (!videoio_registry::hasBackend(CAP_GSTREAMER))
|
|
|
|
throw SkipTestException("GStreamer backend was not found");
|
|
|
|
|
2018-03-21 23:01:47 +08:00
|
|
|
string format = get<0>(GetParam());
|
|
|
|
Size frame_size = get<1>(GetParam());
|
|
|
|
Size mat_size = get<2>(GetParam());
|
|
|
|
int convertToRGB = get<3>(GetParam());
|
|
|
|
int count_frames = 10;
|
|
|
|
std::ostringstream pipeline;
|
|
|
|
pipeline << "videotestsrc pattern=ball num-buffers=" << count_frames << " ! " << format;
|
2018-04-16 20:59:25 +08:00
|
|
|
pipeline << ", width=" << frame_size.width << ", height=" << frame_size.height << " ! appsink";
|
|
|
|
VideoCapture cap;
|
|
|
|
ASSERT_NO_THROW(cap.open(pipeline.str(), CAP_GSTREAMER));
|
2018-03-21 23:01:47 +08:00
|
|
|
ASSERT_TRUE(cap.isOpened());
|
|
|
|
|
|
|
|
Mat buffer, decode_frame, gray_frame, rgb_frame;
|
|
|
|
for (int i = 0; i < count_frames; ++i)
|
|
|
|
{
|
|
|
|
cap >> buffer;
|
|
|
|
decode_frame = (format == "jpegenc ! image/jpeg") ? imdecode(buffer, IMREAD_UNCHANGED) : buffer;
|
|
|
|
EXPECT_EQ(mat_size, decode_frame.size());
|
|
|
|
|
|
|
|
cvtColor(decode_frame, rgb_frame, convertToRGB);
|
|
|
|
cvtColor(rgb_frame, gray_frame, COLOR_RGB2GRAY);
|
2021-08-17 00:20:10 +08:00
|
|
|
if (gray_frame.depth() == CV_16U)
|
|
|
|
{
|
|
|
|
gray_frame.convertTo(gray_frame, CV_8U, 255.0/65535);
|
|
|
|
}
|
2018-03-21 23:01:47 +08:00
|
|
|
|
|
|
|
vector<Vec3f> circles;
|
|
|
|
HoughCircles(gray_frame, circles, HOUGH_GRADIENT, 1, gray_frame.rows/16, 100, 30, 1, 30 );
|
|
|
|
if (circles.size() == 1)
|
|
|
|
{
|
|
|
|
EXPECT_NEAR(18.5, circles[0][2], 1.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ADD_FAILURE() << "Found " << circles.size() << " on frame " << i ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Mat frame;
|
|
|
|
cap >> frame;
|
|
|
|
EXPECT_TRUE(frame.empty());
|
|
|
|
}
|
|
|
|
cap.release();
|
|
|
|
ASSERT_FALSE(cap.isOpened());
|
|
|
|
}
|
|
|
|
|
2021-02-24 16:40:42 +08:00
|
|
|
static const Param test_data[] = {
|
2018-03-21 23:01:47 +08:00
|
|
|
make_tuple("video/x-raw, format=BGR" , Size(640, 480), Size(640, 480), COLOR_BGR2RGB),
|
2021-08-17 00:20:10 +08:00
|
|
|
make_tuple("video/x-raw, format=BGRA" , Size(640, 480), Size(640, 480), COLOR_BGRA2RGB),
|
|
|
|
make_tuple("video/x-raw, format=RGBA" , Size(640, 480), Size(640, 480), COLOR_RGBA2RGB),
|
|
|
|
make_tuple("video/x-raw, format=BGRx" , Size(640, 480), Size(640, 480), COLOR_BGRA2RGB),
|
|
|
|
make_tuple("video/x-raw, format=RGBx" , Size(640, 480), Size(640, 480), COLOR_RGBA2RGB),
|
2018-03-21 23:01:47 +08:00
|
|
|
make_tuple("video/x-raw, format=GRAY8", Size(640, 480), Size(640, 480), COLOR_GRAY2RGB),
|
|
|
|
make_tuple("video/x-raw, format=UYVY" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_UYVY),
|
|
|
|
make_tuple("video/x-raw, format=YUY2" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_YUY2),
|
|
|
|
make_tuple("video/x-raw, format=YVYU" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_YVYU),
|
|
|
|
make_tuple("video/x-raw, format=NV12" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_NV12),
|
|
|
|
make_tuple("video/x-raw, format=NV21" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_NV21),
|
|
|
|
make_tuple("video/x-raw, format=YV12" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_YV12),
|
|
|
|
make_tuple("video/x-raw, format=I420" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_I420),
|
|
|
|
make_tuple("video/x-bayer" , Size(640, 480), Size(640, 480), COLOR_BayerBG2RGB),
|
2021-02-24 16:40:42 +08:00
|
|
|
make_tuple("jpegenc ! image/jpeg" , Size(640, 480), Size(640, 480), COLOR_BGR2RGB),
|
|
|
|
|
|
|
|
// unaligned cases, strides information must be used
|
|
|
|
make_tuple("video/x-raw, format=BGR" , Size(322, 242), Size(322, 242), COLOR_BGR2RGB),
|
|
|
|
make_tuple("video/x-raw, format=GRAY8", Size(322, 242), Size(322, 242), COLOR_GRAY2RGB),
|
|
|
|
make_tuple("video/x-raw, format=NV12" , Size(322, 242), Size(322, 363), COLOR_YUV2RGB_NV12),
|
|
|
|
make_tuple("video/x-raw, format=NV21" , Size(322, 242), Size(322, 363), COLOR_YUV2RGB_NV21),
|
|
|
|
make_tuple("video/x-raw, format=YV12" , Size(322, 242), Size(322, 363), COLOR_YUV2RGB_YV12),
|
|
|
|
make_tuple("video/x-raw, format=I420" , Size(322, 242), Size(322, 363), COLOR_YUV2RGB_I420),
|
2021-08-17 00:20:10 +08:00
|
|
|
|
|
|
|
// 16 bit
|
|
|
|
make_tuple("video/x-raw, format=GRAY16_LE", Size(640, 480), Size(640, 480), COLOR_GRAY2RGB),
|
|
|
|
make_tuple("video/x-raw, format=GRAY16_BE", Size(640, 480), Size(640, 480), COLOR_GRAY2RGB),
|
2018-03-21 23:01:47 +08:00
|
|
|
};
|
|
|
|
|
2019-01-14 18:33:38 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(videoio, videoio_gstreamer, testing::ValuesIn(test_data));
|
2018-03-21 23:01:47 +08:00
|
|
|
|
2020-12-06 05:28:07 +08:00
|
|
|
TEST(videoio_gstreamer, unsupported_pipeline)
|
2019-06-20 18:51:57 +08:00
|
|
|
{
|
2020-12-06 05:28:07 +08:00
|
|
|
if (!videoio_registry::hasBackend(CAP_GSTREAMER))
|
|
|
|
throw SkipTestException("GStreamer backend was not found");
|
2019-06-20 18:51:57 +08:00
|
|
|
|
|
|
|
// could not link videoconvert0 to matroskamux0, matroskamux0 can't handle caps video/x-raw, format=(string)RGBA
|
|
|
|
std::string pipeline = "appsrc ! videoconvert ! video/x-raw, format=(string)RGBA ! matroskamux ! filesink location=test.mkv";
|
|
|
|
Size frame_size(640, 480);
|
|
|
|
|
|
|
|
VideoWriter writer;
|
2020-12-06 05:28:07 +08:00
|
|
|
EXPECT_NO_THROW(writer.open(pipeline, CAP_GSTREAMER, 0/*fourcc*/, 30/*fps*/, frame_size, true));
|
2019-06-20 18:51:57 +08:00
|
|
|
EXPECT_FALSE(writer.isOpened());
|
|
|
|
// no frames
|
|
|
|
EXPECT_NO_THROW(writer.release());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-06 05:28:07 +08:00
|
|
|
TEST(videoio_gstreamer, gray16_writing)
|
|
|
|
{
|
|
|
|
if (!videoio_registry::hasBackend(CAP_GSTREAMER))
|
|
|
|
throw SkipTestException("GStreamer backend was not found");
|
|
|
|
|
|
|
|
Size frame_size(320, 240);
|
|
|
|
|
|
|
|
// generate a noise frame
|
|
|
|
Mat frame = Mat(frame_size, CV_16U);
|
|
|
|
randu(frame, 0, 65535);
|
|
|
|
|
|
|
|
// generate a temp filename, and fix path separators to how GStreamer expects them
|
|
|
|
cv::String temp_file = cv::tempfile(".raw");
|
|
|
|
std::replace(temp_file.begin(), temp_file.end(), '\\', '/');
|
|
|
|
|
|
|
|
// write noise frame to file using GStreamer
|
|
|
|
std::ostringstream writer_pipeline;
|
|
|
|
writer_pipeline << "appsrc ! filesink location=" << temp_file;
|
|
|
|
std::vector<int> params {
|
|
|
|
VIDEOWRITER_PROP_IS_COLOR, 0/*false*/,
|
|
|
|
VIDEOWRITER_PROP_DEPTH, CV_16U
|
|
|
|
};
|
|
|
|
VideoWriter writer;
|
|
|
|
ASSERT_NO_THROW(writer.open(writer_pipeline.str(), CAP_GSTREAMER, 0/*fourcc*/, 30/*fps*/, frame_size, params));
|
|
|
|
ASSERT_TRUE(writer.isOpened());
|
|
|
|
ASSERT_NO_THROW(writer.write(frame));
|
|
|
|
ASSERT_NO_THROW(writer.release());
|
|
|
|
|
|
|
|
// read noise frame back in
|
|
|
|
Mat written_frame(frame_size, CV_16U);
|
|
|
|
std::ifstream fs(temp_file, std::ios::in | std::ios::binary);
|
|
|
|
fs.read((char*)written_frame.ptr(0), frame_size.width * frame_size.height * 2);
|
|
|
|
ASSERT_TRUE(fs);
|
|
|
|
fs.close();
|
|
|
|
|
|
|
|
// compare to make sure it's identical
|
|
|
|
EXPECT_EQ(0, cv::norm(frame, written_frame, NORM_INF));
|
|
|
|
|
|
|
|
// remove temp file
|
|
|
|
EXPECT_EQ(0, remove(temp_file.c_str()));
|
|
|
|
}
|
|
|
|
|
2022-12-15 17:53:22 +08:00
|
|
|
TEST(videoio_gstreamer, timeout_property)
|
|
|
|
{
|
|
|
|
if (!videoio_registry::hasBackend(CAP_GSTREAMER))
|
|
|
|
throw SkipTestException("GStreamer backend was not found");
|
|
|
|
|
|
|
|
VideoCapture cap;
|
|
|
|
cap.open("videotestsrc ! appsink", CAP_GSTREAMER);
|
|
|
|
ASSERT_TRUE(cap.isOpened());
|
|
|
|
const double default_timeout = 30000; // 30 seconds
|
|
|
|
const double open_timeout = 5678; // 3 seconds
|
|
|
|
const double read_timeout = 1234; // 1 second
|
|
|
|
EXPECT_NEAR(default_timeout, cap.get(CAP_PROP_OPEN_TIMEOUT_MSEC), 1e-3);
|
|
|
|
const double current_read_timeout = cap.get(CAP_PROP_READ_TIMEOUT_MSEC);
|
|
|
|
const bool read_timeout_supported = current_read_timeout > 0.0;
|
|
|
|
if (read_timeout_supported)
|
|
|
|
{
|
|
|
|
EXPECT_NEAR(default_timeout, current_read_timeout, 1e-3);
|
|
|
|
}
|
|
|
|
cap.set(CAP_PROP_OPEN_TIMEOUT_MSEC, open_timeout);
|
|
|
|
EXPECT_NEAR(open_timeout, cap.get(CAP_PROP_OPEN_TIMEOUT_MSEC), 1e-3);
|
|
|
|
if (read_timeout_supported)
|
|
|
|
{
|
|
|
|
cap.set(CAP_PROP_READ_TIMEOUT_MSEC, read_timeout);
|
|
|
|
EXPECT_NEAR(read_timeout, cap.get(CAP_PROP_READ_TIMEOUT_MSEC), 1e-3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Merge pull request #24243 from kecsap:4.x
Fix gstreamer backend with manual pipelines #24243
- Fix broken seeking in audio/video playback
- Fix broken audio playback
- Fix unreliable seeking
- Estimate frame count if it is not available directly
- Return -1 for frame count and fps if it is not available.
- Return 0 for fps if the video has variable frame rate
- Enable and fix tests
### Pull Request Readiness Checklist
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
- [-] There is a reference to the original bug report and related work => Reproducible test provided
- [-] 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
1. Download two test videos:
```bash
wget https://github.com/ietf-wg-cellar/matroska-test-files/raw/master/test_files/test1.mkv
wget https://test-videos.co.uk/vids/jellyfish/mkv/360/Jellyfish_360_10s_5MB.mkv
```
2. I modified a OpenCV videoio sample to demonstrate the problem, here it is the patch: http://dpaste.com//C9MAT2K6W
3. Build the sample, on Ubuntu:
```bash
g++ -g videocapture_audio_combination.cpp -I/usr/include/opencv4 `pkg-config --libs --cflags opencv4` -o videocapture_audio_combination
```
4. Play an audio stream with seeking BEFORE the fix:
```bash
$ ./videocapture_audio_combination --audio "filesrc location=test1.mkv ! queue ! matroskademux name=demux demux.audio_0 ! decodebin ! audioconvert ! appsink"[ERROR:0@0.009] global cap.cpp:164 open VIDEOIO(GSTREAMER): raised OpenCV exception:
OpenCV(4.8.0-dev) ./modules/videoio/src/cap_gstreamer.cpp:153: error: (-215:Assertion failed) ptr in function 'get'
[ WARN:0@0.009] global cap.cpp:204 open VIDEOIO(GSTREAMER): backend is generally available but can't be used to capture by name
ERROR! Can't to open file: filesrc location=test1.mkv ! queue ! matroskademux name=demux demux.audio_0 ! decodebin ! audioconvert ! appsink
```
5. Play a video stream with seeking BEFORE the fix:
```bash
$ ./videocapture_audio_combination --audio "filesrc location=Jellyfish_360_10s_5MB.mkv ! queue ! matroskademux name=demux demux.video_0 ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink drop=1"
[ WARN:0@0.034] global cap_gstreamer.cpp:1728 open OpenCV | GStreamer warning: Cannot query video position: status=1, value=22, duration=300
CAP_PROP_AUDIO_DATA_DEPTH: CV_16S
CAP_PROP_AUDIO_SAMPLES_PER_SECOND: 44100
CAP_PROP_AUDIO_TOTAL_CHANNELS: 0
CAP_PROP_AUDIO_TOTAL_STREAMS: [ WARN:0@0.034] global cap_gstreamer.cpp:1898 getProperty OpenCV | GStreamer: CAP_PROP_AUDIO_TOTAL_STREAMS property is not supported
0
[ WARN:0@0.034] global cap_gstreamer.cpp:1817 getProperty OpenCV | GStreamer: CAP_PROP_POS_MSEC property result may be unrealiable: https://github.com/opencv/opencv/issues/19025
Timestamp: 0.6218
Timestamp: 33.1085
Timestamp: 67.1274
Timestamp: 100.1182
Timestamp: 133.1204
Timestamp: 167.1195
Timestamp: 200.1161
Timestamp: 233.1147
Timestamp: 267.1194
Timestamp: 300.1202
[ WARN:0@0.338] global cap_gstreamer.cpp:1949 setProperty OpenCV | GStreamer warning: GStreamer: unable to seek
0:00:00.338215907 3892572 0x5592899c7580 WARN basesrc gstbasesrc.c:3127:gst_base_src_loop:<filesrc0> error: Internal data stream error.
0:00:00.338235884 3892572 0x5592899c7580 WARN basesrc gstbasesrc.c:3127:gst_base_src_loop:<filesrc0> error: streaming stopped, reason not-linked (-1)
0:00:00.338264287 3892572 0x5592899c7580 WARN queue gstqueue.c:992:gst_queue_handle_sink_event:<queue0> error: Internal data stream error.
0:00:00.338270329 3892572 0x5592899c7580 WARN queue gstqueue.c:992:gst_queue_handle_sink_event:<queue0> error: streaming stopped, reason not-linked (-1)
[ WARN:0@0.339] global cap_gstreamer.cpp:2784 handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module filesrc0 reported: Internal data stream error.
[ WARN:0@0.339] global cap_gstreamer.cpp:1199 startPipeline OpenCV | GStreamer warning: unable to start pipeline
Number of audio samples: 0
Number of video frames: 10
[ WARN:0@0.339] global cap_gstreamer.cpp:1164 isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
```
6. Play an audio stream with seeking AFTER the fix:
```bash
$ ./videocapture_audio_combination --audio "filesrc location=test1.mkv ! queue ! matroskademux name=demux demux.audio_0 ! decodebin ! audioconvert ! appsink"CAP_PROP_AUDIO_DATA_DEPTH: CV_16S
CAP_PROP_AUDIO_SAMPLES_PER_SECOND: 48000
CAP_PROP_AUDIO_TOTAL_CHANNELS: 2
CAP_PROP_AUDIO_TOTAL_STREAMS: [ WARN:0@0.025] global cap_gstreamer.cpp:1903 getProperty OpenCV | GStreamer: CAP_PROP_AUDIO_TOTAL_STREAMS property is not supported
0
Timestamp: 0.0000
Timestamp: 24.0000
Timestamp: 48.0000
Timestamp: 72.0000
Timestamp: 96.0000
Timestamp: 120.0000
Timestamp: 144.0000
Timestamp: 168.0000
Timestamp: 192.0000
Timestamp: 216.0000
Timestamp: 3500.0000
Timestamp: 3504.0000
Timestamp: 3528.0000
Timestamp: 3552.0000
Timestamp: 3576.0000
Timestamp: 3600.0000
Timestamp: 3624.0000
Timestamp: 3648.0000
Timestamp: 3672.0000
Timestamp: 3696.0000
Timestamp: 3720.0000
Timestamp: 3744.0000
Timestamp: 3768.0000
Timestamp: 3792.0000
Timestamp: 3816.0000
Timestamp: 3840.0000
Timestamp: 3864.0000
Timestamp: 3888.0000
Timestamp: 3912.0000
Timestamp: 3936.0000
```
7. Play a video stream with seeking AFTER the fix:
```bash
$ ./videocapture_audio_combination --audio "filesrc location=Jellyfish_360_10s_5MB.mkv ! queue ! matroskademux name=demux demux.video_0 ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink drop=1"
[ WARN:0@0.033] global cap_gstreamer.cpp:1746 open OpenCV | GStreamer warning: Cannot query video position: status=1, value=22, duration=300
CAP_PROP_AUDIO_DATA_DEPTH: CV_16S
CAP_PROP_AUDIO_SAMPLES_PER_SECOND: 44100
CAP_PROP_AUDIO_TOTAL_CHANNELS: 0
CAP_PROP_AUDIO_TOTAL_STREAMS: [ WARN:0@0.034] global cap_gstreamer.cpp:1903 getProperty OpenCV | GStreamer: CAP_PROP_AUDIO_TOTAL_STREAMS property is not supported
0
Timestamp: 0.0000
Timestamp: 33.0000
Timestamp: 67.0000
Timestamp: 100.0000
Timestamp: 133.0000
Timestamp: 167.0000
Timestamp: 200.0000
Timestamp: 233.0000
Timestamp: 267.0000
Timestamp: 300.0000
0:00:00.335931693 3893501 0x55bbe76ad920 WARN matroskareadcommon matroska-read-common.c:759:gst_matroska_read_common_parse_skip:<demux:sink> Unknown CueTrackPositions subelement 0xf0 - ignoring
0:00:00.335952823 3893501 0x55bbe76ad920 WARN matroskareadcommon matroska-read-common.c:759:gst_matroska_read_common_parse_skip:<demux:sink> Unknown CueTrackPositions subelement 0xf0 - ignoring
0:00:00.335988029 3893501 0x55bbe76ad920 WARN basesrc gstbasesrc.c:1742:gst_base_src_perform_seek:<filesrc0> duplicate event found 184
Timestamp: 3467.0000
Timestamp: 3500.0000
Timestamp: 3533.0000
Timestamp: 3567.0000
Timestamp: 3600.0000
Timestamp: 3633.0000
Timestamp: 3667.0000
Timestamp: 3700.0000
Timestamp: 3733.0000
Timestamp: 3767.0000
Timestamp: 3800.0000
Timestamp: 3833.0000
Timestamp: 3867.0000
Timestamp: 3900.0000
Timestamp: 3933.0000
Timestamp: 3967.0000
Timestamp: 4000.0000
Timestamp: 4033.0000
Timestamp: 4067.0000
Timestamp: 4100.0000
```
2023-11-08 18:41:50 +08:00
|
|
|
//==============================================================================
|
|
|
|
// Seeking test with manual GStreamer pipeline
|
|
|
|
typedef testing::TestWithParam<string> gstreamer_bunny;
|
|
|
|
|
|
|
|
TEST_P(gstreamer_bunny, manual_seek)
|
|
|
|
{
|
|
|
|
if (!videoio_registry::hasBackend(CAP_GSTREAMER))
|
|
|
|
throw SkipTestException("GStreamer backend was not found");
|
|
|
|
|
|
|
|
const string video_file = BunnyParameters::getFilename("." + GetParam());
|
|
|
|
const string pipeline = "filesrc location=" + video_file + " ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink drop=1";
|
|
|
|
const double target_pos = 3000.0;
|
2023-11-08 19:46:44 +08:00
|
|
|
const double ms_per_frame = 1000.0 / BunnyParameters::getFps();
|
Merge pull request #24243 from kecsap:4.x
Fix gstreamer backend with manual pipelines #24243
- Fix broken seeking in audio/video playback
- Fix broken audio playback
- Fix unreliable seeking
- Estimate frame count if it is not available directly
- Return -1 for frame count and fps if it is not available.
- Return 0 for fps if the video has variable frame rate
- Enable and fix tests
### Pull Request Readiness Checklist
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
- [-] There is a reference to the original bug report and related work => Reproducible test provided
- [-] 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
1. Download two test videos:
```bash
wget https://github.com/ietf-wg-cellar/matroska-test-files/raw/master/test_files/test1.mkv
wget https://test-videos.co.uk/vids/jellyfish/mkv/360/Jellyfish_360_10s_5MB.mkv
```
2. I modified a OpenCV videoio sample to demonstrate the problem, here it is the patch: http://dpaste.com//C9MAT2K6W
3. Build the sample, on Ubuntu:
```bash
g++ -g videocapture_audio_combination.cpp -I/usr/include/opencv4 `pkg-config --libs --cflags opencv4` -o videocapture_audio_combination
```
4. Play an audio stream with seeking BEFORE the fix:
```bash
$ ./videocapture_audio_combination --audio "filesrc location=test1.mkv ! queue ! matroskademux name=demux demux.audio_0 ! decodebin ! audioconvert ! appsink"[ERROR:0@0.009] global cap.cpp:164 open VIDEOIO(GSTREAMER): raised OpenCV exception:
OpenCV(4.8.0-dev) ./modules/videoio/src/cap_gstreamer.cpp:153: error: (-215:Assertion failed) ptr in function 'get'
[ WARN:0@0.009] global cap.cpp:204 open VIDEOIO(GSTREAMER): backend is generally available but can't be used to capture by name
ERROR! Can't to open file: filesrc location=test1.mkv ! queue ! matroskademux name=demux demux.audio_0 ! decodebin ! audioconvert ! appsink
```
5. Play a video stream with seeking BEFORE the fix:
```bash
$ ./videocapture_audio_combination --audio "filesrc location=Jellyfish_360_10s_5MB.mkv ! queue ! matroskademux name=demux demux.video_0 ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink drop=1"
[ WARN:0@0.034] global cap_gstreamer.cpp:1728 open OpenCV | GStreamer warning: Cannot query video position: status=1, value=22, duration=300
CAP_PROP_AUDIO_DATA_DEPTH: CV_16S
CAP_PROP_AUDIO_SAMPLES_PER_SECOND: 44100
CAP_PROP_AUDIO_TOTAL_CHANNELS: 0
CAP_PROP_AUDIO_TOTAL_STREAMS: [ WARN:0@0.034] global cap_gstreamer.cpp:1898 getProperty OpenCV | GStreamer: CAP_PROP_AUDIO_TOTAL_STREAMS property is not supported
0
[ WARN:0@0.034] global cap_gstreamer.cpp:1817 getProperty OpenCV | GStreamer: CAP_PROP_POS_MSEC property result may be unrealiable: https://github.com/opencv/opencv/issues/19025
Timestamp: 0.6218
Timestamp: 33.1085
Timestamp: 67.1274
Timestamp: 100.1182
Timestamp: 133.1204
Timestamp: 167.1195
Timestamp: 200.1161
Timestamp: 233.1147
Timestamp: 267.1194
Timestamp: 300.1202
[ WARN:0@0.338] global cap_gstreamer.cpp:1949 setProperty OpenCV | GStreamer warning: GStreamer: unable to seek
0:00:00.338215907 3892572 0x5592899c7580 WARN basesrc gstbasesrc.c:3127:gst_base_src_loop:<filesrc0> error: Internal data stream error.
0:00:00.338235884 3892572 0x5592899c7580 WARN basesrc gstbasesrc.c:3127:gst_base_src_loop:<filesrc0> error: streaming stopped, reason not-linked (-1)
0:00:00.338264287 3892572 0x5592899c7580 WARN queue gstqueue.c:992:gst_queue_handle_sink_event:<queue0> error: Internal data stream error.
0:00:00.338270329 3892572 0x5592899c7580 WARN queue gstqueue.c:992:gst_queue_handle_sink_event:<queue0> error: streaming stopped, reason not-linked (-1)
[ WARN:0@0.339] global cap_gstreamer.cpp:2784 handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module filesrc0 reported: Internal data stream error.
[ WARN:0@0.339] global cap_gstreamer.cpp:1199 startPipeline OpenCV | GStreamer warning: unable to start pipeline
Number of audio samples: 0
Number of video frames: 10
[ WARN:0@0.339] global cap_gstreamer.cpp:1164 isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
```
6. Play an audio stream with seeking AFTER the fix:
```bash
$ ./videocapture_audio_combination --audio "filesrc location=test1.mkv ! queue ! matroskademux name=demux demux.audio_0 ! decodebin ! audioconvert ! appsink"CAP_PROP_AUDIO_DATA_DEPTH: CV_16S
CAP_PROP_AUDIO_SAMPLES_PER_SECOND: 48000
CAP_PROP_AUDIO_TOTAL_CHANNELS: 2
CAP_PROP_AUDIO_TOTAL_STREAMS: [ WARN:0@0.025] global cap_gstreamer.cpp:1903 getProperty OpenCV | GStreamer: CAP_PROP_AUDIO_TOTAL_STREAMS property is not supported
0
Timestamp: 0.0000
Timestamp: 24.0000
Timestamp: 48.0000
Timestamp: 72.0000
Timestamp: 96.0000
Timestamp: 120.0000
Timestamp: 144.0000
Timestamp: 168.0000
Timestamp: 192.0000
Timestamp: 216.0000
Timestamp: 3500.0000
Timestamp: 3504.0000
Timestamp: 3528.0000
Timestamp: 3552.0000
Timestamp: 3576.0000
Timestamp: 3600.0000
Timestamp: 3624.0000
Timestamp: 3648.0000
Timestamp: 3672.0000
Timestamp: 3696.0000
Timestamp: 3720.0000
Timestamp: 3744.0000
Timestamp: 3768.0000
Timestamp: 3792.0000
Timestamp: 3816.0000
Timestamp: 3840.0000
Timestamp: 3864.0000
Timestamp: 3888.0000
Timestamp: 3912.0000
Timestamp: 3936.0000
```
7. Play a video stream with seeking AFTER the fix:
```bash
$ ./videocapture_audio_combination --audio "filesrc location=Jellyfish_360_10s_5MB.mkv ! queue ! matroskademux name=demux demux.video_0 ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink drop=1"
[ WARN:0@0.033] global cap_gstreamer.cpp:1746 open OpenCV | GStreamer warning: Cannot query video position: status=1, value=22, duration=300
CAP_PROP_AUDIO_DATA_DEPTH: CV_16S
CAP_PROP_AUDIO_SAMPLES_PER_SECOND: 44100
CAP_PROP_AUDIO_TOTAL_CHANNELS: 0
CAP_PROP_AUDIO_TOTAL_STREAMS: [ WARN:0@0.034] global cap_gstreamer.cpp:1903 getProperty OpenCV | GStreamer: CAP_PROP_AUDIO_TOTAL_STREAMS property is not supported
0
Timestamp: 0.0000
Timestamp: 33.0000
Timestamp: 67.0000
Timestamp: 100.0000
Timestamp: 133.0000
Timestamp: 167.0000
Timestamp: 200.0000
Timestamp: 233.0000
Timestamp: 267.0000
Timestamp: 300.0000
0:00:00.335931693 3893501 0x55bbe76ad920 WARN matroskareadcommon matroska-read-common.c:759:gst_matroska_read_common_parse_skip:<demux:sink> Unknown CueTrackPositions subelement 0xf0 - ignoring
0:00:00.335952823 3893501 0x55bbe76ad920 WARN matroskareadcommon matroska-read-common.c:759:gst_matroska_read_common_parse_skip:<demux:sink> Unknown CueTrackPositions subelement 0xf0 - ignoring
0:00:00.335988029 3893501 0x55bbe76ad920 WARN basesrc gstbasesrc.c:1742:gst_base_src_perform_seek:<filesrc0> duplicate event found 184
Timestamp: 3467.0000
Timestamp: 3500.0000
Timestamp: 3533.0000
Timestamp: 3567.0000
Timestamp: 3600.0000
Timestamp: 3633.0000
Timestamp: 3667.0000
Timestamp: 3700.0000
Timestamp: 3733.0000
Timestamp: 3767.0000
Timestamp: 3800.0000
Timestamp: 3833.0000
Timestamp: 3867.0000
Timestamp: 3900.0000
Timestamp: 3933.0000
Timestamp: 3967.0000
Timestamp: 4000.0000
Timestamp: 4033.0000
Timestamp: 4067.0000
Timestamp: 4100.0000
```
2023-11-08 18:41:50 +08:00
|
|
|
VideoCapture cap;
|
|
|
|
cap.open(pipeline, CAP_GSTREAMER);
|
|
|
|
ASSERT_TRUE(cap.isOpened());
|
|
|
|
Mat img;
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
cap >> img;
|
|
|
|
}
|
|
|
|
EXPECT_FALSE(img.empty());
|
|
|
|
cap.set(CAP_PROP_POS_MSEC, target_pos);
|
|
|
|
cap >> img;
|
|
|
|
EXPECT_FALSE(img.empty());
|
|
|
|
double actual_pos = cap.get(CAP_PROP_POS_MSEC);
|
|
|
|
EXPECT_NEAR(actual_pos, target_pos, ms_per_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const string bunny_params[] = {
|
|
|
|
// string("wmv"),
|
|
|
|
string("mov"),
|
|
|
|
string("mp4"),
|
|
|
|
// string("mpg"),
|
|
|
|
string("avi"),
|
|
|
|
// string("h264"),
|
|
|
|
// string("h265"),
|
|
|
|
string("mjpg.avi")
|
|
|
|
};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(videoio, gstreamer_bunny, testing::ValuesIn(bunny_params));
|
|
|
|
|
|
|
|
|
2021-02-24 16:40:42 +08:00
|
|
|
}} // namespace
|