77#include " src/torchcodec/_core/FFMPEGCommon.h"
88
99#include < c10/util/Exception.h>
10-
1110extern " C" {
1211#include < libavfilter/avfilter.h>
1312#include < libavfilter/buffersink.h>
@@ -381,18 +380,21 @@ SwrContext* createSwrContext(
381380
382381AVFilterContext* createBuffersinkFilter (
383382 AVFilterGraph* filterGraph,
384- const char * name,
385383 enum AVPixelFormat outputFormat) {
386384 const AVFilter* buffersink = avfilter_get_by_name (" buffersink" );
387385 TORCH_CHECK (buffersink != nullptr , " Failed to get buffersink filter." );
388386
389387 AVFilterContext* sinkContext = nullptr ;
390388 int status;
389+ const char * filterName = " out" ;
390+
391+ enum AVPixelFormat pix_fmts[] = {outputFormat, AV_PIX_FMT_NONE};
391392
392- // av_opt_set_int_list was replaced by av_opt_set () in FFmpeg 8.
393+ // av_opt_set_int_list was replaced by av_opt_set_array () in FFmpeg 8.
393394#if LIBAVUTIL_VERSION_MAJOR >= 60 // FFmpeg >= 8
394395 // Output options like pixel_formats must be set before filter init
395- sinkContext = avfilter_graph_alloc_filter (filterGraph, buffersink, name);
396+ sinkContext =
397+ avfilter_graph_alloc_filter (filterGraph, buffersink, filterName);
396398 TORCH_CHECK (
397399 sinkContext != nullptr , " Failed to allocate buffersink filter context." );
398400
@@ -403,7 +405,7 @@ AVFilterContext* createBuffersinkFilter(
403405 0 , // start_elem
404406 1 , // nb_elems
405407 AV_OPT_TYPE_PIXEL_FMT,
406- &outputFormat );
408+ pix_fmts );
407409 TORCH_CHECK (
408410 status >= 0 ,
409411 " Failed to set pixel format for buffersink filter: " ,
@@ -417,14 +419,12 @@ AVFilterContext* createBuffersinkFilter(
417419#else // FFmpeg <= 7
418420 // For older FFmpeg versions, create filter and then set options
419421 status = avfilter_graph_create_filter (
420- &sinkContext, buffersink, name , nullptr , nullptr , filterGraph);
422+ &sinkContext, buffersink, filterName , nullptr , nullptr , filterGraph);
421423 TORCH_CHECK (
422424 status >= 0 ,
423425 " Failed to create buffersink filter: " ,
424426 getFFMPEGErrorStringFromErrorCode (status));
425427
426- enum AVPixelFormat pix_fmts[] = {outputFormat, AV_PIX_FMT_NONE};
427-
428428 status = av_opt_set_int_list (
429429 sinkContext,
430430 " pix_fmts" ,
0 commit comments