Skip to content

Commit c5fa1e1

Browse files
author
Daniel Flores
committed
incorporate suggestions
1 parent 4d41abb commit c5fa1e1

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/torchcodec/_core/FFMPEGCommon.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "src/torchcodec/_core/FFMPEGCommon.h"
88

99
#include <c10/util/Exception.h>
10-
1110
extern "C" {
1211
#include <libavfilter/avfilter.h>
1312
#include <libavfilter/buffersink.h>
@@ -381,18 +380,21 @@ SwrContext* createSwrContext(
381380

382381
AVFilterContext* 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",

src/torchcodec/_core/FFMPEGCommon.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ int64_t computeSafeDuration(
239239

240240
AVFilterContext* createBuffersinkFilter(
241241
AVFilterGraph* filterGraph,
242-
const char* name,
243242
enum AVPixelFormat outputFormat);
244243

245244
} // namespace facebook::torchcodec

src/torchcodec/_core/FilterGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ FilterGraph::FilterGraph(
9393
"Failed to create filter graph : ",
9494
getFFMPEGErrorStringFromErrorCode(status));
9595

96-
sinkContext_ = createBuffersinkFilter(
97-
filterGraph_.get(), "out", filtersContext.outputFormat);
96+
sinkContext_ =
97+
createBuffersinkFilter(filterGraph_.get(), filtersContext.outputFormat);
9898
TORCH_CHECK(
9999
sinkContext_ != nullptr, "Failed to create and configure buffersink");
100100

0 commit comments

Comments
 (0)