1 // 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 11 namespace common 12 { 13 14 class CvVideoFileWriter : public IFrameOutput<cv::Mat> { 15 public: 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 57 private: 58 cv::VideoWriter m_cvWriter{}; 59 bool m_ready = false; 60 }; 61 }// namespace common