@@ -337,12 +337,12 @@ void VideoDecoder::createFilterGraph(
337
337
StreamInfo& streamInfo,
338
338
int expectedOutputHeight,
339
339
int expectedOutputWidth) {
340
- FilterState& filterState = streamInfo.filterState ;
341
- filterState .filterGraph .reset (avfilter_graph_alloc ());
342
- TORCH_CHECK (filterState .filterGraph .get () != nullptr );
340
+ FilterGraphContext& filterGraphContext = streamInfo.filterGraphContext ;
341
+ filterGraphContext .filterGraph .reset (avfilter_graph_alloc ());
342
+ TORCH_CHECK (filterGraphContext .filterGraph .get () != nullptr );
343
343
344
344
if (streamInfo.videoStreamOptions .ffmpegThreadCount .has_value ()) {
345
- filterState .filterGraph ->nb_threads =
345
+ filterGraphContext .filterGraph ->nb_threads =
346
346
streamInfo.videoStreamOptions .ffmpegThreadCount .value ();
347
347
}
348
348
@@ -360,25 +360,25 @@ void VideoDecoder::createFilterGraph(
360
360
<< codecContext->sample_aspect_ratio .den ;
361
361
362
362
int ffmpegStatus = avfilter_graph_create_filter (
363
- &filterState .sourceContext ,
363
+ &filterGraphContext .sourceContext ,
364
364
buffersrc,
365
365
" in" ,
366
366
filterArgs.str ().c_str (),
367
367
nullptr ,
368
- filterState .filterGraph .get ());
368
+ filterGraphContext .filterGraph .get ());
369
369
if (ffmpegStatus < 0 ) {
370
370
throw std::runtime_error (
371
371
std::string (" Failed to create filter graph: " ) + filterArgs.str () +
372
372
" : " + getFFMPEGErrorStringFromErrorCode (ffmpegStatus));
373
373
}
374
374
375
375
ffmpegStatus = avfilter_graph_create_filter (
376
- &filterState .sinkContext ,
376
+ &filterGraphContext .sinkContext ,
377
377
buffersink,
378
378
" out" ,
379
379
nullptr ,
380
380
nullptr ,
381
- filterState .filterGraph .get ());
381
+ filterGraphContext .filterGraph .get ());
382
382
if (ffmpegStatus < 0 ) {
383
383
throw std::runtime_error (
384
384
" Failed to create filter graph: " +
@@ -388,7 +388,7 @@ void VideoDecoder::createFilterGraph(
388
388
enum AVPixelFormat pix_fmts[] = {AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE};
389
389
390
390
ffmpegStatus = av_opt_set_int_list (
391
- filterState .sinkContext ,
391
+ filterGraphContext .sinkContext ,
392
392
" pix_fmts" ,
393
393
pix_fmts,
394
394
AV_PIX_FMT_NONE,
@@ -403,11 +403,11 @@ void VideoDecoder::createFilterGraph(
403
403
UniqueAVFilterInOut inputs (avfilter_inout_alloc ());
404
404
405
405
outputs->name = av_strdup (" in" );
406
- outputs->filter_ctx = filterState .sourceContext ;
406
+ outputs->filter_ctx = filterGraphContext .sourceContext ;
407
407
outputs->pad_idx = 0 ;
408
408
outputs->next = nullptr ;
409
409
inputs->name = av_strdup (" out" );
410
- inputs->filter_ctx = filterState .sinkContext ;
410
+ inputs->filter_ctx = filterGraphContext .sinkContext ;
411
411
inputs->pad_idx = 0 ;
412
412
inputs->next = nullptr ;
413
413
@@ -418,7 +418,7 @@ void VideoDecoder::createFilterGraph(
418
418
AVFilterInOut* outputsTmp = outputs.release ();
419
419
AVFilterInOut* inputsTmp = inputs.release ();
420
420
ffmpegStatus = avfilter_graph_parse_ptr (
421
- filterState .filterGraph .get (),
421
+ filterGraphContext .filterGraph .get (),
422
422
description.str ().c_str (),
423
423
&inputsTmp,
424
424
&outputsTmp,
@@ -431,7 +431,8 @@ void VideoDecoder::createFilterGraph(
431
431
getFFMPEGErrorStringFromErrorCode (ffmpegStatus));
432
432
}
433
433
434
- ffmpegStatus = avfilter_graph_config (filterState.filterGraph .get (), nullptr );
434
+ ffmpegStatus =
435
+ avfilter_graph_config (filterGraphContext.filterGraph .get (), nullptr );
435
436
if (ffmpegStatus < 0 ) {
436
437
throw std::runtime_error (
437
438
" Failed to configure filter graph: " +
@@ -1057,7 +1058,7 @@ void VideoDecoder::convertAVFrameToFrameOutputOnCPU(
1057
1058
} else if (
1058
1059
streamInfo.colorConversionLibrary ==
1059
1060
ColorConversionLibrary::FILTERGRAPH) {
1060
- if (!streamInfo.filterState .filterGraph ||
1061
+ if (!streamInfo.filterGraphContext .filterGraph ||
1061
1062
streamInfo.prevFrameContext != frameContext) {
1062
1063
createFilterGraph (streamInfo, expectedOutputHeight, expectedOutputWidth);
1063
1064
streamInfo.prevFrameContext = frameContext;
@@ -1615,16 +1616,17 @@ int VideoDecoder::convertAVFrameToTensorUsingSwsScale(
1615
1616
torch::Tensor VideoDecoder::convertAVFrameToTensorUsingFilterGraph (
1616
1617
int streamIndex,
1617
1618
const AVFrame* avFrame) {
1618
- FilterState& filterState = streamInfos_[streamIndex].filterState ;
1619
+ FilterGraphContext& filterGraphContext =
1620
+ streamInfos_[streamIndex].filterGraphContext ;
1619
1621
int ffmpegStatus =
1620
- av_buffersrc_write_frame (filterState .sourceContext , avFrame);
1622
+ av_buffersrc_write_frame (filterGraphContext .sourceContext , avFrame);
1621
1623
if (ffmpegStatus < AVSUCCESS) {
1622
1624
throw std::runtime_error (" Failed to add frame to buffer source context" );
1623
1625
}
1624
1626
1625
1627
UniqueAVFrame filteredAVFrame (av_frame_alloc ());
1626
- ffmpegStatus =
1627
- av_buffersink_get_frame (filterState .sinkContext , filteredAVFrame.get ());
1628
+ ffmpegStatus = av_buffersink_get_frame (
1629
+ filterGraphContext .sinkContext , filteredAVFrame.get ());
1628
1630
TORCH_CHECK_EQ (filteredAVFrame->format , AV_PIX_FMT_RGB24);
1629
1631
1630
1632
auto frameDims = getHeightAndWidthFromResizedAVFrame (*filteredAVFrame.get ());
0 commit comments