This repository has been archived on 2021-03-01. You can view files and clone it, but cannot push or open issues or pull requests.
prpa/src/encoder/video_reader.cc

66 lines
1.2 KiB
C++

#include "opencv2/opencv.hpp"
#include "video_reader.hh"
VideoReader::VideoReader(std::string filename)
: filter(tbb::filter::serial_in_order), capture_(filename)
{
this->remaining_ = framecount_get();
}
VideoReader::VideoReader(const VideoReader& vr)
: filter(tbb::filter::serial_in_order)
{
this->capture_ = vr.capture_;
this->remaining_ = framecount_get();
}
void* VideoReader::operator()(void* ign)
{
(void)ign;
cv::Mat retrieved;
if (this->remaining_ > 0)
{
this->capture_.read(retrieved);
cv::Mat* res = new cv::Mat;
*res = retrieved.clone();
this->remaining_--;
return res;
}
else
return nullptr;
}
int VideoReader::framecount_get()
{
if (this->capture_.isOpened())
return (int)this->capture_.get(CV_CAP_PROP_FRAME_COUNT);
else
return -1;
}
int VideoReader::fps_get()
{
if (this->capture_.isOpened())
return (int)this->capture_.get(CV_CAP_PROP_FPS);
else
return -1;
}
int VideoReader::width_get()
{
if (this->capture_.isOpened())
return (int)this->capture_.get(CV_CAP_PROP_FRAME_WIDTH);
else
return -1;
}
int VideoReader::height_get()
{
if (this->capture_.isOpened())
return (int)this->capture_.get(CV_CAP_PROP_FRAME_HEIGHT);
else
return -1;
}