mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 22:00:25 +08:00
Merge pull request #3876 from vpisarev:mjpeg_codec
This commit is contained in:
commit
fa9c9e791b
@ -27,6 +27,8 @@ set(videoio_hdrs
|
||||
set(videoio_srcs
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/cap.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/cap_images.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/cap_mjpeg_encoder.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/cap_mjpeg_decoder.cpp
|
||||
)
|
||||
|
||||
file(GLOB videoio_ext_hdrs
|
||||
|
@ -376,6 +376,9 @@ enum { CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integ
|
||||
CAP_INTELPERC_IMAGE = 3
|
||||
};
|
||||
|
||||
enum { VIDEOWRITER_PROP_QUALITY = 1, // Quality (0..100%) of the videostream encoded
|
||||
VIDEOWRITER_PROP_FRAMEBYTES = 2, // (Read-only): Size of just encoded video frame
|
||||
};
|
||||
|
||||
class IVideoCapture;
|
||||
|
||||
@ -586,10 +589,10 @@ public:
|
||||
protected:
|
||||
Ptr<CvCapture> cap;
|
||||
Ptr<IVideoCapture> icap;
|
||||
private:
|
||||
static Ptr<IVideoCapture> createCameraCapture(int index);
|
||||
};
|
||||
|
||||
class IVideoWriter;
|
||||
|
||||
/** @brief Video writer class.
|
||||
*/
|
||||
class CV_EXPORTS_W VideoWriter
|
||||
@ -642,6 +645,25 @@ public:
|
||||
*/
|
||||
CV_WRAP virtual void write(const Mat& image);
|
||||
|
||||
/** @brief Sets a property in the VideoWriter.
|
||||
|
||||
@param propId Property identifier. It can be one of the following:
|
||||
- **VIDEOWRITER_PROP_QUALITY** Quality (0..100%) of the videostream encoded. Can be adjusted dynamically in some codecs.
|
||||
@param value Value of the property.
|
||||
*/
|
||||
CV_WRAP virtual bool set(int propId, double value);
|
||||
|
||||
/** @brief Returns the specified VideoWriter property
|
||||
|
||||
@param propId Property identifier. It can be one of the following:
|
||||
- **VIDEOWRITER_PROP_QUALITY** Current quality of the encoded videostream.
|
||||
- **VIDEOWRITER_PROP_FRAMEBYTES** (Read-only) Size of just encoded video frame; note that the encoding order may be different from representation order.
|
||||
|
||||
**Note**: When querying a property that is not supported by the backend used by the VideoWriter
|
||||
class, value 0 is returned.
|
||||
*/
|
||||
CV_WRAP virtual double get(int propId) const;
|
||||
|
||||
/** @brief Concatenates 4 chars to a fourcc code
|
||||
|
||||
This static method constructs the fourcc code of the codec to be used in the constructor
|
||||
@ -651,6 +673,10 @@ public:
|
||||
|
||||
protected:
|
||||
Ptr<CvVideoWriter> writer;
|
||||
Ptr<IVideoWriter> iwriter;
|
||||
|
||||
static Ptr<IVideoWriter> create(const String& filename, int fourcc, double fps,
|
||||
Size frameSize, bool isColor = true);
|
||||
};
|
||||
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const;
|
||||
|
@ -499,6 +499,67 @@ CV_IMPL void cvReleaseVideoWriter( CvVideoWriter** pwriter )
|
||||
namespace cv
|
||||
{
|
||||
|
||||
static Ptr<IVideoCapture> IVideoCapture_create(int index)
|
||||
{
|
||||
int domains[] =
|
||||
{
|
||||
#ifdef HAVE_DSHOW
|
||||
CV_CAP_DSHOW,
|
||||
#endif
|
||||
#ifdef HAVE_INTELPERC
|
||||
CV_CAP_INTELPERC,
|
||||
#endif
|
||||
-1, -1
|
||||
};
|
||||
|
||||
// interpret preferred interface (0 = autodetect)
|
||||
int pref = (index / 100) * 100;
|
||||
if (pref)
|
||||
{
|
||||
domains[0]=pref;
|
||||
index %= 100;
|
||||
domains[1]=-1;
|
||||
}
|
||||
|
||||
// try every possibly installed camera API
|
||||
for (int i = 0; domains[i] >= 0; i++)
|
||||
{
|
||||
#if defined(HAVE_DSHOW) || \
|
||||
defined(HAVE_INTELPERC) || \
|
||||
(0)
|
||||
Ptr<IVideoCapture> capture;
|
||||
|
||||
switch (domains[i])
|
||||
{
|
||||
#ifdef HAVE_DSHOW
|
||||
case CV_CAP_DSHOW:
|
||||
capture = makePtr<VideoCapture_DShow>(index);
|
||||
break; // CV_CAP_DSHOW
|
||||
#endif
|
||||
#ifdef HAVE_INTELPERC
|
||||
case CV_CAP_INTELPERC:
|
||||
capture = makePtr<VideoCapture_IntelPerC>();
|
||||
break; // CV_CAP_INTEL_PERC
|
||||
#endif
|
||||
}
|
||||
if (capture && capture->isOpened())
|
||||
return capture;
|
||||
#endif
|
||||
}
|
||||
|
||||
// failed open a camera
|
||||
return Ptr<IVideoCapture>();
|
||||
}
|
||||
|
||||
|
||||
static Ptr<IVideoWriter> IVideoWriter_create(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
|
||||
{
|
||||
Ptr<IVideoWriter> iwriter;
|
||||
if( _fourcc == CV_FOURCC('M', 'J', 'P', 'G') )
|
||||
iwriter = createMotionJpegWriter(filename, fps, frameSize, isColor);
|
||||
return iwriter;
|
||||
}
|
||||
|
||||
VideoCapture::VideoCapture()
|
||||
{}
|
||||
|
||||
@ -528,7 +589,7 @@ bool VideoCapture::open(const String& filename)
|
||||
bool VideoCapture::open(int device)
|
||||
{
|
||||
if (isOpened()) release();
|
||||
icap = createCameraCapture(device);
|
||||
icap = IVideoCapture_create(device);
|
||||
if (!icap.empty())
|
||||
return true;
|
||||
cap.reset(cvCreateCameraCapture(device));
|
||||
@ -609,59 +670,6 @@ double VideoCapture::get(int propId) const
|
||||
return icvGetCaptureProperty(cap, propId);
|
||||
}
|
||||
|
||||
Ptr<IVideoCapture> VideoCapture::createCameraCapture(int index)
|
||||
{
|
||||
int domains[] =
|
||||
{
|
||||
#ifdef HAVE_DSHOW
|
||||
CV_CAP_DSHOW,
|
||||
#endif
|
||||
#ifdef HAVE_INTELPERC
|
||||
CV_CAP_INTELPERC,
|
||||
#endif
|
||||
-1, -1
|
||||
};
|
||||
|
||||
// interpret preferred interface (0 = autodetect)
|
||||
int pref = (index / 100) * 100;
|
||||
if (pref)
|
||||
{
|
||||
domains[0]=pref;
|
||||
index %= 100;
|
||||
domains[1]=-1;
|
||||
}
|
||||
|
||||
// try every possibly installed camera API
|
||||
for (int i = 0; domains[i] >= 0; i++)
|
||||
{
|
||||
#if defined(HAVE_DSHOW) || \
|
||||
defined(HAVE_INTELPERC) || \
|
||||
(0)
|
||||
Ptr<IVideoCapture> capture;
|
||||
|
||||
switch (domains[i])
|
||||
{
|
||||
#ifdef HAVE_DSHOW
|
||||
case CV_CAP_DSHOW:
|
||||
capture = makePtr<VideoCapture_DShow>(index);
|
||||
if (capture && capture.dynamicCast<VideoCapture_DShow>()->isOpened())
|
||||
return capture;
|
||||
break; // CV_CAP_DSHOW
|
||||
#endif
|
||||
#ifdef HAVE_INTELPERC
|
||||
case CV_CAP_INTELPERC:
|
||||
capture = makePtr<VideoCapture_IntelPerC>();
|
||||
if (capture && capture.dynamicCast<VideoCapture_IntelPerC>()->isOpened())
|
||||
return capture;
|
||||
break; // CV_CAP_INTEL_PERC
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// failed open a camera
|
||||
return Ptr<IVideoCapture>();
|
||||
}
|
||||
|
||||
VideoWriter::VideoWriter()
|
||||
{}
|
||||
@ -673,6 +681,7 @@ VideoWriter::VideoWriter(const String& filename, int _fourcc, double fps, Size f
|
||||
|
||||
void VideoWriter::release()
|
||||
{
|
||||
iwriter.release();
|
||||
writer.release();
|
||||
}
|
||||
|
||||
@ -683,19 +692,43 @@ VideoWriter::~VideoWriter()
|
||||
|
||||
bool VideoWriter::open(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
|
||||
{
|
||||
if (isOpened()) release();
|
||||
iwriter = IVideoWriter_create(filename, _fourcc, fps, frameSize, isColor);
|
||||
if (!iwriter.empty())
|
||||
return true;
|
||||
writer.reset(cvCreateVideoWriter(filename.c_str(), _fourcc, fps, frameSize, isColor));
|
||||
return isOpened();
|
||||
}
|
||||
|
||||
bool VideoWriter::isOpened() const
|
||||
{
|
||||
return !writer.empty();
|
||||
return !iwriter.empty() || !writer.empty();
|
||||
}
|
||||
|
||||
|
||||
bool VideoWriter::set(int propId, double value)
|
||||
{
|
||||
if (!iwriter.empty())
|
||||
return iwriter->setProperty(propId, value);
|
||||
return false;
|
||||
}
|
||||
|
||||
double VideoWriter::get(int propId) const
|
||||
{
|
||||
if (!iwriter.empty())
|
||||
return iwriter->getProperty(propId);
|
||||
return 0.;
|
||||
}
|
||||
|
||||
void VideoWriter::write(const Mat& image)
|
||||
{
|
||||
IplImage _img = image;
|
||||
cvWriteFrame(writer, &_img);
|
||||
if( iwriter )
|
||||
iwriter->write(image);
|
||||
else
|
||||
{
|
||||
IplImage _img = image;
|
||||
cvWriteFrame(writer, &_img);
|
||||
}
|
||||
}
|
||||
|
||||
VideoWriter& VideoWriter::operator << (const Mat& image)
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
virtual bool grabFrame();
|
||||
virtual bool retrieveFrame(int outputType, OutputArray frame);
|
||||
virtual int getCaptureDomain();
|
||||
bool isOpened() const;
|
||||
virtual bool isOpened() const;
|
||||
protected:
|
||||
void open(int index);
|
||||
void close();
|
||||
|
@ -100,7 +100,7 @@ public:
|
||||
virtual bool grabFrame();
|
||||
virtual bool retrieveFrame(int outputType, OutputArray frame);
|
||||
virtual int getCaptureDomain();
|
||||
bool isOpened() const;
|
||||
virtual bool isOpened() const;
|
||||
protected:
|
||||
bool m_contextOpened;
|
||||
|
||||
|
52
modules/videoio/src/cap_mjpeg_decoder.cpp
Normal file
52
modules/videoio/src/cap_mjpeg_decoder.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2015, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
Ptr<IVideoCapture> createMotionJpegCapture(const String&)
|
||||
{
|
||||
return Ptr<IVideoCapture>();
|
||||
}
|
||||
|
||||
}
|
1464
modules/videoio/src/cap_mjpeg_encoder.cpp
Normal file
1464
modules/videoio/src/cap_mjpeg_encoder.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -166,11 +166,26 @@ namespace cv
|
||||
public:
|
||||
virtual ~IVideoCapture() {}
|
||||
virtual double getProperty(int) const { return 0; }
|
||||
virtual bool setProperty(int, double) { return 0; }
|
||||
virtual bool setProperty(int, double) { return false; }
|
||||
virtual bool grabFrame() = 0;
|
||||
virtual bool retrieveFrame(int, cv::OutputArray) = 0;
|
||||
virtual bool retrieveFrame(int, OutputArray) = 0;
|
||||
virtual bool isOpened() const = 0;
|
||||
virtual int getCaptureDomain() { return CAP_ANY; } // Return the type of the capture object: CAP_VFW, etc...
|
||||
};
|
||||
|
||||
class IVideoWriter
|
||||
{
|
||||
public:
|
||||
virtual ~IVideoWriter() {}
|
||||
virtual double getProperty(int) const { return 0; }
|
||||
virtual bool setProperty(int, double) { return false; }
|
||||
|
||||
virtual bool isOpened() const = 0;
|
||||
virtual void write(InputArray) = 0;
|
||||
};
|
||||
|
||||
Ptr<IVideoCapture> createMotionJpegCapture(const String& filename);
|
||||
Ptr<IVideoWriter> createMotionJpegWriter( const String& filename, double fps, Size frameSize, bool iscolor );
|
||||
};
|
||||
|
||||
#endif /* __VIDEOIO_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user