Skip to content

Commit 3c7b97e

Browse files
author
Molly Xu
committed
fix compiilation issues related to different ffmpeg versions
1 parent 708f790 commit 3c7b97e

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

src/torchcodec/_core/CudaDeviceInterface.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ const int MAX_CONTEXTS_PER_GPU_IN_CACHE = -1;
4141
PerGpuCache<AVBufferRef, Deleterp<AVBufferRef, void, av_buffer_unref>>
4242
g_cached_hw_device_ctxs(MAX_CUDA_GPUS, MAX_CONTEXTS_PER_GPU_IN_CACHE);
4343

44+
// 58.26.100 introduced the concept of reusing the existing cuda context
45+
// which is much faster and lower memory than creating a new cuda context.
46+
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58, 26, 100)
47+
int flags = AV_CUDA_USE_CURRENT_CONTEXT;
48+
#else
49+
int flags = 0;
50+
#endif
51+
4452
UniqueAVBufferRef getHardwareDeviceContext(const torch::Device& device) {
4553
enum AVHWDeviceType type = av_hwdevice_find_type_by_name("cuda");
4654
TORCH_CHECK(type != AV_HWDEVICE_TYPE_NONE, "Failed to find cuda device");
@@ -62,7 +70,6 @@ UniqueAVBufferRef getHardwareDeviceContext(const torch::Device& device) {
6270
AVBufferRef* hw_device_ctx_raw = nullptr;
6371
std::string deviceOrdinal = std::to_string(nonNegativeDeviceIndex);
6472

65-
int flags = (canReuseHardwareContext()) ? AV_CUDA_USE_CURRENT_CONTEXT : 0;
6673
int err = av_hwdevice_ctx_create(
6774
&hw_device_ctx_raw, type, deviceOrdinal.c_str(), nullptr, flags);
6875

src/torchcodec/_core/FFMPEGCommon.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,4 @@ int64_t computeSafeDuration(
605605
}
606606
}
607607

608-
int64_t canReuseHardwareContext() {
609-
// 58.26.100 introduced the concept of reusing the existing cuda context
610-
// which is much faster and lower memory than creating a new cuda context.
611-
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58, 26, 100)
612-
return 1;
613-
#else
614-
return 0;
615-
#endif
616-
}
617-
618608
} // namespace facebook::torchcodec

src/torchcodec/_core/FFMPEGCommon.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,4 @@ AVFilterContext* createBuffersinkFilter(
242242
AVFilterGraph* filterGraph,
243243
enum AVPixelFormat outputFormat);
244244

245-
// Returns whether hardware context can be reused based on FFmpeg
246-
// version.
247-
int64_t canReuseHardwareContext();
248-
249245
} // namespace facebook::torchcodec

0 commit comments

Comments
 (0)