@@ -234,25 +234,13 @@ void FrameWriter::init_video_filters(const AVCodec *codec)
234234 }
235235
236236 if (this ->hw_device_context ) {
237- this ->hw_frame_context = av_hwframe_ctx_alloc (this ->hw_device_context );
238- AVHWFramesContext *hwfc = reinterpret_cast <AVHWFramesContext*>(this ->hw_frame_context ->data );
239- hwfc->format = AV_PIX_FMT_VAAPI;
240- hwfc->sw_format = AV_PIX_FMT_NV12;
241- hwfc->width = params.width ;
242- hwfc->height = params.height ;
243- int err = av_hwframe_ctx_init (this ->hw_frame_context );
244- if (err < 0 ) {
245- std::cerr << " Cannot create hw frames context: " << averr (err) << std::endl;
246- exit (-1 );
247- }
248-
249237 this ->hw_frame_context_in = av_hwframe_ctx_alloc (this ->hw_device_context );
250- hwfc = reinterpret_cast <AVHWFramesContext*>(this ->hw_frame_context_in ->data );
238+ AVHWFramesContext * hwfc = reinterpret_cast <AVHWFramesContext*>(this ->hw_frame_context_in ->data );
251239 hwfc->format = AV_PIX_FMT_VAAPI;
252240 hwfc->sw_format = get_drm_av_format (params.drm_format );
253241 hwfc->width = params.width ;
254242 hwfc->height = params.height ;
255- err = av_hwframe_ctx_init (this ->hw_frame_context_in );
243+ int err = av_hwframe_ctx_init (this ->hw_frame_context_in );
256244 if (err < 0 ) {
257245 std::cerr << " Cannot create hw frames context: " << averr (err) << std::endl;
258246 exit (-1 );
@@ -385,6 +373,8 @@ void FrameWriter::init_video_filters(const AVCodec *codec)
385373 this ->videoCodecCtx ->framerate = filter_output->frame_rate ; // can be 1/0 if unknown
386374 this ->videoCodecCtx ->sample_aspect_ratio = filter_output->sample_aspect_ratio ;
387375
376+ this ->hw_frame_context = av_buffersink_get_hw_frames_ctx (
377+ this ->videoFilterSinkCtx );
388378 avfilter_inout_free (&inputs);
389379 avfilter_inout_free (&outputs);
390380}
0 commit comments