AVIRecordingStrategy.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package visionx::imrec
17 * @author Christian R. G. Dreher <christian.dreher@student.kit.edu>
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
25
26
27// OpenCV 2
28#include <opencv2/core/core.hpp>
29#include <opencv2/highgui/highgui.hpp> // cv::VideoWriter
30
31// Simox
32#include <SimoxUtility/algorithm.h>
33
38
40 const std::filesystem::path& file_path,
41 const std::string& filename,
42 const double fps) :
44{
45 std::string filename_ext = filename;
46 if (not simox::alg::ends_with(filename_ext, ".avi"))
47 {
48 filename_ext += ".avi";
49 }
50
51 m_file_path /= filename_ext;
52}
53
58
59void
65
66void
68 const std::chrono::microseconds timestamp)
69{
71
72 if (not m_avi_video_writer->isOpened())
73 {
74 const std::string filePath = getFilePath().string();
75 const int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
76 m_avi_video_writer->open(filePath, fourcc, m_fps, frame.size());
77
78 if (not m_avi_video_writer->isOpened())
79 {
80 ARMARX_ERROR << deactivateSpam() << "Could not open the output video file '" << filePath
81 << "' for writing. FRAME DROPPED!";
82 return;
83 }
84 }
85
86 m_avi_video_writer->write(frame);
87}
88
89void
std::string timestamp()
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
AbstractRecordingStrategy()
Default constructor to start the recording manually.
std::filesystem::path m_file_path
Path to where the recording file should be written to.
virtual void startRecording()
Starts the recording manually if constructed empty.
virtual std::tuple< unsigned int, std::string > writeMetadataFrame(const CByteImage &frame, std::chrono::microseconds timestamp)
virtual std::filesystem::path getFilePath() const
Gets the raw file path for the recording as configured.
void startRecording() override
Starts the recording manually if constructed empty.
std::unique_ptr< cv::VideoWriter > m_avi_video_writer
void recordFrame(const cv::Mat &frame, std::chrono::microseconds timestamp) override
Adds the given frame to the recording.
void stopRecording() override
Stops the recording.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
ArmarX headers.