Skip to content

Commit 63425d3

Browse files
committed
Put back thread_count init before call to open2
1 parent 85b0bdc commit 63425d3

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ VideoDecoder::VideoStreamOptions::VideoStreamOptions(
411411
void VideoDecoder::addStream(
412412
int streamIndex,
413413
AVMediaType mediaType,
414-
const torch::Device& device) {
414+
const torch::Device& device,
415+
std::optional<int> ffmpegThreadCount) {
415416
TORCH_CHECK(
416417
activeStreamIndex_ == NO_ACTIVE_STREAM,
417418
"Can only add one single stream.");
@@ -462,6 +463,8 @@ void VideoDecoder::addStream(
462463
streamInfo.codecContext.get(), streamInfo.stream->codecpar);
463464
TORCH_CHECK_EQ(retVal, AVSUCCESS);
464465

466+
streamInfo.codecContext->thread_count = ffmpegThreadCount.value_or(0);
467+
465468
// TODO_CODE_QUALITY same as above.
466469
if (mediaType == AVMEDIA_TYPE_VIDEO && device.type() == torch::kCUDA) {
467470
initializeContextOnCuda(device, codecContext);
@@ -495,7 +498,11 @@ void VideoDecoder::addVideoStream(
495498
videoStreamOptions.device.type() == torch::kCUDA,
496499
"Invalid device type: " + videoStreamOptions.device.str());
497500

498-
addStream(streamIndex, AVMEDIA_TYPE_VIDEO, videoStreamOptions.device);
501+
addStream(
502+
streamIndex,
503+
AVMEDIA_TYPE_VIDEO,
504+
videoStreamOptions.device,
505+
videoStreamOptions.ffmpegThreadCount);
499506

500507
auto& streamMetadata =
501508
containerMetadata_.allStreamMetadata[activeStreamIndex_];
@@ -510,8 +517,6 @@ void VideoDecoder::addVideoStream(
510517

511518
auto& streamInfo = streamInfos_[activeStreamIndex_];
512519
streamInfo.videoStreamOptions = videoStreamOptions;
513-
streamInfo.codecContext->thread_count =
514-
videoStreamOptions.ffmpegThreadCount.value_or(0);
515520

516521
streamMetadata.width = streamInfo.codecContext->width;
517522
streamMetadata.height = streamInfo.codecContext->height;

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ class VideoDecoder {
429429
void addStream(
430430
int streamIndex,
431431
AVMediaType mediaType,
432-
const torch::Device& device = torch::kCPU);
432+
const torch::Device& device = torch::kCPU,
433+
std::optional<int> ffmpegThreadCount = std::nullopt);
433434

434435
// Returns the "best" stream index for a given media type. The "best" is
435436
// determined by various heuristics in FFMPEG.

0 commit comments

Comments
 (0)