@@ -139,15 +139,8 @@ bool Recorder::init(const RenderSettings& settings) {
139139 }
140140
141141 m_filteredFrame = av_frame_alloc ();
142- m_filteredFrame->format = m_codecContext->pix_fmt ;
143- m_filteredFrame->width = m_codecContext->width ;
144- m_filteredFrame->height = m_codecContext->height ;
145- if (av_image_alloc (m_filteredFrame->data , m_filteredFrame->linesize , m_filteredFrame->width , m_filteredFrame->height , m_codecContext->pix_fmt , 32 ) < 0 ) {
146- geode::log::error (" Could not allocate raw picture buffer." );
147- return false ;
148- }
149142
150- m_packet = new AVPacket ();
143+ m_packet = av_packet_alloc ();
151144
152145 av_init_packet (m_packet);
153146 m_packet->data = NULL ;
@@ -156,8 +149,8 @@ bool Recorder::init(const RenderSettings& settings) {
156149 int inputPixelFormat = (int )settings.m_pixelFormat ;
157150
158151 if (!settings.m_colorspaceFilters .empty ()) {
159- AVFilterGraph* filterGraph = avfilter_graph_alloc ();
160- if (!filterGraph ) {
152+ m_filterGraph = avfilter_graph_alloc ();
153+ if (!m_filterGraph ) {
161154 geode::log::error (" Could not allocate filter graph." );
162155 return false ;
163156 }
@@ -173,24 +166,24 @@ bool Recorder::init(const RenderSettings& settings) {
173166 m_codecContext->time_base .num , m_codecContext->time_base .den ,
174167 m_codecContext->sample_aspect_ratio .num , m_codecContext->sample_aspect_ratio .den );
175168
176- if (avfilter_graph_create_filter (&m_buffersrcCtx, buffersrc, " in" , args, nullptr , filterGraph ) < 0 ||
177- avfilter_graph_create_filter (&m_buffersinkCtx, buffersink, " out" , nullptr , nullptr , filterGraph ) < 0 ||
178- avfilter_graph_create_filter (&m_colorspaceCtx, colorspace, " colorspace" , settings.m_colorspaceFilters .c_str (), nullptr , filterGraph ) < 0 ) {
169+ if (avfilter_graph_create_filter (&m_buffersrcCtx, buffersrc, " in" , args, nullptr , m_filterGraph ) < 0 ||
170+ avfilter_graph_create_filter (&m_buffersinkCtx, buffersink, " out" , nullptr , nullptr , m_filterGraph ) < 0 ||
171+ avfilter_graph_create_filter (&m_colorspaceCtx, colorspace, " colorspace" , settings.m_colorspaceFilters .c_str (), nullptr , m_filterGraph ) < 0 ) {
179172 geode::log::error (" Error creating filter contexts." );
180- avfilter_graph_free (&filterGraph );
173+ avfilter_graph_free (&m_filterGraph );
181174 return false ;
182175 }
183176
184177 if (avfilter_link (m_buffersrcCtx, 0 , m_colorspaceCtx, 0 ) < 0 ||
185178 avfilter_link (m_colorspaceCtx, 0 , m_buffersinkCtx, 0 ) < 0 ) {
186179 geode::log::error (" Error linking filters." );
187- avfilter_graph_free (&filterGraph );
180+ avfilter_graph_free (&m_filterGraph );
188181 return false ;
189182 }
190183
191- if (avfilter_graph_config (filterGraph , nullptr ) < 0 ) {
184+ if (avfilter_graph_config (m_filterGraph , nullptr ) < 0 ) {
192185 geode::log::error (" Error configuring filter graph." );
193- avfilter_graph_free (&filterGraph );
186+ avfilter_graph_free (&m_filterGraph );
194187 return false ;
195188 }
196189
@@ -253,6 +246,8 @@ bool Recorder::writeFrame(const std::vector<uint8_t>& frameData) {
253246 av_packet_unref (m_packet);
254247 }
255248
249+ av_frame_unref (m_filteredFrame);
250+
256251 return true ;
257252}
258253
@@ -295,7 +290,7 @@ void Recorder::stop() {
295290 av_frame_free (&m_filteredFrame);
296291 }
297292
298- delete m_packet;
293+ av_packet_free (& m_packet) ;
299294}
300295
301296}
0 commit comments