@@ -1240,8 +1240,8 @@ class CvVideoWriter_GStreamer : public CvVideoWriter
1240
1240
{
1241
1241
public:
1242
1242
CvVideoWriter_GStreamer ()
1243
- : input_pix_fmt( 0 ),
1244
- num_frames (0 ), framerate(0 )
1243
+ : ipl_depth(CV_8U)
1244
+ , input_pix_fmt( 0 ), num_frames(0 ), framerate(0 )
1245
1245
{
1246
1246
}
1247
1247
virtual ~CvVideoWriter_GStreamer () CV_OVERRIDE
@@ -1263,14 +1263,16 @@ class CvVideoWriter_GStreamer : public CvVideoWriter
1263
1263
int getCaptureDomain () const CV_OVERRIDE { return cv::CAP_GSTREAMER; }
1264
1264
1265
1265
bool open (const std::string &filename, int fourcc,
1266
- double fps, const Size &frameSize, bool isColor );
1266
+ double fps, const Size &frameSize, bool isColor, int depth );
1267
1267
void close ();
1268
1268
bool writeFrame ( const IplImage* image ) CV_OVERRIDE;
1269
+
1270
+ int getIplDepth () const { return ipl_depth; }
1269
1271
protected:
1270
1272
const char * filenameToMimetype (const char * filename);
1271
1273
GSafePtr<GstElement> pipeline;
1272
1274
GSafePtr<GstElement> source;
1273
-
1275
+ int ipl_depth;
1274
1276
int input_pix_fmt;
1275
1277
int num_frames;
1276
1278
double framerate;
@@ -1396,6 +1398,7 @@ const char* CvVideoWriter_GStreamer::filenameToMimetype(const char *filename)
1396
1398
* \param fps desired framerate
1397
1399
* \param frameSize the size of the expected frames
1398
1400
* \param is_color color or grayscale
1401
+ * \param depth the depth of the expected frames
1399
1402
* \return success
1400
1403
*
1401
1404
* We support 2 modes of operation. Either the user enters a filename and a fourcc
@@ -1408,7 +1411,8 @@ const char* CvVideoWriter_GStreamer::filenameToMimetype(const char *filename)
1408
1411
*
1409
1412
*/
1410
1413
bool CvVideoWriter_GStreamer::open ( const std::string &filename, int fourcc,
1411
- double fps, const cv::Size &frameSize, bool is_color )
1414
+ double fps, const cv::Size &frameSize,
1415
+ bool is_color, int depth )
1412
1416
{
1413
1417
// check arguments
1414
1418
CV_Assert (!filename.empty ());
@@ -1548,6 +1552,8 @@ bool CvVideoWriter_GStreamer::open( const std::string &filename, int fourcc,
1548
1552
1549
1553
if (fourcc == CV_FOURCC (' M' ,' J' ,' P' ,' G' ) && frameSize.height == 1 )
1550
1554
{
1555
+ CV_Assert (depth == CV_8U);
1556
+ ipl_depth = IPL_DEPTH_8U;
1551
1557
input_pix_fmt = GST_VIDEO_FORMAT_ENCODED;
1552
1558
caps.attach (gst_caps_new_simple (" image/jpeg" ,
1553
1559
" framerate" , GST_TYPE_FRACTION, int (fps_num), int (fps_denom),
@@ -1556,6 +1562,8 @@ bool CvVideoWriter_GStreamer::open( const std::string &filename, int fourcc,
1556
1562
}
1557
1563
else if (is_color)
1558
1564
{
1565
+ CV_Assert (depth == CV_8U);
1566
+ ipl_depth = IPL_DEPTH_8U;
1559
1567
input_pix_fmt = GST_VIDEO_FORMAT_BGR;
1560
1568
bufsize = frameSize.width * frameSize.height * 3 ;
1561
1569
@@ -1569,8 +1577,9 @@ bool CvVideoWriter_GStreamer::open( const std::string &filename, int fourcc,
1569
1577
caps.attach (gst_caps_fixate (caps.detach ()));
1570
1578
CV_Assert (caps);
1571
1579
}
1572
- else
1580
+ else if (!is_color && depth == CV_8U)
1573
1581
{
1582
+ ipl_depth = IPL_DEPTH_8U;
1574
1583
input_pix_fmt = GST_VIDEO_FORMAT_GRAY8;
1575
1584
bufsize = frameSize.width * frameSize.height ;
1576
1585
@@ -1582,6 +1591,26 @@ bool CvVideoWriter_GStreamer::open( const std::string &filename, int fourcc,
1582
1591
NULL ));
1583
1592
caps.attach (gst_caps_fixate (caps.detach ()));
1584
1593
}
1594
+ else if (!is_color && depth == CV_16U)
1595
+ {
1596
+ ipl_depth = IPL_DEPTH_16U;
1597
+ input_pix_fmt = GST_VIDEO_FORMAT_GRAY16_LE;
1598
+ bufsize = frameSize.width * frameSize.height * 2 ;
1599
+
1600
+ caps.attach (gst_caps_new_simple (" video/x-raw" ,
1601
+ " format" , G_TYPE_STRING, " GRAY16_LE" ,
1602
+ " width" , G_TYPE_INT, frameSize.width ,
1603
+ " height" , G_TYPE_INT, frameSize.height ,
1604
+ " framerate" , GST_TYPE_FRACTION, gint (fps_num), gint (fps_denom),
1605
+ NULL ));
1606
+ caps.attach (gst_caps_fixate (caps.detach ()));
1607
+ }
1608
+ else
1609
+ {
1610
+ CV_WARN (" unsupported depth=" << depth <<" , and is_color=" << is_color << " combination" );
1611
+ pipeline.release ();
1612
+ return false ;
1613
+ }
1585
1614
1586
1615
gst_app_src_set_caps (GST_APP_SRC (source.get ()), caps);
1587
1616
gst_app_src_set_stream_type (GST_APP_SRC (source.get ()), GST_APP_STREAM_TYPE_STREAM);
@@ -1659,6 +1688,12 @@ bool CvVideoWriter_GStreamer::writeFrame( const IplImage * image )
1659
1688
return false ;
1660
1689
}
1661
1690
}
1691
+ else if (input_pix_fmt == GST_VIDEO_FORMAT_GRAY16_LE) {
1692
+ if (image->nChannels != 1 || image->depth != IPL_DEPTH_16U) {
1693
+ CV_WARN (" cvWriteFrame() needs images with depth = IPL_DEPTH_16U and nChannels = 1." );
1694
+ return false ;
1695
+ }
1696
+ }
1662
1697
else {
1663
1698
CV_WARN (" cvWriteFrame() needs BGR or grayscale images\n " );
1664
1699
return false ;
@@ -1699,9 +1734,10 @@ Ptr<IVideoWriter> create_GStreamer_writer(const std::string& filename, int fourc
1699
1734
{
1700
1735
CvVideoWriter_GStreamer* wrt = new CvVideoWriter_GStreamer;
1701
1736
const bool isColor = params.get (VIDEOWRITER_PROP_IS_COLOR, true );
1737
+ const int depth = params.get (VIDEOWRITER_PROP_DEPTH, CV_8U);
1702
1738
try
1703
1739
{
1704
- if (wrt->open (filename, fourcc, fps, frameSize, isColor))
1740
+ if (wrt->open (filename, fourcc, fps, frameSize, isColor, depth ))
1705
1741
return makePtr<LegacyWriter>(wrt);
1706
1742
delete wrt;
1707
1743
}
@@ -1921,15 +1957,40 @@ CvResult CV_API_CALL cv_capture_retrieve(CvPluginCapture handle, int stream_idx,
1921
1957
}
1922
1958
1923
1959
static
1924
- CvResult CV_API_CALL cv_writer_open (const char * filename, int fourcc, double fps, int width, int height, int isColor,
1925
- CV_OUT CvPluginWriter* handle)
1960
+ CvResult CV_API_CALL cv_writer_open_with_params (
1961
+ const char * filename, int fourcc, double fps, int width, int height,
1962
+ int * params, unsigned n_params,
1963
+ CV_OUT CvPluginWriter* handle)
1926
1964
{
1927
1965
CvVideoWriter_GStreamer* wrt = 0 ;
1928
1966
try
1929
1967
{
1930
- wrt = new CvVideoWriter_GStreamer ();
1931
1968
CvSize sz = { width, height };
1932
- if (wrt && wrt->open (filename, fourcc, fps, sz, isColor))
1969
+ bool isColor = true ;
1970
+ int depth = CV_8U;
1971
+ if (params)
1972
+ {
1973
+ for (unsigned i = 0 ; i < n_params; ++i)
1974
+ {
1975
+ const int prop = params[i*2 ];
1976
+ const int value = params[i*2 + 1 ];
1977
+ switch (prop)
1978
+ {
1979
+ case VIDEOWRITER_PROP_IS_COLOR:
1980
+ isColor = value != 0 ;
1981
+ break ;
1982
+ case VIDEOWRITER_PROP_DEPTH:
1983
+ depth = value;
1984
+ break ;
1985
+ default :
1986
+ // TODO emit message about non-recognized propert
1987
+ // FUTURE: there should be mandatory and optional properties
1988
+ return CV_ERROR_FAIL;
1989
+ }
1990
+ }
1991
+ }
1992
+ wrt = new CvVideoWriter_GStreamer ();
1993
+ if (wrt && wrt->open (filename, fourcc, fps, sz, isColor, depth))
1933
1994
{
1934
1995
*handle = (CvPluginWriter)wrt;
1935
1996
return CV_ERROR_OK;
@@ -1943,6 +2004,14 @@ CvResult CV_API_CALL cv_writer_open(const char* filename, int fourcc, double fps
1943
2004
return CV_ERROR_FAIL;
1944
2005
}
1945
2006
2007
+ static
2008
+ CvResult CV_API_CALL cv_writer_open (const char * filename, int fourcc, double fps, int width, int height, int isColor,
2009
+ CV_OUT CvPluginWriter* handle)
2010
+ {
2011
+ int params[2 ] = { VIDEOWRITER_PROP_IS_COLOR, isColor };
2012
+ return cv_writer_open_with_params (filename, fourcc, fps, width, height, params, 1 , handle);
2013
+ }
2014
+
1946
2015
static
1947
2016
CvResult CV_API_CALL cv_writer_release (CvPluginWriter handle)
1948
2017
{
@@ -1975,7 +2044,7 @@ CvResult CV_API_CALL cv_writer_write(CvPluginWriter handle, const unsigned char
1975
2044
CvVideoWriter_GStreamer* instance = (CvVideoWriter_GStreamer*)handle;
1976
2045
CvSize sz = { width, height };
1977
2046
IplImage img;
1978
- cvInitImageHeader (&img, sz, IPL_DEPTH_8U , cn);
2047
+ cvInitImageHeader (&img, sz, instance-> getIplDepth () , cn);
1979
2048
cvSetData (&img, const_cast <unsigned char *>(data), step);
1980
2049
return instance->writeFrame (&img) ? CV_ERROR_OK : CV_ERROR_FAIL;
1981
2050
}
@@ -2003,7 +2072,8 @@ static const OpenCV_VideoIO_Plugin_API_preview plugin_api_v0 =
2003
2072
/* 9*/ cv_writer_release,
2004
2073
/* 10*/ cv_writer_get_prop,
2005
2074
/* 11*/ cv_writer_set_prop,
2006
- /* 12*/ cv_writer_write
2075
+ /* 12*/ cv_writer_write,
2076
+ /* 13*/ cv_writer_open_with_params
2007
2077
};
2008
2078
2009
2079
} // namespace
@@ -2012,7 +2082,7 @@ const OpenCV_VideoIO_Plugin_API_preview* opencv_videoio_plugin_init_v0(int reque
2012
2082
{
2013
2083
if (requested_abi_version != 0 )
2014
2084
return NULL ;
2015
- if (requested_api_version != 0 )
2085
+ if (requested_api_version != 0 && requested_api_version != 1 )
2016
2086
return NULL ;
2017
2087
return &cv::plugin_api_v0;
2018
2088
}
0 commit comments