1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-17 15:26:00 +08:00

Two factory methods.

This commit is contained in:
James Bowley
2022-10-14 18:23:36 +03:00
parent 4fa9c71169
commit fbd6827e71
4 changed files with 18 additions and 59 deletions

View File

@@ -231,10 +231,11 @@ public:
@param codec Codec.
@param fps Framerate of the created video stream.
@param colorFormat OpenCv color format of the frames to be encoded.
@param encoderCallback Callbacks for video encoder. See cudacodec::EncoderCallback. Required for working with the encoded video stream.
@param stream Stream for frame pre-processing.
*/
CV_EXPORTS_W Ptr<cudacodec::VideoWriter> createVideoWriter(const String& fileName, const Size frameSize, const CODEC_VW codec = CODEC_VW::H264,
const double fps = 25.0, const COLOR_FORMAT_VW colorFormat = BGR, const Stream& stream = Stream::Null());
CV_EXPORTS_W Ptr<cudacodec::VideoWriter> createVideoWriter(const String& fileName, const Size frameSize, const CODEC_VW codec = CODEC_VW::H264, const double fps = 25.0,
const COLOR_FORMAT_VW colorFormat = BGR, Ptr<EncoderCallback> encoderCallback = 0, const Stream& stream = Stream::Null());
/** @brief Creates video writer.
@@ -244,39 +245,11 @@ CV_EXPORTS_W Ptr<cudacodec::VideoWriter> createVideoWriter(const String& fileNam
@param fps Framerate of the created video stream.
@param colorFormat OpenCv color format of the frames to be encoded.
@param params Additional encoding parameters.
@param encoderCallback Callbacks for video encoder. See cudacodec::EncoderCallback. Required for working with the encoded video stream.
@param stream Stream for frame pre-processing.
*/
CV_EXPORTS_W Ptr<cudacodec::VideoWriter> createVideoWriter(const String& fileName, const Size frameSize, const CODEC_VW codec,
const double fps, const COLOR_FORMAT_VW colorFormat, const EncoderParams& params, const Stream& stream = Stream::Null());
/** @brief Creates video writer.
@param encoderCallback Callbacks for video encoder. See cudacodec::EncoderCallback . Use it if you want to work with the raw video stream.
@param frameSize Size of the input video frames.
@param codec Codec.
@param fps Framerate of the created video stream.
@param colorFormat OpenCv color format of the frames to be encoded.
@param stream Stream for frame pre-processing.
The constructors initialize video writer. User can implement their own multiplexing with cudacodec::EncoderCallback.
*/
CV_EXPORTS_W Ptr<cudacodec::VideoWriter> createVideoWriter(const Ptr<EncoderCallback>& encoderCallback, const Size frameSize, const CODEC_VW codec = CODEC_VW::H264,
const double fps = 25.0, const COLOR_FORMAT_VW colorFormat = BGR, const Stream& stream = Stream::Null());
/** @brief Creates video writer.
@param encoderCallback Callbacks for video encoder. See cudacodec::EncoderCallback . Use it if you want to work with the raw video stream.
@param frameSize Size of the input video frames.
@param codec Codec.
@param fps Framerate of the created video stream.
@param colorFormat OpenCv color format of the frames to be encoded.
@param params Additional encoding parameters.
@param stream Stream for frame pre-processing.
The constructors initialize video writer. User can implement their own multiplexing with cudacodec::EncoderCallback.
*/
CV_EXPORTS_W Ptr<cudacodec::VideoWriter> createVideoWriter(const Ptr<EncoderCallback>& encoderCallback, const Size frameSize, const CODEC_VW codec,
const double fps, const COLOR_FORMAT_VW colorFormat, const EncoderParams& params, const Stream& stream = Stream::Null());
CV_EXPORTS_W Ptr<cudacodec::VideoWriter> createVideoWriter(const String& fileName, const Size frameSize, const CODEC_VW codec, const double fps, const COLOR_FORMAT_VW colorFormat,
const EncoderParams& params, Ptr<EncoderCallback> encoderCallback = 0, const Stream& stream = Stream::Null());
////////////////////////////////// Video Decoding //////////////////////////////////////////

View File

@@ -147,7 +147,7 @@ PERF_TEST_P(WriteToFile, VideoWriter, Combine(VIDEO_SRC, COLOR_FORMAT, CODEC))
frames.push_back(frame);
}
stream.waitForCompletion();
cv::Ptr<cv::cudacodec::VideoWriter> d_writer = cv::cudacodec::createVideoWriter(outputFile, frameBgr.size(), codec, fps, surfaceFormat, stream);
cv::Ptr<cv::cudacodec::VideoWriter> d_writer = cv::cudacodec::createVideoWriter(outputFile, frameBgr.size(), codec, fps, surfaceFormat, 0, stream);
for (int i = 0; i < nFrames - 1; ++i) {
startTimer();
d_writer->write(frames[i]);

View File

@@ -48,10 +48,8 @@ using namespace cv::cuda;
#if !defined(HAVE_NVCUVENC)
Ptr<cudacodec::VideoWriter> createVideoWriter(const String&, const Size, const CODEC_VW, const double, const COLOR_FORMAT_VW, const cv::cuda::Stream&) { throw_no_cuda(); return Ptr<cv::cudacodec::VideoWriter>(); }
Ptr<cudacodec::VideoWriter> createVideoWriter(const String&, const Size, const CODEC_VW, const double, const COLOR_FORMAT_VW, const EncoderParams&, const cv::cuda::Stream&) { throw_no_cuda(); return Ptr<cv::cudacodec::VideoWriter>(); }
Ptr<cudacodec::VideoWriter> createVideoWriter(const Ptr<EncoderCallback>&, const Size, const CODEC_VW codec, const double, const COLOR_FORMAT_VW, const cv::cuda::Stream&) { throw_no_cuda(); return Ptr<cv::cudacodec::VideoWriter>(); }
Ptr<cudacodec::VideoWriter> createVideoWriter(const Ptr<EncoderCallback>&, const Size, const CODEC_VW, const double, const COLOR_FORMAT_VW, const EncoderParams&, const cv::cuda::Stream&) { throw_no_cuda(); return Ptr<cv::cudacodec::VideoWriter>(); }
Ptr<cudacodec::VideoWriter> createVideoWriter(const String&, const Size, const CODEC_VW, const double, const COLOR_FORMAT_VW, const Ptr<EncoderCallback>, const cv::cuda::Stream&) { throw_no_cuda(); return Ptr<cv::cudacodec::VideoWriter>(); }
Ptr<cudacodec::VideoWriter> createVideoWriter(const String&, const Size, const CODEC_VW, const double, const COLOR_FORMAT_VW, const EncoderParams&, const Ptr<EncoderCallback>, const cv::cuda::Stream&) { throw_no_cuda(); return Ptr<cv::cudacodec::VideoWriter>(); }
#else // !defined HAVE_NVCUVENC
@@ -376,29 +374,17 @@ EncoderParams VideoWriterImpl::getEncoderParams() const {
return encoderParams;
};
Ptr<VideoWriter> createVideoWriter(const String& fileName, const Size frameSize, const CODEC_VW codec, const double fps,
const COLOR_FORMAT_VW colorFormat, const Stream& stream)
{
Ptr<EncoderCallback> rawVideoWriter = new RawVideoWriter(fileName);
return createVideoWriter(rawVideoWriter, frameSize, codec, fps, colorFormat, stream);
}
Ptr<VideoWriter> createVideoWriter(const String& fileName, const Size frameSize, const CODEC_VW codec, const double fps,
const COLOR_FORMAT_VW colorFormat, const EncoderParams& params, const Stream& stream)
{
Ptr<EncoderCallback> rawVideoWriter = new RawVideoWriter(fileName);
return createVideoWriter(rawVideoWriter, frameSize, codec, fps, colorFormat, params, stream);
}
Ptr<VideoWriter> createVideoWriter(const Ptr<EncoderCallback>& encoderCallback, const Size frameSize, const CODEC_VW codec, const double fps,
const COLOR_FORMAT_VW colorFormat, const Stream& stream)
Ptr<VideoWriter> createVideoWriter(const String& fileName, const Size frameSize, const CODEC_VW codec, const double fps, const COLOR_FORMAT_VW colorFormat,
Ptr<EncoderCallback> encoderCallback, const Stream& stream)
{
encoderCallback = encoderCallback ? encoderCallback : new RawVideoWriter(fileName);
return makePtr<VideoWriterImpl>(encoderCallback, frameSize, codec, fps, colorFormat, stream);
}
Ptr<VideoWriter> createVideoWriter(const Ptr<EncoderCallback>& encoderCallback, const Size frameSize, const CODEC_VW codec, const double fps,
const COLOR_FORMAT_VW colorFormat, const EncoderParams& params, const Stream& stream)
Ptr<VideoWriter> createVideoWriter(const String& fileName, const Size frameSize, const CODEC_VW codec, const double fps, const COLOR_FORMAT_VW colorFormat,
const EncoderParams& params, Ptr<EncoderCallback> encoderCallback, const Stream& stream)
{
encoderCallback = encoderCallback ? encoderCallback : new RawVideoWriter(fileName);
return makePtr<VideoWriterImpl>(encoderCallback, frameSize, codec, fps, colorFormat, params, stream);
}

View File

@@ -463,7 +463,7 @@ CUDA_TEST_P(TransCode, H264ToH265)
Mat tst; frame.download(tst);
if (writer.empty()) {
frameSz = Size(fmt.width, fmt.height);
writer = cv::cudacodec::createVideoWriter(outputFile, frameSz, codec, fps, colorFormat, stream);
writer = cv::cudacodec::createVideoWriter(outputFile, frameSz, codec, fps, colorFormat, 0, stream);
}
writer->write(frame);
}
@@ -537,7 +537,7 @@ CUDA_TEST_P(Write, Writer)
ASSERT_FALSE(frame.empty());
if (writer.empty()) {
frameSz = frame.size();
writer = cv::cudacodec::createVideoWriter(outputFile, frameSz, codec, fps, colorFormat, stream);
writer = cv::cudacodec::createVideoWriter(outputFile, frameSz, codec, fps, colorFormat, 0, stream);
}
CvtColor(frame, frameNewSf, colorFormat);
if (deviceSrc) {
@@ -618,7 +618,7 @@ CUDA_TEST_P(EncoderParams, Writer)
dFrame.upload(frame);
if (writer.empty()) {
frameSz = frame.size();
writer = cv::cudacodec::createVideoWriter(outputFile, frameSz, codec, fps, colorFormat, params, stream);
writer = cv::cudacodec::createVideoWriter(outputFile, frameSz, codec, fps, colorFormat, params, 0, stream);
cv::cudacodec::EncoderParams paramsOut = writer->getEncoderParams();
ASSERT_EQ(params, paramsOut);
}