32#include <opencv2/imgproc/imgproc.hpp>
44 const std::filesystem::path& filePath)
57 return this->videoCapture.isOpened();
69 return this->frameCount;
75 return this->frameHeight;
81 return this->frameWidth;
88 <<
"Desired frame number to set is above the number of frames in total";
89 if (frame != currentFrame)
91 this->videoCapture.set(cv::CAP_PROP_POS_FRAMES,
static_cast<double>(frame));
92 this->currentFrame = frame;
99 return this->currentFrame;
105 return this->currentFrame < this->frameCount;
111 this->filePath = std::filesystem::canonical(file_path);
112 this->videoCapture.open(this->filePath.string());
115 <<
"Could not open the output video file '" + this->filePath.string() +
"' for writing";
117 this->fps =
static_cast<unsigned int>(this->videoCapture.get(cv::CAP_PROP_FPS));
119 static_cast<unsigned int>(this->videoCapture.get(cv::CAP_PROP_FRAME_HEIGHT));
120 this->frameWidth =
static_cast<unsigned int>(this->videoCapture.get(cv::CAP_PROP_FRAME_WIDTH));
121 this->frameCount =
static_cast<unsigned int>(this->videoCapture.get(cv::CAP_PROP_FRAME_COUNT));
122 this->currentFrame = 0;
129 <<
"Could not open the output video file '" + this->filePath.string() +
"' for writing";
132 const bool success = this->videoCapture.read(frame);
133 ++this->currentFrame;
138 cv::cvtColor(frame, frame, cv::COLOR_BGR2RGB);
141 this->frameHeight * this->frameWidth *
142 static_cast<unsigned int>(frame.channels()));
153 ++this->currentFrame;
161 <<
"Could not open the output video file '" + this->filePath.string() +
"' for writing";
163 return this->videoCapture.read(buffer);
169 if (this->videoCapture.isOpened())
171 this->videoCapture.release();
virtual void setCurrentFrame(unsigned int frame) override
Sets the frame from there the playback should resume afterwards (seek)
virtual void stopPlayback() override
Stops the playback.
virtual unsigned int getFrameWidth() const override
Gets the width of a frame in pixel.
virtual unsigned int getFps() const override
Gets the amount of frames per second of the recording.
virtual bool hasNextFrame() const override
Indicates whether the recording has a consecutive frame.
virtual unsigned int getFrameCount() const override
Gets the total amout of frames in the recording.
virtual unsigned int getCurrentFrame() const override
Gets the current frame index of the playback.
virtual bool getNextFrame(void *buffer) override
Writes the next frame into a buffer of any form (RGB)
virtual void startPlayback(const std::filesystem::path &filePath) override
Starts the playback.
virtual bool isPlayingBack() const override
Indicates whether the instance is configured to be able to play back.
VideoPlaybackStrategy()
Default constructor to manually setup later.
virtual ~VideoPlaybackStrategy() override
Destructor.
virtual unsigned int getFrameHeight() const override
Gets the height of a frame in pixel.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_LESS(lhs, rhs)
This macro evaluates whether lhs is less (<) than rhs and if it turns out to be false it will throw a...