@@ -25,6 +25,36 @@ class AVFilterGraph;
2525BEGIN_FFMPEG_NAMESPACE_V
2626
2727class FFMPEG_API_DLL Recorder {
28+ private:
29+ class Impl {
30+ public:
31+ AVFormatContext* m_formatContext = nullptr ;
32+ const AVCodec* m_codec = nullptr ;
33+ AVStream* m_videoStream = nullptr ;
34+ AVCodecContext* m_codecContext = nullptr ;
35+ AVBufferRef* m_hwDevice = nullptr ;
36+ AVFrame* m_frame = nullptr ;
37+ AVFrame* m_convertedFrame = nullptr ;
38+ AVFrame* m_filteredFrame = nullptr ;
39+ AVPacket* m_packet = nullptr ;
40+ SwsContext* m_swsCtx = nullptr ;
41+ AVFilterGraph* m_filterGraph = nullptr ;
42+ AVFilterContext* m_buffersrcCtx = nullptr ;
43+ AVFilterContext* m_buffersinkCtx = nullptr ;
44+ AVFilterContext* m_colorspaceCtx = nullptr ;
45+ AVFilterContext* m_vflipCtx = nullptr ;
46+
47+ size_t m_frameCount = 0 ;
48+ bool m_init = false ;
49+
50+ geode::Result<> init (const RenderSettings& settings);
51+ void stop ();
52+ geode::Result<> writeFrame (const std::vector<uint8_t >& frameData);
53+ geode::Result<> filterFrame (AVFrame* inputFrame, AVFrame* outputFrame);
54+ };
55+
56+ std::unique_ptr<Impl> m_impl = nullptr ;
57+
2858public:
2959 /* *
3060 * @brief Initializes the Recorder with the specified rendering settings.
@@ -37,15 +67,18 @@ class FFMPEG_API_DLL Recorder {
3767 *
3868 * @return true if initialization is successful, false otherwise.
3969 */
40- geode::Result<> init (const RenderSettings& settings);
70+ geode::Result<> init (const RenderSettings& settings) {
71+ m_impl = std::make_unique<Impl>();
72+ return m_impl->init (settings);
73+ }
4174
4275 /* *
4376 * @brief Stops the recording process and finalizes the output file.
4477 *
4578 * This function ensures that all buffered frames are written to the output file,
4679 * releases allocated resources, and properly closes the output file.
4780 */
48- void stop ();
81+ void stop () const { m_impl-> stop (); }
4982
5083 /* *
5184 * @brief Writes a single video frame to the output.
@@ -60,7 +93,9 @@ class FFMPEG_API_DLL Recorder {
6093 *
6194 * @warning Ensure that the frameData size matches the expected dimensions of the frame.
6295 */
63- geode::Result<> writeFrame (const std::vector<uint8_t >& frameData);
96+ geode::Result<> writeFrame (const std::vector<uint8_t >& frameData) const {
97+ return m_impl->writeFrame (frameData);
98+ }
6499
65100 /* *
66101 * @brief Retrieves a list of available codecs for video encoding.
@@ -73,32 +108,9 @@ class FFMPEG_API_DLL Recorder {
73108 static std::vector<std::string> getAvailableCodecs ();
74109
75110private:
76- geode::Result<> filterFrame (AVFrame* inputFrame, AVFrame* outputFrame);
77-
78- private:
79- class Impl {
80- public:
81- AVFormatContext* m_formatContext = nullptr ;
82- const AVCodec* m_codec = nullptr ;
83- AVStream* m_videoStream = nullptr ;
84- AVCodecContext* m_codecContext = nullptr ;
85- AVBufferRef* m_hwDevice = nullptr ;
86- AVFrame* m_frame = nullptr ;
87- AVFrame* m_convertedFrame = nullptr ;
88- AVFrame* m_filteredFrame = nullptr ;
89- AVPacket* m_packet = nullptr ;
90- SwsContext* m_swsCtx = nullptr ;
91- AVFilterGraph* m_filterGraph = nullptr ;
92- AVFilterContext* m_buffersrcCtx = nullptr ;
93- AVFilterContext* m_buffersinkCtx = nullptr ;
94- AVFilterContext* m_colorspaceCtx = nullptr ;
95- AVFilterContext* m_vflipCtx = nullptr ;
96-
97- size_t m_frameCount = 0 ;
98- bool m_init = false ;
99- };
100-
101- std::unique_ptr<Impl> m_impl = nullptr ;
111+ geode::Result<> filterFrame (AVFrame* inputFrame, AVFrame* outputFrame) const {
112+ return m_impl->filterFrame (inputFrame, outputFrame);
113+ }
102114};
103115
104116END_FFMPEG_NAMESPACE_V
0 commit comments