File indexing completed on 2025-01-18 10:04:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef Image_VideoRecorder_HeaderFile_
0017 #define Image_VideoRecorder_HeaderFile_
0018
0019 #include <Image_PixMap.hxx>
0020 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
0021 #include <Standard_Transient.hxx>
0022 #include <TCollection_AsciiString.hxx>
0023
0024
0025 struct AVFormatContext;
0026 struct AVStream;
0027 struct AVCodec;
0028 struct AVFrame;
0029 struct SwsContext;
0030
0031
0032
0033
0034 #ifdef PixelFormat
0035 #undef PixelFormat
0036 #endif
0037
0038
0039
0040 struct Image_VideoParams
0041 {
0042 TCollection_AsciiString Format;
0043 TCollection_AsciiString VideoCodec;
0044 TCollection_AsciiString PixelFormat;
0045 Standard_Integer Width;
0046 Standard_Integer Height;
0047 Standard_Integer FpsNum;
0048 Standard_Integer FpsDen;
0049 Resource_DataMapOfAsciiStringAsciiString
0050 VideoCodecParams;
0051
0052
0053 Image_VideoParams() : Width (0), Height (0), FpsNum (0), FpsDen (1) {}
0054
0055
0056 void SetFramerate (const Standard_Integer theNumerator,
0057 const Standard_Integer theDenominator)
0058 {
0059 FpsNum = theNumerator;
0060 FpsDen = theDenominator;
0061 }
0062
0063
0064
0065 void SetFramerate (const Standard_Integer theValue)
0066 {
0067 FpsNum = theValue;
0068 FpsDen = 1;
0069 }
0070 };
0071
0072
0073 class Image_VideoRecorder : public Standard_Transient
0074 {
0075 DEFINE_STANDARD_RTTIEXT(Image_VideoRecorder, Standard_Transient)
0076 public:
0077
0078
0079 Standard_EXPORT Image_VideoRecorder();
0080
0081
0082 Standard_EXPORT virtual ~Image_VideoRecorder();
0083
0084
0085 Standard_EXPORT void Close();
0086
0087
0088
0089
0090 Standard_EXPORT Standard_Boolean Open (const char* theFileName,
0091 const Image_VideoParams& theParams);
0092
0093
0094
0095 Image_PixMap& ChangeFrame() { return myImgSrcRgba; }
0096
0097
0098 int64_t FrameCount() const { return myFrameCount; }
0099
0100
0101 Standard_Boolean PushFrame()
0102 {
0103 return writeVideoFrame (Standard_False);
0104 }
0105
0106 protected:
0107
0108
0109 Standard_EXPORT TCollection_AsciiString formatAvError (const int theError) const;
0110
0111
0112
0113
0114 Standard_EXPORT Standard_Boolean addVideoStream (const Image_VideoParams& theParams,
0115 const Standard_Integer theDefCodecId);
0116
0117
0118 Standard_EXPORT Standard_Boolean openVideoCodec (const Image_VideoParams& theParams);
0119
0120
0121 Standard_EXPORT Standard_Boolean writeVideoFrame (const Standard_Boolean theToFlush);
0122
0123 protected:
0124
0125
0126 struct VideoRational
0127 {
0128 int num;
0129 int den;
0130 };
0131
0132 protected:
0133
0134 AVFormatContext* myAVContext;
0135 AVStream* myVideoStream;
0136 AVCodec* myVideoCodec;
0137 AVFrame* myFrame;
0138 SwsContext* myScaleCtx;
0139
0140 Image_PixMap myImgSrcRgba;
0141 VideoRational myFrameRate;
0142 int64_t myFrameCount;
0143
0144 };
0145
0146 DEFINE_STANDARD_HANDLE(Image_VideoRecorder, Standard_Transient)
0147
0148 #endif