32 #include <opencv2/imgproc/imgproc.hpp>
47 this->startPlayback(filePath);
60 return this->videoCapture.isOpened();
74 return this->frameCount;
81 return this->frameHeight;
88 return this->frameWidth;
95 ARMARX_CHECK_LESS(frame, this->frameCount) <<
"Desired frame number to set is above the number of frames in total";
96 if (frame != currentFrame)
98 this->videoCapture.set(cv::CAP_PROP_POS_FRAMES,
static_cast<double>(frame));
99 this->currentFrame = frame;
107 return this->currentFrame;
114 return this->currentFrame < this->frameCount;
121 this->filePath = std::filesystem::canonical(file_path);
122 this->videoCapture.open(this->filePath.string());
124 ARMARX_CHECK_EXPRESSION(this->videoCapture.isOpened()) <<
"Could not open the output video file '" + this->filePath.string() +
"' for writing";
126 this->fps =
static_cast<unsigned int>(this->videoCapture.get(cv::CAP_PROP_FPS));
127 this->frameHeight =
static_cast<unsigned int>(this->videoCapture.get(cv::CAP_PROP_FRAME_HEIGHT));
128 this->frameWidth =
static_cast<unsigned int>(this->videoCapture.get(cv::CAP_PROP_FRAME_WIDTH));
129 this->frameCount =
static_cast<unsigned int>(this->videoCapture.get(cv::CAP_PROP_FRAME_COUNT));
130 this->currentFrame = 0;
137 ARMARX_CHECK_EXPRESSION(this->videoCapture.isOpened()) <<
"Could not open the output video file '" + this->filePath.string() +
"' for writing";
140 const bool success = this->videoCapture.read(frame);
141 ++this->currentFrame;
146 cv::cvtColor(frame, frame, cv::COLOR_BGR2RGB);
147 std::memcpy(buffer, frame.data, this->frameHeight * this->frameWidth *
static_cast<unsigned int>(frame.channels()));
158 const bool success = this->getNextFrame(buffer.pixels);
159 ++this->currentFrame;
167 ARMARX_CHECK_EXPRESSION(this->videoCapture.isOpened()) <<
"Could not open the output video file '" + this->filePath.string() +
"' for writing";
169 return this->videoCapture.read(buffer);
176 if (this->videoCapture.isOpened())
178 this->videoCapture.release();