Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
ecbec723
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ecbec723
编写于
9月 23, 2014
作者:
V
Vadim Pisarevsky
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3253 from asmorkalov:ocv_gstreamer2
上级
77524834
05184551
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
107 addition
and
27 deletion
+107
-27
modules/videoio/src/cap_gstreamer.cpp
modules/videoio/src/cap_gstreamer.cpp
+97
-25
modules/videoio/test/test_video_io.cpp
modules/videoio/test/test_video_io.cpp
+10
-2
未找到文件。
modules/videoio/src/cap_gstreamer.cpp
浏览文件 @
ecbec723
...
...
@@ -73,13 +73,14 @@
#define CV_WARN(message) fprintf(stderr, "warning: %s (%s:%d)\n", message, __FILE__, __LINE__)
#endif
#if GST_VERSION_MAJOR > 0
#define COLOR_ELEM "autovideoconvert"
#else
#if GST_VERSION_MAJOR == 0
#define COLOR_ELEM "ffmpegcolorspace"
#elif FULL_GST_VERSION < VERSION_NUM(1,5,0)
#define COLOR_ELEM "videoconvert"
#else
#define COLOR_ELEM "autovideoconvert"
#endif
void
toFraction
(
double
decimal
,
double
&
numerator
,
double
&
denominator
);
void
handleMessage
(
GstElement
*
pipeline
);
...
...
@@ -555,6 +556,7 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
gst_initializer
::
init
();
bool
file
=
false
;
bool
stream
=
false
;
bool
manualpipeline
=
false
;
char
*
uri
=
NULL
;
...
...
@@ -591,7 +593,12 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
if
(
uri
)
{
uri
=
g_filename_to_uri
(
uri
,
NULL
,
NULL
);
if
(
!
uri
)
{
if
(
uri
)
{
file
=
true
;
}
else
{
CV_WARN
(
"GStreamer: Error opening file
\n
"
);
close
();
return
false
;
...
...
@@ -601,9 +608,9 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
{
GError
*
err
=
NULL
;
uridecodebin
=
gst_parse_launch
(
filename
,
&
err
);
if
(
!
uridecodebin
)
{
//fprintf(stderr, "GStreamer: Error opening bin: %s\n", err->message);
//close(
);
if
(
!
uridecodebin
)
{
fprintf
(
stderr
,
"GStreamer: Error opening bin: %s
\n
"
,
err
->
message
);
return
false
;
}
stream
=
true
;
...
...
@@ -632,7 +639,7 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
element_from_uri
=
true
;
}
else
{
uridecodebin
=
gst_element_factory_make
(
"uridecodebin"
,
NULL
);
g_object_set
(
G_OBJECT
(
uridecodebin
),
"uri"
,
uri
,
NULL
);
g_object_set
(
G_OBJECT
(
uridecodebin
),
"uri"
,
uri
,
NULL
);
}
g_free
(
protocol
);
...
...
@@ -744,7 +751,7 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
gst_caps_unref
(
caps
);
// For video files only: set pipeline to PAUSED state to get its duration
if
(
stream
)
if
(
file
)
{
status
=
gst_element_set_state
(
GST_ELEMENT
(
pipeline
),
GST_STATE_PAUSED
);
if
(
status
==
GST_STATE_CHANGE_ASYNC
)
...
...
@@ -772,6 +779,7 @@ bool CvCapture_GStreamer::open( int type, const char* filename )
if
(
!
gst_element_query_duration
(
sink
,
format
,
&
duration
))
#endif
{
handleMessage
(
pipeline
);
CV_WARN
(
"GStreamer: unable to query duration of stream"
);
duration
=
-
1
;
return
true
;
...
...
@@ -1166,7 +1174,6 @@ const char* CvVideoWriter_GStreamer::filenameToMimetype(const char *filename)
return
(
const
char
*
)
"video/x-msvideo"
;
}
/*!
* \brief CvVideoWriter_GStreamer::open
* \param filename filename to output to
...
...
@@ -1214,7 +1221,12 @@ bool CvVideoWriter_GStreamer::open( const char * filename, int fourcc,
GstEncodingVideoProfile
*
videoprofile
=
NULL
;
#endif
GstIterator
*
it
=
NULL
;
GstIterator
*
it
=
NULL
;
gboolean
done
=
FALSE
;
GstElement
*
element
=
NULL
;
gchar
*
name
=
NULL
;
GstElement
*
splitter
=
NULL
;
GstElement
*
combiner
=
NULL
;
// we first try to construct a pipeline from the given string.
// if that fails, we assume it is an ordinary filename
...
...
@@ -1222,9 +1234,7 @@ bool CvVideoWriter_GStreamer::open( const char * filename, int fourcc,
__BEGIN__
;
encodebin
=
gst_parse_launch
(
filename
,
&
err
);
if
(
!
encodebin
)
{
manualpipeline
=
false
;
}
manualpipeline
=
(
encodebin
!=
NULL
);
if
(
manualpipeline
)
{
...
...
@@ -1236,10 +1246,6 @@ bool CvVideoWriter_GStreamer::open( const char * filename, int fourcc,
}
#else
it
=
gst_bin_iterate_sources
(
GST_BIN
(
encodebin
));
gboolean
done
=
FALSE
;
GstElement
*
element
=
NULL
;
gchar
*
name
=
NULL
;
GValue
value
=
G_VALUE_INIT
;
while
(
!
done
)
{
...
...
@@ -1289,7 +1295,9 @@ bool CvVideoWriter_GStreamer::open( const char * filename, int fourcc,
if
(
fourcc
==
CV_FOURCC
(
'M'
,
'P'
,
'2'
,
'V'
))
fourcc
=
CV_FOURCC
(
'M'
,
'P'
,
'G'
,
'2'
);
if
(
fourcc
==
CV_FOURCC
(
'D'
,
'R'
,
'A'
,
'C'
))
fourcc
=
CV_FOURCC
(
'd'
,
'r'
,
'a'
,
'c'
);
//create encoder caps from fourcc
videocaps
=
gst_riff_create_video_caps
(
fourcc
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
!
videocaps
){
CV_ERROR
(
CV_StsUnsupportedFormat
,
"Gstreamer Opencv backend does not support this codec."
);
...
...
@@ -1312,6 +1320,7 @@ bool CvVideoWriter_GStreamer::open( const char * filename, int fourcc,
//create pipeline elements
encodebin
=
gst_element_factory_make
(
"encodebin"
,
NULL
);
#if FULL_GST_VERSION >= VERSION_NUM(0,10,32)
g_object_set
(
G_OBJECT
(
encodebin
),
"profile"
,
containerprofile
,
NULL
);
#endif
...
...
@@ -1376,7 +1385,7 @@ bool CvVideoWriter_GStreamer::open( const char * filename, int fourcc,
g_object_set
(
G_OBJECT
(
source
),
"format"
,
GST_FORMAT_TIME
,
NULL
);
g_object_set
(
G_OBJECT
(
source
),
"block"
,
1
,
NULL
);
g_object_set
(
G_OBJECT
(
source
),
"is-live"
,
0
,
NULL
);
g_object_set
(
G_OBJECT
(
source
),
"emit-signals"
,
1
,
NULL
);
if
(
!
manualpipeline
)
{
...
...
@@ -1387,6 +1396,63 @@ bool CvVideoWriter_GStreamer::open( const char * filename, int fourcc,
}
}
#if GST_VERSION_MAJOR == 0
// HACK: remove streamsplitter and streamcombiner from
// encodebin pipeline to prevent early EOF event handling
// We always fetch BGR or gray-scale frames, so combiner->spliter
// endge in graph is useless.
it
=
gst_bin_iterate_recurse
(
GST_BIN
(
encodebin
));
while
(
!
done
)
{
switch
(
gst_iterator_next
(
it
,
(
void
**
)
&
element
))
{
case
GST_ITERATOR_OK
:
name
=
gst_element_get_name
(
element
);
if
(
strstr
(
name
,
"streamsplitter"
))
splitter
=
element
;
else
if
(
strstr
(
name
,
"streamcombiner"
))
combiner
=
element
;
break
;
case
GST_ITERATOR_RESYNC
:
gst_iterator_resync
(
it
);
break
;
case
GST_ITERATOR_ERROR
:
done
=
true
;
break
;
case
GST_ITERATOR_DONE
:
done
=
true
;
break
;
}
}
gst_iterator_free
(
it
);
if
(
splitter
&&
combiner
)
{
gst_element_unlink
(
splitter
,
combiner
);
GstPad
*
src
=
gst_element_get_pad
(
combiner
,
"src"
);
GstPad
*
sink
=
gst_element_get_pad
(
combiner
,
"encodingsink"
);
GstPad
*
srcPeer
=
gst_pad_get_peer
(
src
);
GstPad
*
sinkPeer
=
gst_pad_get_peer
(
sink
);
gst_pad_unlink
(
sinkPeer
,
sink
);
gst_pad_unlink
(
src
,
srcPeer
);
gst_pad_link
(
sinkPeer
,
srcPeer
);
src
=
gst_element_get_pad
(
splitter
,
"encodingsrc"
);
sink
=
gst_element_get_pad
(
splitter
,
"sink"
);
srcPeer
=
gst_pad_get_peer
(
src
);
sinkPeer
=
gst_pad_get_peer
(
sink
);
gst_pad_unlink
(
sinkPeer
,
sink
);
gst_pad_unlink
(
src
,
srcPeer
);
gst_pad_link
(
sinkPeer
,
srcPeer
);
}
#endif
stateret
=
gst_element_set_state
(
GST_ELEMENT
(
pipeline
),
GST_STATE_PLAYING
);
if
(
stateret
==
GST_STATE_CHANGE_FAILURE
)
{
handleMessage
(
pipeline
);
...
...
@@ -1437,7 +1503,7 @@ bool CvVideoWriter_GStreamer::writeFrame( const IplImage * image )
}
#endif
else
{
CV_
WARN
(
"Invalid video format!
\n
"
);
CV_
ERROR
(
CV_StsUnsupportedFormat
,
"cvWriteFrame() needs BGR or grayscale images
\n
"
);
return
false
;
}
...
...
@@ -1447,7 +1513,12 @@ bool CvVideoWriter_GStreamer::writeFrame( const IplImage * image )
//gst_app_src_push_buffer takes ownership of the buffer, so we need to supply it a copy
#if GST_VERSION_MAJOR == 0
buffer
=
gst_buffer_new_and_alloc
(
size
);
buffer
=
gst_buffer_try_new_and_alloc
(
size
);
if
(
!
buffer
)
{
CV_ERROR
(
CV_StsBadSize
,
"Cannot create GStreamer buffer"
);
}
memcpy
(
GST_BUFFER_DATA
(
buffer
),
(
guint8
*
)
image
->
imageData
,
size
);
GST_BUFFER_DURATION
(
buffer
)
=
duration
;
GST_BUFFER_TIMESTAMP
(
buffer
)
=
timestamp
;
...
...
@@ -1469,7 +1540,8 @@ bool CvVideoWriter_GStreamer::writeFrame( const IplImage * image )
CV_WARN
(
"Error pushing buffer to GStreamer pipeline"
);
return
false
;
}
//gst_debug_bin_to_dot_file (GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline");
//GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline");
++
num_frames
;
...
...
@@ -1559,8 +1631,8 @@ void handleMessage(GstElement * pipeline)
break
;
case
GST_MESSAGE_ERROR
:
gst_message_parse_error
(
msg
,
&
err
,
&
debug
);
//
fprintf(stderr, "GStreamer Plugin: Embedded video playback halted; module %s reported: %s\n",
//
gst_element_get_name(GST_MESSAGE_SRC (msg)), err->message);
fprintf
(
stderr
,
"GStreamer Plugin: Embedded video playback halted; module %s reported: %s
\n
"
,
gst_element_get_name
(
GST_MESSAGE_SRC
(
msg
)),
err
->
message
);
g_error_free
(
err
);
g_free
(
debug
);
...
...
modules/videoio/test/test_video_io.cpp
浏览文件 @
ecbec723
...
...
@@ -92,7 +92,9 @@ const VideoFormat g_specific_fmt_list[] =
VideoFormat
(
"mkv"
,
VideoWriter
::
fourcc
(
'X'
,
'V'
,
'I'
,
'D'
)),
VideoFormat
(
"mkv"
,
VideoWriter
::
fourcc
(
'M'
,
'P'
,
'E'
,
'G'
)),
VideoFormat
(
"mkv"
,
VideoWriter
::
fourcc
(
'M'
,
'J'
,
'P'
,
'G'
)),
#ifndef HAVE_GSTREAMER
VideoFormat
(
"mov"
,
VideoWriter
::
fourcc
(
'm'
,
'p'
,
'4'
,
'v'
)),
#endif
VideoFormat
()
};
#endif
...
...
@@ -490,7 +492,13 @@ void CV_VideoIOTest::SpecificVideoTest(const string& dir, const cvtest::VideoFor
if
(
fourcc
==
VideoWriter
::
fourcc
(
'M'
,
'P'
,
'E'
,
'G'
)
&&
ext
==
"mkv"
)
allowed_extra_frames
=
1
;
if
(
FRAME_COUNT
<
IMAGE_COUNT
||
FRAME_COUNT
>
IMAGE_COUNT
+
allowed_extra_frames
)
// Hack! Some GStreamer encoding pipelines drop last frame in the video
int
allowed_frame_frop
=
0
;
#ifdef HAVE_GSTREAMER
allowed_frame_frop
=
1
;
#endif
if
(
FRAME_COUNT
<
IMAGE_COUNT
-
allowed_frame_frop
||
FRAME_COUNT
>
IMAGE_COUNT
+
allowed_extra_frames
)
{
ts
->
printf
(
ts
->
LOG
,
"
\n
Frame count checking for video_%s.%s...
\n
"
,
fourcc_str
.
c_str
(),
ext
.
c_str
());
ts
->
printf
(
ts
->
LOG
,
"Video codec: %s
\n
"
,
fourcc_str
.
c_str
());
...
...
@@ -505,7 +513,7 @@ void CV_VideoIOTest::SpecificVideoTest(const string& dir, const cvtest::VideoFor
return
;
}
for
(
int
i
=
0
;
(
size_t
)
i
<
IMAGE_COUNT
;
i
++
)
for
(
int
i
=
0
;
(
size_t
)
i
<
IMAGE_COUNT
-
allowed_frame_frop
;
i
++
)
{
Mat
frame
;
cap
>>
frame
;
if
(
frame
.
empty
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录