@@ -439,9 +439,9 @@ void VideoDecoder::createFilterGraph(
439439}
440440
441441int VideoDecoder::getBestStreamIndex (AVMediaType mediaType) {
442- AVCodecPtr codec = nullptr ;
442+ AVCodecOnlyUseForCallingAVFindBestStream avCodec = nullptr ;
443443 int streamIndex =
444- av_find_best_stream (formatContext_.get (), mediaType, -1 , -1 , &codec , 0 );
444+ av_find_best_stream (formatContext_.get (), mediaType, -1 , -1 , &avCodec , 0 );
445445 return streamIndex;
446446}
447447
@@ -455,18 +455,18 @@ void VideoDecoder::addVideoStreamDecoder(
455455 }
456456 TORCH_CHECK (formatContext_.get () != nullptr );
457457
458- AVCodecPtr codec = nullptr ;
458+ AVCodecOnlyUseForCallingAVFindBestStream avCodec = nullptr ;
459459 int streamIndex = av_find_best_stream (
460460 formatContext_.get (),
461461 AVMEDIA_TYPE_VIDEO,
462462 preferredStreamIndex,
463463 -1 ,
464- &codec ,
464+ &avCodec ,
465465 0 );
466466 if (streamIndex < 0 ) {
467467 throw std::invalid_argument (" No valid stream found in input file." );
468468 }
469- TORCH_CHECK (codec != nullptr );
469+ TORCH_CHECK (avCodec != nullptr );
470470
471471 StreamMetadata& streamMetadata =
472472 containerMetadata_.streamMetadatas [streamIndex];
@@ -489,13 +489,13 @@ void VideoDecoder::addVideoStreamDecoder(
489489 }
490490
491491 if (videoStreamOptions.device .type () == torch::kCUDA ) {
492- codec =
492+ avCodec = makeAVCodecOnlyUseForCallingAVFindBestStream (
493493 findCudaCodec (
494494 videoStreamOptions.device , streamInfo.stream ->codecpar ->codec_id )
495- .value_or (codec );
495+ .value_or (avCodec) );
496496 }
497497
498- AVCodecContext* codecContext = avcodec_alloc_context3 (codec );
498+ AVCodecContext* codecContext = avcodec_alloc_context3 (avCodec );
499499 TORCH_CHECK (codecContext != nullptr );
500500 codecContext->thread_count = videoStreamOptions.ffmpegThreadCount .value_or (0 );
501501 streamInfo.codecContext .reset (codecContext);
@@ -513,7 +513,7 @@ void VideoDecoder::addVideoStreamDecoder(
513513 false , " Invalid device type: " + videoStreamOptions.device .str ());
514514 }
515515
516- retVal = avcodec_open2 (streamInfo.codecContext .get (), codec , nullptr );
516+ retVal = avcodec_open2 (streamInfo.codecContext .get (), avCodec , nullptr );
517517 if (retVal < AVSUCCESS) {
518518 throw std::invalid_argument (getFFMPEGErrorStringFromErrorCode (retVal));
519519 }
0 commit comments