blob: 30348f09cc1cb1db4d32b239fead5fa16d1b72e1 [file] [log] [blame]
Éanna Ó Catháin919c14e2020-09-14 17:36:49 +01001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include "IFrameOutput.hpp"
9#include <opencv2/opencv.hpp>
10
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010011namespace common
Éanna Ó Catháin919c14e2020-09-14 17:36:49 +010012{
13
14class CvVideoFileWriter : public IFrameOutput<cv::Mat> {
15public:
16 /**
17 * @brief Default constructor.
18 *
19 * Underlying open cv video writer object will be instantiated.
20 */
21 CvVideoFileWriter() = default;
22
23 ~CvVideoFileWriter() override = default;
24
25 /**
26 * @brief Initialises video file writer.
27 *
28 * Opens opencv writer with given params. FFMPEG backend is used.
29 *
30 * @param outputVideo path to the video file.
31 * @param encoding cv::CAP_PROP_FOURCC code.
32 * @param fps target frame rate.
33 * @param width target frame width.
34 * @param height target frame height.
35 *
36 */
37 void Init(const std::string& outputVideo, int encoding, double fps, int width, int height);
38
39 /**
40 * Writes frame to the file using opencv writer.
41 *
42 * @param frame data to write.
43 */
44 void WriteFrame(std::shared_ptr<cv::Mat>& frame) override;
45
46 /**
47 * Releases opencv writer.
48 */
49 void Close() override;
50
51 /**
52 * Checks if opencv writer was successfully opened.
53 * @return true is underlying writer is ready to be used, false otherwise.
54 */
55 bool IsReady() const override;
56
57private:
58 cv::VideoWriter m_cvWriter{};
59 bool m_ready = false;
60};
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010061}// namespace common