55
66#include < iostream>
77#include " frame-writer.hpp"
8- #include < vector>
9- #include < queue>
8+ #include < libavfilter/version.h>
109#include < cstring>
1110#include < sstream>
1211#include " averr.h"
@@ -310,34 +309,42 @@ void FrameWriter::init_video_filters(const AVCodec *codec)
310309 }
311310 buffer_filter_config << " :pixel_aspect=1/1" ;
312311
313- int err = avfilter_graph_create_filter (& this ->videoFilterSourceCtx , source ,
314- " Source" , buffer_filter_config. str (). c_str (), NULL , this -> videoFilterGraph );
315- if (err < 0 ) {
316- std::cerr << " Cannot create video filter in: " << averr (err) << std::endl;;
312+ this -> videoFilterSourceCtx = avfilter_graph_alloc_filter ( this ->videoFilterGraph ,
313+ source, " Source" );
314+ if (! this -> videoFilterSourceCtx ) {
315+ std::cerr << " Cannot alloc video filter in. " << std::endl;;
317316 exit (-1 );
318317 }
319318
320319 AVBufferSrcParameters *p = av_buffersrc_parameters_alloc ();
321320 memset (p, 0 , sizeof (*p));
322321 p->format = AV_PIX_FMT_NONE;
323322 p->hw_frames_ctx = this ->hw_frame_context_in ;
324- err = av_buffersrc_parameters_set (this ->videoFilterSourceCtx , p);
323+ int err = av_buffersrc_parameters_set (this ->videoFilterSourceCtx , p);
325324 av_free (p);
326325 if (err < 0 ) {
327326 std::cerr << " Cannot set hwcontext filter in: " << averr (err) << std::endl;;
328327 exit (-1 );
329328 }
330329
331- err = avfilter_graph_create_filter (&this ->videoFilterSinkCtx , sink, " Sink" ,
332- NULL , NULL , this ->videoFilterGraph );
330+ err = avfilter_init_str (this ->videoFilterSourceCtx , buffer_filter_config.str ().c_str ());
333331 if (err < 0 ) {
334- std::cerr << " Cannot create video filter out: " << averr (err) << std::endl;;
332+ std::cerr << " Cannot init filter in: " << averr (err) << std::endl;;
333+ exit (-1 );
334+ }
335+
336+ this ->videoFilterSinkCtx = avfilter_graph_alloc_filter (this ->videoFilterGraph ,
337+ sink, " Sink" );
338+ if (!this ->videoFilterSinkCtx ) {
339+ std::cerr << " Cannot alloc video filter out." << std::endl;;
335340 exit (-1 );
336341 }
337342
338343 // We also need to tell the sink which pixel formats are supported.
339344 // by the video encoder. codevIndicate to our sink pixel formats
340345 // are accepted by our codec.
346+ // pixel_formats used to be called pix_fmts and was renamed in 10.6.100
347+ #if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(10, 6, 100)
341348 const AVPixelFormat picked_pix_fmt[] =
342349 {
343350 handle_buffersink_pix_fmt (codec),
@@ -346,12 +353,22 @@ void FrameWriter::init_video_filters(const AVCodec *codec)
346353
347354 err = av_opt_set_int_list (this ->videoFilterSinkCtx , " pix_fmts" ,
348355 picked_pix_fmt, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
356+ #else
357+ err = av_opt_set (this ->videoFilterSinkCtx , " pixel_formats" ,
358+ av_get_pix_fmt_name (handle_buffersink_pix_fmt (codec)), AV_OPT_SEARCH_CHILDREN);
359+ #endif
349360
350361 if (err < 0 ) {
351362 std::cerr << " Failed to set pix_fmts: " << averr (err) << std::endl;;
352363 exit (-1 );
353364 }
354365
366+ err = avfilter_init_dict (this ->videoFilterSinkCtx , NULL );
367+ if (err < 0 ) {
368+ std::cerr << " Cannot init filter out: " << averr (err) << std::endl;;
369+ exit (-1 );
370+ }
371+
355372 // Create the connections to the filter graph
356373 //
357374 // The in/out swap is not a mistake:
0 commit comments