@@ -139,15 +139,8 @@ bool Recorder::init(const RenderSettings& settings) {
139
139
}
140
140
141
141
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
- }
149
142
150
- m_packet = new AVPacket ();
143
+ m_packet = av_packet_alloc ();
151
144
152
145
av_init_packet (m_packet);
153
146
m_packet->data = NULL ;
@@ -156,8 +149,8 @@ bool Recorder::init(const RenderSettings& settings) {
156
149
int inputPixelFormat = (int )settings.m_pixelFormat ;
157
150
158
151
if (!settings.m_colorspaceFilters .empty ()) {
159
- AVFilterGraph* filterGraph = avfilter_graph_alloc ();
160
- if (!filterGraph ) {
152
+ m_filterGraph = avfilter_graph_alloc ();
153
+ if (!m_filterGraph ) {
161
154
geode::log::error (" Could not allocate filter graph." );
162
155
return false ;
163
156
}
@@ -173,24 +166,24 @@ bool Recorder::init(const RenderSettings& settings) {
173
166
m_codecContext->time_base .num , m_codecContext->time_base .den ,
174
167
m_codecContext->sample_aspect_ratio .num , m_codecContext->sample_aspect_ratio .den );
175
168
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 ) {
179
172
geode::log::error (" Error creating filter contexts." );
180
- avfilter_graph_free (&filterGraph );
173
+ avfilter_graph_free (&m_filterGraph );
181
174
return false ;
182
175
}
183
176
184
177
if (avfilter_link (m_buffersrcCtx, 0 , m_colorspaceCtx, 0 ) < 0 ||
185
178
avfilter_link (m_colorspaceCtx, 0 , m_buffersinkCtx, 0 ) < 0 ) {
186
179
geode::log::error (" Error linking filters." );
187
- avfilter_graph_free (&filterGraph );
180
+ avfilter_graph_free (&m_filterGraph );
188
181
return false ;
189
182
}
190
183
191
- if (avfilter_graph_config (filterGraph , nullptr ) < 0 ) {
184
+ if (avfilter_graph_config (m_filterGraph , nullptr ) < 0 ) {
192
185
geode::log::error (" Error configuring filter graph." );
193
- avfilter_graph_free (&filterGraph );
186
+ avfilter_graph_free (&m_filterGraph );
194
187
return false ;
195
188
}
196
189
@@ -253,6 +246,8 @@ bool Recorder::writeFrame(const std::vector<uint8_t>& frameData) {
253
246
av_packet_unref (m_packet);
254
247
}
255
248
249
+ av_frame_unref (m_filteredFrame);
250
+
256
251
return true ;
257
252
}
258
253
@@ -295,7 +290,7 @@ void Recorder::stop() {
295
290
av_frame_free (&m_filteredFrame);
296
291
}
297
292
298
- delete m_packet;
293
+ av_packet_free (& m_packet) ;
299
294
}
300
295
301
296
}
0 commit comments