7
7
#include " src/torchcodec/_core/FFMPEGCommon.h"
8
8
9
9
#include < c10/util/Exception.h>
10
-
11
10
extern " C" {
12
11
#include < libavfilter/avfilter.h>
13
12
#include < libavfilter/buffersink.h>
@@ -381,18 +380,21 @@ SwrContext* createSwrContext(
381
380
382
381
AVFilterContext* createBuffersinkFilter (
383
382
AVFilterGraph* filterGraph,
384
- const char * name,
385
383
enum AVPixelFormat outputFormat) {
386
384
const AVFilter* buffersink = avfilter_get_by_name (" buffersink" );
387
385
TORCH_CHECK (buffersink != nullptr , " Failed to get buffersink filter." );
388
386
389
387
AVFilterContext* sinkContext = nullptr ;
390
388
int status;
389
+ const char * filterName = " out" ;
390
+
391
+ enum AVPixelFormat pix_fmts[] = {outputFormat, AV_PIX_FMT_NONE};
391
392
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.
393
394
#if LIBAVUTIL_VERSION_MAJOR >= 60 // FFmpeg >= 8
394
395
// 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);
396
398
TORCH_CHECK (
397
399
sinkContext != nullptr , " Failed to allocate buffersink filter context." );
398
400
@@ -403,7 +405,7 @@ AVFilterContext* createBuffersinkFilter(
403
405
0 , // start_elem
404
406
1 , // nb_elems
405
407
AV_OPT_TYPE_PIXEL_FMT,
406
- &outputFormat );
408
+ pix_fmts );
407
409
TORCH_CHECK (
408
410
status >= 0 ,
409
411
" Failed to set pixel format for buffersink filter: " ,
@@ -417,14 +419,12 @@ AVFilterContext* createBuffersinkFilter(
417
419
#else // FFmpeg <= 7
418
420
// For older FFmpeg versions, create filter and then set options
419
421
status = avfilter_graph_create_filter (
420
- &sinkContext, buffersink, name , nullptr , nullptr , filterGraph);
422
+ &sinkContext, buffersink, filterName , nullptr , nullptr , filterGraph);
421
423
TORCH_CHECK (
422
424
status >= 0 ,
423
425
" Failed to create buffersink filter: " ,
424
426
getFFMPEGErrorStringFromErrorCode (status));
425
427
426
- enum AVPixelFormat pix_fmts[] = {outputFormat, AV_PIX_FMT_NONE};
427
-
428
428
status = av_opt_set_int_list (
429
429
sinkContext,
430
430
" pix_fmts" ,
0 commit comments