#include "opencv2/core/gpu.hpp"
-namespace cv { namespace gpucodec {
+namespace cv { namespace cudacodec {
////////////////////////////////// Video Encoding //////////////////////////////////
CV_EXPORTS Ptr<VideoReader> createVideoReader(const String& filename);
CV_EXPORTS Ptr<VideoReader> createVideoReader(const Ptr<RawVideoSource>& source);
-}} // namespace cv { namespace gpucodec {
+}} // namespace cv { namespace cudacodec {
#endif /* __OPENCV_GPUCODEC_HPP__ */
if (PERF_RUN_GPU())
{
- cv::Ptr<cv::gpucodec::VideoReader> d_reader = cv::gpucodec::createVideoReader(inputFile);
+ cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(inputFile);
cv::cuda::GpuMat frame;
if (PERF_RUN_GPU())
{
- cv::Ptr<cv::gpucodec::VideoWriter> d_writer;
+ cv::Ptr<cv::cudacodec::VideoWriter> d_writer;
cv::cuda::GpuMat d_frame;
d_frame.upload(frame);
if (d_writer.empty())
- d_writer = cv::gpucodec::createVideoWriter(outputFile, frame.size(), FPS);
+ d_writer = cv::cudacodec::createVideoWriter(outputFile, frame.size(), FPS);
startTimer(); next();
d_writer->write(d_frame);
#ifdef HAVE_NVCUVID
using namespace cv;
-using namespace cv::gpucodec;
-using namespace cv::gpucodec::detail;
+using namespace cv::cudacodec;
+using namespace cv::cudacodec::detail;
-cv::gpucodec::detail::CuvidVideoSource::CuvidVideoSource(const String& fname)
+cv::cudacodec::detail::CuvidVideoSource::CuvidVideoSource(const String& fname)
{
CUVIDSOURCEPARAMS params;
std::memset(¶ms, 0, sizeof(CUVIDSOURCEPARAMS));
format_.height = vidfmt.coded_height;
}
-cv::gpucodec::detail::CuvidVideoSource::~CuvidVideoSource()
+cv::cudacodec::detail::CuvidVideoSource::~CuvidVideoSource()
{
cuvidDestroyVideoSource(videoSource_);
}
-FormatInfo cv::gpucodec::detail::CuvidVideoSource::format() const
+FormatInfo cv::cudacodec::detail::CuvidVideoSource::format() const
{
return format_;
}
-void cv::gpucodec::detail::CuvidVideoSource::start()
+void cv::cudacodec::detail::CuvidVideoSource::start()
{
cuSafeCall( cuvidSetVideoSourceState(videoSource_, cudaVideoState_Started) );
}
-void cv::gpucodec::detail::CuvidVideoSource::stop()
+void cv::cudacodec::detail::CuvidVideoSource::stop()
{
cuSafeCall( cuvidSetVideoSourceState(videoSource_, cudaVideoState_Stopped) );
}
-bool cv::gpucodec::detail::CuvidVideoSource::isStarted() const
+bool cv::cudacodec::detail::CuvidVideoSource::isStarted() const
{
return (cuvidGetVideoSourceState(videoSource_) == cudaVideoState_Started);
}
-bool cv::gpucodec::detail::CuvidVideoSource::hasError() const
+bool cv::cudacodec::detail::CuvidVideoSource::hasError() const
{
return (cuvidGetVideoSourceState(videoSource_) == cudaVideoState_Error);
}
-int CUDAAPI cv::gpucodec::detail::CuvidVideoSource::HandleVideoData(void* userData, CUVIDSOURCEDATAPACKET* packet)
+int CUDAAPI cv::cudacodec::detail::CuvidVideoSource::HandleVideoData(void* userData, CUVIDSOURCEDATAPACKET* packet)
{
CuvidVideoSource* thiz = static_cast<CuvidVideoSource*>(userData);
#include "opencv2/gpucodec.hpp"
#include "video_source.hpp"
-namespace cv { namespace gpucodec { namespace detail
+namespace cv { namespace cudacodec { namespace detail
{
class CuvidVideoSource : public VideoSource
#ifdef HAVE_NVCUVID
using namespace cv;
-using namespace cv::gpucodec;
-using namespace cv::gpucodec::detail;
+using namespace cv::cudacodec;
+using namespace cv::cudacodec::detail;
namespace
{
}
}
-cv::gpucodec::detail::FFmpegVideoSource::FFmpegVideoSource(const String& fname) :
+cv::cudacodec::detail::FFmpegVideoSource::FFmpegVideoSource(const String& fname) :
stream_(0)
{
CV_Assert( init_MediaStream_FFMPEG() );
format_.height = height;
}
-cv::gpucodec::detail::FFmpegVideoSource::~FFmpegVideoSource()
+cv::cudacodec::detail::FFmpegVideoSource::~FFmpegVideoSource()
{
if (stream_)
release_InputMediaStream_FFMPEG_p(stream_);
}
-FormatInfo cv::gpucodec::detail::FFmpegVideoSource::format() const
+FormatInfo cv::cudacodec::detail::FFmpegVideoSource::format() const
{
return format_;
}
-bool cv::gpucodec::detail::FFmpegVideoSource::getNextPacket(unsigned char** data, int* size, bool* bEndOfFile)
+bool cv::cudacodec::detail::FFmpegVideoSource::getNextPacket(unsigned char** data, int* size, bool* bEndOfFile)
{
int endOfFile;
struct InputMediaStream_FFMPEG;
-namespace cv { namespace gpucodec { namespace detail {
+namespace cv { namespace cudacodec { namespace detail {
class FFmpegVideoSource : public RawVideoSource
{
#ifdef HAVE_NVCUVID
-cv::gpucodec::detail::FrameQueue::FrameQueue() :
+cv::cudacodec::detail::FrameQueue::FrameQueue() :
endOfDecode_(0),
framesInQueue_(0),
readPosition_(0)
std::memset((void*) isFrameInUse_, 0, sizeof(isFrameInUse_));
}
-bool cv::gpucodec::detail::FrameQueue::waitUntilFrameAvailable(int pictureIndex)
+bool cv::cudacodec::detail::FrameQueue::waitUntilFrameAvailable(int pictureIndex)
{
while (isInUse(pictureIndex))
{
return true;
}
-void cv::gpucodec::detail::FrameQueue::enqueue(const CUVIDPARSERDISPINFO* picParams)
+void cv::cudacodec::detail::FrameQueue::enqueue(const CUVIDPARSERDISPINFO* picParams)
{
// Mark the frame as 'in-use' so we don't re-use it for decoding until it is no longer needed
// for display
} while (!isEndOfDecode());
}
-bool cv::gpucodec::detail::FrameQueue::dequeue(CUVIDPARSERDISPINFO& displayInfo)
+bool cv::cudacodec::detail::FrameQueue::dequeue(CUVIDPARSERDISPINFO& displayInfo)
{
AutoLock autoLock(mtx_);
#include <nvcuvid.h>
-namespace cv { namespace gpucodec { namespace detail
+namespace cv { namespace cudacodec { namespace detail
{
class FrameQueue
#ifdef HAVE_NVCUVID
-using namespace cv::gpucodec::detail;
+using namespace cv::cudacodec::detail;
#ifdef WIN32
}
}
-class cv::gpucodec::detail::Thread::Impl
+class cv::cudacodec::detail::Thread::Impl
{
public:
Impl(Thread::Func func, void* userData)
}
}
-class cv::gpucodec::detail::Thread::Impl
+class cv::cudacodec::detail::Thread::Impl
{
public:
Impl(Thread::Func func, void* userData)
#endif
-cv::gpucodec::detail::Thread::Thread(Func func, void* userData) :
+cv::cudacodec::detail::Thread::Thread(Func func, void* userData) :
impl_(new Impl(func, userData))
{
}
-void cv::gpucodec::detail::Thread::wait()
+void cv::cudacodec::detail::Thread::wait()
{
impl_->wait();
}
-void cv::gpucodec::detail::Thread::sleep(int ms)
+void cv::cudacodec::detail::Thread::sleep(int ms)
{
#ifdef WIN32
::Sleep(ms);
#endif
}
-template <> void cv::Ptr<cv::gpucodec::detail::Thread::Impl>::delete_obj()
+template <> void cv::Ptr<cv::cudacodec::detail::Thread::Impl>::delete_obj()
{
if (obj) delete obj;
}
#include "opencv2/core.hpp"
-namespace cv { namespace gpucodec { namespace detail {
+namespace cv { namespace cudacodec { namespace detail {
class Thread
{
}}}
namespace cv {
- template <> void Ptr<cv::gpucodec::detail::Thread::Impl>::delete_obj();
+ template <> void Ptr<cv::cudacodec::detail::Thread::Impl>::delete_obj();
}
#endif // __THREAD_WRAPPERS_HPP__
#ifdef HAVE_NVCUVID
-void cv::gpucodec::detail::VideoDecoder::create(const FormatInfo& videoFormat)
+void cv::cudacodec::detail::VideoDecoder::create(const FormatInfo& videoFormat)
{
release();
cuSafeCall( cuvidCreateDecoder(&decoder_, &createInfo_) );
}
-void cv::gpucodec::detail::VideoDecoder::release()
+void cv::cudacodec::detail::VideoDecoder::release()
{
if (decoder_)
{
#include "opencv2/core/private.gpu.hpp"
#include "opencv2/gpucodec.hpp"
-namespace cv { namespace gpucodec { namespace detail
+namespace cv { namespace cudacodec { namespace detail
{
class VideoDecoder
#ifdef HAVE_NVCUVID
-cv::gpucodec::detail::VideoParser::VideoParser(VideoDecoder* videoDecoder, FrameQueue* frameQueue) :
+cv::cudacodec::detail::VideoParser::VideoParser(VideoDecoder* videoDecoder, FrameQueue* frameQueue) :
videoDecoder_(videoDecoder), frameQueue_(frameQueue), unparsedPackets_(0), hasError_(false)
{
CUVIDPARSERPARAMS params;
cuSafeCall( cuvidCreateVideoParser(&parser_, ¶ms) );
}
-bool cv::gpucodec::detail::VideoParser::parseVideoData(const unsigned char* data, size_t size, bool endOfStream)
+bool cv::cudacodec::detail::VideoParser::parseVideoData(const unsigned char* data, size_t size, bool endOfStream)
{
CUVIDSOURCEDATAPACKET packet;
std::memset(&packet, 0, sizeof(CUVIDSOURCEDATAPACKET));
return !frameQueue_->isEndOfDecode();
}
-int CUDAAPI cv::gpucodec::detail::VideoParser::HandleVideoSequence(void* userData, CUVIDEOFORMAT* format)
+int CUDAAPI cv::cudacodec::detail::VideoParser::HandleVideoSequence(void* userData, CUVIDEOFORMAT* format)
{
VideoParser* thiz = static_cast<VideoParser*>(userData);
return true;
}
-int CUDAAPI cv::gpucodec::detail::VideoParser::HandlePictureDecode(void* userData, CUVIDPICPARAMS* picParams)
+int CUDAAPI cv::cudacodec::detail::VideoParser::HandlePictureDecode(void* userData, CUVIDPICPARAMS* picParams)
{
VideoParser* thiz = static_cast<VideoParser*>(userData);
return true;
}
-int CUDAAPI cv::gpucodec::detail::VideoParser::HandlePictureDisplay(void* userData, CUVIDPARSERDISPINFO* picParams)
+int CUDAAPI cv::cudacodec::detail::VideoParser::HandlePictureDisplay(void* userData, CUVIDPARSERDISPINFO* picParams)
{
VideoParser* thiz = static_cast<VideoParser*>(userData);
#include "frame_queue.hpp"
#include "video_decoder.hpp"
-namespace cv { namespace gpucodec { namespace detail
+namespace cv { namespace cudacodec { namespace detail
{
class VideoParser
using namespace cv;
using namespace cv::cuda;
-using namespace cv::gpucodec;
+using namespace cv::cudacodec;
#ifndef HAVE_NVCUVID
-Ptr<VideoReader> cv::gpucodec::createVideoReader(const String&) { throw_no_cuda(); return Ptr<VideoReader>(); }
-Ptr<VideoReader> cv::gpucodec::createVideoReader(const Ptr<RawVideoSource>&) { throw_no_cuda(); return Ptr<VideoReader>(); }
+Ptr<VideoReader> cv::cudacodec::createVideoReader(const String&) { throw_no_cuda(); return Ptr<VideoReader>(); }
+Ptr<VideoReader> cv::cudacodec::createVideoReader(const Ptr<RawVideoSource>&) { throw_no_cuda(); return Ptr<VideoReader>(); }
#else // HAVE_NVCUVID
}
}
-Ptr<VideoReader> cv::gpucodec::createVideoReader(const String& filename)
+Ptr<VideoReader> cv::cudacodec::createVideoReader(const String& filename)
{
CV_Assert( !filename.empty() );
return new VideoReaderImpl(videoSource);
}
-Ptr<VideoReader> cv::gpucodec::createVideoReader(const Ptr<RawVideoSource>& source)
+Ptr<VideoReader> cv::cudacodec::createVideoReader(const Ptr<RawVideoSource>& source)
{
Ptr<detail::VideoSource> videoSource(new detail::RawVideoSourceWrapper(source));
return new VideoReaderImpl(videoSource);
#ifdef HAVE_NVCUVID
using namespace cv;
-using namespace cv::gpucodec;
-using namespace cv::gpucodec::detail;
+using namespace cv::cudacodec;
+using namespace cv::cudacodec::detail;
-bool cv::gpucodec::detail::VideoSource::parseVideoData(const unsigned char* data, size_t size, bool endOfStream)
+bool cv::cudacodec::detail::VideoSource::parseVideoData(const unsigned char* data, size_t size, bool endOfStream)
{
return videoParser_->parseVideoData(data, size, endOfStream);
}
-cv::gpucodec::detail::RawVideoSourceWrapper::RawVideoSourceWrapper(const Ptr<RawVideoSource>& source) :
+cv::cudacodec::detail::RawVideoSourceWrapper::RawVideoSourceWrapper(const Ptr<RawVideoSource>& source) :
source_(source)
{
CV_Assert( !source_.empty() );
}
-cv::gpucodec::FormatInfo cv::gpucodec::detail::RawVideoSourceWrapper::format() const
+cv::cudacodec::FormatInfo cv::cudacodec::detail::RawVideoSourceWrapper::format() const
{
return source_->format();
}
-void cv::gpucodec::detail::RawVideoSourceWrapper::start()
+void cv::cudacodec::detail::RawVideoSourceWrapper::start()
{
stop_ = false;
hasError_ = false;
thread_ = new Thread(readLoop, this);
}
-void cv::gpucodec::detail::RawVideoSourceWrapper::stop()
+void cv::cudacodec::detail::RawVideoSourceWrapper::stop()
{
stop_ = true;
thread_->wait();
thread_.release();
}
-bool cv::gpucodec::detail::RawVideoSourceWrapper::isStarted() const
+bool cv::cudacodec::detail::RawVideoSourceWrapper::isStarted() const
{
return !stop_;
}
-bool cv::gpucodec::detail::RawVideoSourceWrapper::hasError() const
+bool cv::cudacodec::detail::RawVideoSourceWrapper::hasError() const
{
return hasError_;
}
-void cv::gpucodec::detail::RawVideoSourceWrapper::readLoop(void* userData)
+void cv::cudacodec::detail::RawVideoSourceWrapper::readLoop(void* userData)
{
RawVideoSourceWrapper* thiz = static_cast<RawVideoSourceWrapper*>(userData);
#include "opencv2/gpucodec.hpp"
#include "thread.hpp"
-namespace cv { namespace gpucodec { namespace detail
+namespace cv { namespace cudacodec { namespace detail
{
class VideoParser;
using namespace cv;
using namespace cv::cuda;
-using namespace cv::gpucodec;
+using namespace cv::cudacodec;
#if !defined(HAVE_NVCUVID) || !defined(WIN32)
-cv::gpucodec::EncoderParams::EncoderParams() { throw_no_cuda(); }
-cv::gpucodec::EncoderParams::EncoderParams(const String&) { throw_no_cuda(); }
-void cv::gpucodec::EncoderParams::load(const String&) { throw_no_cuda(); }
-void cv::gpucodec::EncoderParams::save(const String&) const { throw_no_cuda(); }
+cv::cudacodec::EncoderParams::EncoderParams() { throw_no_cuda(); }
+cv::cudacodec::EncoderParams::EncoderParams(const String&) { throw_no_cuda(); }
+void cv::cudacodec::EncoderParams::load(const String&) { throw_no_cuda(); }
+void cv::cudacodec::EncoderParams::save(const String&) const { throw_no_cuda(); }
-Ptr<VideoWriter> cv::gpucodec::createVideoWriter(const String&, Size, double, SurfaceFormat) { throw_no_cuda(); return Ptr<VideoWriter>(); }
-Ptr<VideoWriter> cv::gpucodec::createVideoWriter(const String&, Size, double, const EncoderParams&, SurfaceFormat) { throw_no_cuda(); return Ptr<VideoWriter>(); }
+Ptr<VideoWriter> cv::cudacodec::createVideoWriter(const String&, Size, double, SurfaceFormat) { throw_no_cuda(); return Ptr<VideoWriter>(); }
+Ptr<VideoWriter> cv::cudacodec::createVideoWriter(const String&, Size, double, const EncoderParams&, SurfaceFormat) { throw_no_cuda(); return Ptr<VideoWriter>(); }
-Ptr<VideoWriter> cv::gpucodec::createVideoWriter(const Ptr<EncoderCallBack>&, Size, double, SurfaceFormat) { throw_no_cuda(); return Ptr<VideoWriter>(); }
-Ptr<VideoWriter> cv::gpucodec::createVideoWriter(const Ptr<EncoderCallBack>&, Size, double, const EncoderParams&, SurfaceFormat) { throw_no_cuda(); return Ptr<VideoWriter>(); }
+Ptr<VideoWriter> cv::cudacodec::createVideoWriter(const Ptr<EncoderCallBack>&, Size, double, SurfaceFormat) { throw_no_cuda(); return Ptr<VideoWriter>(); }
+Ptr<VideoWriter> cv::cudacodec::createVideoWriter(const Ptr<EncoderCallBack>&, Size, double, const EncoderParams&, SurfaceFormat) { throw_no_cuda(); return Ptr<VideoWriter>(); }
#else // !defined HAVE_CUDA || !defined WIN32
///////////////////////////////////////////////////////////////////////////
// EncoderParams
-cv::gpucodec::EncoderParams::EncoderParams()
+cv::cudacodec::EncoderParams::EncoderParams()
{
P_Interval = 3;
IDR_Period = 15;
DisableSPSPPS = 0;
}
-cv::gpucodec::EncoderParams::EncoderParams(const String& configFile)
+cv::cudacodec::EncoderParams::EncoderParams(const String& configFile)
{
load(configFile);
}
-void cv::gpucodec::EncoderParams::load(const String& configFile)
+void cv::cudacodec::EncoderParams::load(const String& configFile)
{
FileStorage fs(configFile, FileStorage::READ);
CV_Assert( fs.isOpened() );
read(fs["DisableSPSPPS" ], DisableSPSPPS, 0);
}
-void cv::gpucodec::EncoderParams::save(const String& configFile) const
+void cv::cudacodec::EncoderParams::save(const String& configFile) const
{
FileStorage fs(configFile, FileStorage::WRITE);
CV_Assert( fs.isOpened() );
///////////////////////////////////////////////////////////////////////////
// createVideoWriter
-Ptr<VideoWriter> cv::gpucodec::createVideoWriter(const String& fileName, Size frameSize, double fps, SurfaceFormat format)
+Ptr<VideoWriter> cv::cudacodec::createVideoWriter(const String& fileName, Size frameSize, double fps, SurfaceFormat format)
{
Ptr<EncoderCallBack> encoderCallback(new EncoderCallBackFFMPEG(fileName, frameSize, fps));
return createVideoWriter(encoderCallback, frameSize, fps, format);
}
-Ptr<VideoWriter> cv::gpucodec::createVideoWriter(const String& fileName, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format)
+Ptr<VideoWriter> cv::cudacodec::createVideoWriter(const String& fileName, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format)
{
Ptr<EncoderCallBack> encoderCallback(new EncoderCallBackFFMPEG(fileName, frameSize, fps));
return createVideoWriter(encoderCallback, frameSize, fps, params, format);
}
-Ptr<VideoWriter> cv::gpucodec::createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, SurfaceFormat format)
+Ptr<VideoWriter> cv::cudacodec::createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, SurfaceFormat format)
{
return new VideoWriterImpl(encoderCallback, frameSize, fps, format);
}
-Ptr<VideoWriter> cv::gpucodec::createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format)
+Ptr<VideoWriter> cv::cudacodec::createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format)
{
return new VideoWriterImpl(encoderCallback, frameSize, fps, params, format);
}
const std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
- cv::Ptr<cv::gpucodec::VideoReader> reader = cv::gpucodec::createVideoReader(inputFile);
+ cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile);
cv::cuda::GpuMat frame;
cv::VideoCapture reader(inputFile);
ASSERT_TRUE(reader.isOpened());
- cv::Ptr<cv::gpucodec::VideoWriter> d_writer;
+ cv::Ptr<cv::cudacodec::VideoWriter> d_writer;
cv::Mat frame;
cv::cuda::GpuMat d_frame;
d_frame.upload(frame);
if (d_writer.empty())
- d_writer = cv::gpucodec::createVideoWriter(outputFile, frame.size(), FPS);
+ d_writer = cv::cudacodec::createVideoWriter(outputFile, frame.size(), FPS);
d_writer->write(d_frame);
}
private:
String fileName_;
- Ptr<gpucodec::VideoReader> reader_;
+ Ptr<cudacodec::VideoReader> reader_;
GpuMat frame_;
};
void VideoFrameSource_GPU::reset()
{
- reader_ = gpucodec::createVideoReader(fileName_);
+ reader_ = cudacodec::createVideoReader(fileName_);
}
}
cv::VideoCapture reader(fname);
cv::cuda::GpuMat d_frame;
- cv::Ptr<cv::gpucodec::VideoReader> d_reader = cv::gpucodec::createVideoReader(fname);
+ cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname);
cv::TickMeter tm;
std::vector<double> cpu_times;
cv::gpu::printShortCudaDeviceInfo(cv::gpu::getDevice());
cv::VideoWriter writer;
- cv::Ptr<cv::gpucodec::VideoWriter> d_writer;
+ cv::Ptr<cv::cudacodec::VideoWriter> d_writer;
cv::Mat frame;
cv::gpu::GpuMat d_frame;
{
std::cout << "Open GPU Writer" << std::endl;
- d_writer = cv::gpucodec::createVideoWriter("output_gpu.avi", frame.size(), FPS);
+ d_writer = cv::cudacodec::createVideoWriter("output_gpu.avi", frame.size(), FPS);
}
d_frame.upload(frame);