VideoWriter.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //------------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2018-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: DV
  6. //------------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Contains support for writing video files in MP4 format, provided by a supplementary software package.
  10. */
  11. #ifndef INCLUDED_VIDEOWRITER_H_3842348390
  12. #define INCLUDED_VIDEOWRITER_H_3842348390
  13. #include <pylon/Platform.h>
  14. #ifdef _MSC_VER
  15. # pragma pack(push, PYLON_PACKING)
  16. #endif /* _MSC_VER */
  17. #ifdef _MSC_VER
  18. #pragma warning( push )
  19. #pragma warning( disable : 4275 ) // Class must have a dll interface to be used by clients of the class.
  20. #endif
  21. #include <pylon/stdinclude.h>
  22. #include <pylon/PylonUtility.h>
  23. #include <pylon/Image.h>
  24. #include <pylon/_VideoWriterParams.h>
  25. #include <GenApi/INodeMap.h>
  26. namespace Pylon
  27. {
  28. class CVideoWriterImpl;
  29. using namespace Basler_VideoWriterParams;
  30. /*!
  31. \class CVideoWriter
  32. \brief Supports writing video files.
  33. \note Note that a supplementary software package containing additional libraries has to be installed for this.
  34. */
  35. class PYLONUTILITY_API CVideoWriter : public Basler_VideoWriterParams::CVideoWriterParams_Params
  36. {
  37. public:
  38. /*!
  39. \brief Creates a video writer object.
  40. \error
  41. Throws a RuntimeException when no memory can be allocated.
  42. */
  43. CVideoWriter();
  44. /*!
  45. \brief Destroys the video writer object.
  46. \error
  47. Does not throw C++ exceptions.
  48. */
  49. virtual ~CVideoWriter();
  50. /*!
  51. \brief Checks if video writing is supported.
  52. Checks if all necessary dynamic libraries of the supplementary software package are installed and can be loaded.
  53. This does not check if the codec for the video can be used. This is checked in Open().
  54. \return Returns true if video writing is supported.
  55. \error
  56. Does not throw C++ exceptions.
  57. */
  58. static bool IsSupported();
  59. /*!
  60. \brief Easy way to set parameters required for video recording.
  61. This is a convenient way to set all required parameters in a single function call.
  62. The parameters \c width, \c height, \c framesPerSecondPlaybackSpeed and \c quality are set in the nodemap.
  63. The parameter \c inputPixelType is checked for its convertibility to YUV420p or whether it is already YUV420p.
  64. Advanced parameters can be accessed using the nodemap provided by GetNodeMap().
  65. \param[in] width The number of pixels in a row of the video file to save.
  66. \param[in] height The number of rows of the video file to save.
  67. \param[in] inputPixelType The pixel type of the images that will be added to the video writer. This input is used to derive the video format. Currently the output is always YUV420p.
  68. \param[in] framesPerSecondPlaybackSpeed The playback speed in frames per second.
  69. \param[in] quality The quality setting, valid range is 1 ... 100.
  70. \pre The VideoWriter ist closed.
  71. \error
  72. Throws a C++ exception when a parameter is out of range, set to an invalid value or parameters cannot be changed (e.g., after calling Open()).
  73. */
  74. virtual void SetParameter(
  75. uint32_t width, uint32_t height,
  76. EPixelType inputPixelType,
  77. double framesPerSecondPlaybackSpeed,
  78. uint32_t quality
  79. );
  80. /*!
  81. \brief Opens a video file for writing.
  82. If a file with the same \c filename already exists, it will be overwritten.
  83. \param[in] filename Name and path of the video file.
  84. \pre
  85. <ul>
  86. <li> The VideoWriter ist closed.
  87. <li> The width and height parameters are larger than 1.
  88. </ul>
  89. \error
  90. Throws an exception if the video file cannot be opened.
  91. Throws an exception if the current parameters do not meet codec requirements.
  92. \threading
  93. This method is synchronized using the lock provided by GetLock().
  94. */
  95. virtual void Open( const Pylon::String_t& filename );
  96. /*!
  97. \brief Returns the open state of the video file.
  98. \return Returns true if open.
  99. \error
  100. Does not throw C++ exceptions.
  101. \threading
  102. This method is synchronized using the lock provided by GetLock().
  103. */
  104. virtual bool IsOpen() const;
  105. /*!
  106. \brief Closes the video file.
  107. \error
  108. Does not throw C++ exceptions.
  109. \threading
  110. This method is synchronized using the lock provided by GetLock().
  111. */
  112. virtual void Close();
  113. /*!
  114. \brief Adds the image to the video file. Converts the image to the correct format if required.
  115. The image is automatically converted to YUV420p unless the input \c pixelType is already YUV420p.
  116. The orientation of the image is always converted to \c ImageOrientation_TopDown unless the input\c pixelType is
  117. YUV420p. In that case, the \c orientation of the image must already be \c ImageOrientation_TopDown. See preconditions.
  118. \param[in] pBuffer The pointer to the buffer of the image.
  119. \param[in] bufferSize The size of the buffer in byte.
  120. \param[in] pixelType The pixel type of the image to save.
  121. \param[in] width The number of pixels in a row of the image to save.
  122. \param[in] height The number of rows of the image to save.
  123. \param[in] paddingX The number of extra data bytes at the end of each line.
  124. \param[in] orientation The vertical orientation of the image in the image buffer.
  125. \pre
  126. <ul>
  127. <li> The file is open.
  128. <li> The image added is valid.
  129. <li> The \c pixelType of the image to add is a supported input format of the Pylon::CImageFormatConverter or YUV420p.
  130. <li> If the pixelType is YUV420p the \c orientation has to be \c ImageOrientation_TopDown.
  131. <li> The width and height of the image match the values passed when opening the video file.
  132. </ul>
  133. \error
  134. Throws an exception if the image cannot be added.
  135. \threading
  136. This method is synchronized using the lock provided by GetLock().
  137. */
  138. virtual void Add( const void* pBuffer, size_t bufferSize, Pylon::EPixelType pixelType, uint32_t width, uint32_t height, size_t paddingX, Pylon::EImageOrientation orientation );
  139. /*!
  140. \brief Adds the image to the video file. Converts the image to the correct format if required.
  141. The image is automatically converted to YUV420p unless the input \c pixelType is already YUV420p.
  142. The orientation of the image is always converted to \c ImageOrientation_TopDown unless the input \c pixelType is
  143. YUV420p. In that case, the \c orientation of the image must already be \c ImageOrientation_TopDown. See preconditions.
  144. \param[in] image The image to add, e.g., a CPylonImage, CPylonBitmapImage, or Grab Result Smart Pointer object.
  145. \pre
  146. <ul>
  147. <li> The file is open.
  148. <li> The image added is valid.
  149. <li> The \c pixelType of the image to add is a supported input format of the Pylon::CImageFormatConverter or YUV420p.
  150. <li> If the pixelType is YUV420p the \c orientation has to be \c ImageOrientation_TopDown.
  151. <li> The width and height of the image match the values passed when opening the video file.
  152. </ul>
  153. \error
  154. Throws an exception if the image cannot be added.
  155. \threading
  156. This method is synchronized using the lock provided by GetLock().
  157. */
  158. virtual void Add( const Pylon::IImage& image );
  159. /*!
  160. \brief Can be used to check whether the given image is added to the video file without prior conversion when Add() is called.
  161. \param[in] pixelType The pixel type of the image to save.
  162. \param[in] width The number of pixels in a row of the image to save.
  163. \param[in] height The number of rows of the image to save.
  164. \param[in] paddingX The number of extra data bytes at the end of each row.
  165. \param[in] orientation The vertical orientation of the image data in the video file.
  166. \return Returns true if the image is added to the video stream without prior conversion when Add() is called.
  167. Returns false if the image is automatically converted when Add() is called.
  168. Returns false if the image cannot be added at all. See the preconditions of Add() for more information.
  169. \error
  170. Does not throw C++ exceptions.
  171. */
  172. virtual bool CanAddWithoutConversion( Pylon::EPixelType pixelType, uint32_t width, uint32_t height, size_t paddingX, Pylon::EImageOrientation orientation );
  173. /*!
  174. \brief Can be used to check whether the given image is added to the video file without prior conversion when Add() is called.
  175. \param[in] image The image to save, e.g. a CPylonImage, CPylonBitmapImage, or Grab Result Smart Pointer object.
  176. \return Returns true if the image is added to the video stream without prior conversion when Add() is called.
  177. Returns false if the image is automatically converted when Add() is called.
  178. Returns false if the image cannot be added at all. See the preconditions of Add() for more information.
  179. \error
  180. Does not throw C++ exceptions.
  181. */
  182. virtual bool CanAddWithoutConversion( const Pylon::IImage& image );
  183. /*!
  184. \brief Provides access to all parameters via a nodemap.
  185. \error
  186. Does not throw C++ exceptions.
  187. */
  188. virtual GenApi::INodeMap& GetNodeMap();
  189. protected:
  190. /*!
  191. \brief Provides access to the lock used for synchronizing the access to the video writer.
  192. \error
  193. Does not throw C++ exceptions.
  194. */
  195. CLock& GetLock();
  196. private:
  197. CVideoWriterImpl* m_pImpl;
  198. };
  199. }
  200. #ifdef _MSC_VER
  201. #pragma warning(pop)
  202. #endif
  203. #ifdef _MSC_VER
  204. # pragma pack(pop)
  205. #endif /* _MSC_VER */
  206. #endif // INCLUDED_VIDEOWRITER_H_3842348390