Skip to content

Commit ece7f93

Browse files
committed
Rename default interface into FFmpeg (meta-pytorch#964)
1 parent c9c56a2 commit ece7f93

File tree

9 files changed

+19
-23
lines changed

9 files changed

+19
-23
lines changed

src/torchcodec/_core/BetaCudaDeviceInterface.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static UniqueCUvideodecoder createDecoder(CUVIDEOFORMAT* videoFormat) {
129129
// automatically converted to 8bits by NVDEC itself. That is, the raw frames
130130
// we get back from cuvidMapVideoFrame will already be in 8bit format. We
131131
// won't need to do the conversion ourselves, so that's a lot easier.
132-
// In the default interface, we have to do the 10 -> 8bits conversion
132+
// In the ffmpeg CUDA interface, we have to do the 10 -> 8bits conversion
133133
// ourselves later in convertAVFrameToFrameOutput(), because FFmpeg explicitly
134134
// requests 10 or 16bits output formats for >8-bit videos!
135135
// https://github.com/FFmpeg/FFmpeg/blob/e05f8acabff468c1382277c1f31fa8e9d90c3202/libavcodec/nvdec.c#L376-L403
@@ -480,8 +480,7 @@ int BetaCudaDeviceInterface::receiveFrame(UniqueAVFrame& avFrame) {
480480
procParams.top_field_first = dispInfo.top_field_first;
481481
procParams.unpaired_field = dispInfo.repeat_first_field < 0;
482482
// We set the NVDEC stream to the current stream. It will be waited upon by
483-
// the NPP stream before any color conversion. Currently, that syncing logic
484-
// is in the default interface.
483+
// the NPP stream before any color conversion.
485484
// Re types: we get a cudaStream_t from PyTorch but it's interchangeable with
486485
// CUstream
487486
procParams.output_stream = reinterpret_cast<CUstream>(
@@ -618,8 +617,8 @@ void BetaCudaDeviceInterface::convertAVFrameToFrameOutput(
618617
UniqueAVFrame& avFrame,
619618
FrameOutput& frameOutput,
620619
std::optional<torch::Tensor> preAllocatedOutputTensor) {
621-
// TODONVDEC P2: we may need to handle 10bit videos the same way the default
622-
// interface does it with maybeConvertAVFrameToNV12OrRGB24().
620+
// TODONVDEC P2: we may need to handle 10bit videos the same way the CUDA
621+
// ffmpeg interface does it with maybeConvertAVFrameToNV12OrRGB24().
623622
TORCH_CHECK(
624623
avFrame->format == AV_PIX_FMT_CUDA,
625624
"Expected CUDA format frame from BETA CUDA interface");

src/torchcodec/_core/DeviceInterface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace facebook::torchcodec {
2121
// Key for device interface registration with device type + variant support
2222
struct DeviceInterfaceKey {
2323
torch::DeviceType deviceType;
24-
std::string_view variant = "default"; // e.g., "default", "beta", etc.
24+
std::string_view variant = "ffmpeg"; // e.g., "ffmpeg", "beta", etc.
2525

2626
bool operator<(const DeviceInterfaceKey& other) const {
2727
if (deviceType != other.deviceType) {
@@ -141,7 +141,7 @@ void validateDeviceInterface(
141141

142142
std::unique_ptr<DeviceInterface> createDeviceInterface(
143143
const torch::Device& device,
144-
const std::string_view variant = "default");
144+
const std::string_view variant = "ffmpeg");
145145

146146
torch::Tensor rgbAVFrameToTensor(const UniqueAVFrame& avFrame);
147147

src/torchcodec/_core/SingleStreamDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class SingleStreamDecoder {
311311
int streamIndex,
312312
AVMediaType mediaType,
313313
const torch::Device& device = torch::kCPU,
314-
const std::string_view deviceVariant = "default",
314+
const std::string_view deviceVariant = "ffmpeg",
315315
std::optional<int> ffmpegThreadCount = std::nullopt);
316316

317317
// Returns the "best" stream index for a given media type. The "best" is

src/torchcodec/_core/StreamOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ struct VideoStreamOptions {
4141

4242
// By default we use CPU for decoding for both C++ and python users.
4343
torch::Device device = torch::kCPU;
44-
// Device variant (e.g., "default", "beta", etc.)
45-
std::string_view deviceVariant = "default";
44+
// Device variant (e.g., "ffmpeg", "beta", etc.)
45+
std::string_view deviceVariant = "ffmpeg";
4646

4747
// Encoding options
4848
// TODO-VideoEncoder: Consider adding other optional fields here

src/torchcodec/_core/custom_ops.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ TORCH_LIBRARY(torchcodec_ns, m) {
4343
m.def(
4444
"_create_from_file_like(int file_like_context, str? seek_mode=None) -> Tensor");
4545
m.def(
46-
"_add_video_stream(Tensor(a!) decoder, *, int? num_threads=None, str? dimension_order=None, int? stream_index=None, str device=\"cpu\", str device_variant=\"default\", str transform_specs=\"\", (Tensor, Tensor, Tensor)? custom_frame_mappings=None, str? color_conversion_library=None) -> ()");
46+
"_add_video_stream(Tensor(a!) decoder, *, int? num_threads=None, str? dimension_order=None, int? stream_index=None, str device=\"cpu\", str device_variant=\"ffmpeg\", str transform_specs=\"\", (Tensor, Tensor, Tensor)? custom_frame_mappings=None, str? color_conversion_library=None) -> ()");
4747
m.def(
48-
"add_video_stream(Tensor(a!) decoder, *, int? num_threads=None, str? dimension_order=None, int? stream_index=None, str device=\"cpu\", str device_variant=\"default\", str transform_specs=\"\", (Tensor, Tensor, Tensor)? custom_frame_mappings=None) -> ()");
48+
"add_video_stream(Tensor(a!) decoder, *, int? num_threads=None, str? dimension_order=None, int? stream_index=None, str device=\"cpu\", str device_variant=\"ffmpeg\", str transform_specs=\"\", (Tensor, Tensor, Tensor)? custom_frame_mappings=None) -> ()");
4949
m.def(
5050
"add_audio_stream(Tensor(a!) decoder, *, int? stream_index=None, int? sample_rate=None, int? num_channels=None) -> ()");
5151
m.def("seek_to_pts(Tensor(a!) decoder, float seconds) -> ()");
@@ -319,7 +319,7 @@ void _add_video_stream(
319319
std::optional<std::string_view> dimension_order = std::nullopt,
320320
std::optional<int64_t> stream_index = std::nullopt,
321321
std::string_view device = "cpu",
322-
std::string_view device_variant = "default",
322+
std::string_view device_variant = "ffmpeg",
323323
std::string_view transform_specs = "",
324324
std::optional<std::tuple<at::Tensor, at::Tensor, at::Tensor>>
325325
custom_frame_mappings = std::nullopt,
@@ -376,7 +376,7 @@ void add_video_stream(
376376
std::optional<std::string_view> dimension_order = std::nullopt,
377377
std::optional<int64_t> stream_index = std::nullopt,
378378
std::string_view device = "cpu",
379-
std::string_view device_variant = "default",
379+
std::string_view device_variant = "ffmpeg",
380380
std::string_view transform_specs = "",
381381
const std::optional<std::tuple<at::Tensor, at::Tensor, at::Tensor>>&
382382
custom_frame_mappings = std::nullopt) {

src/torchcodec/_core/ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def _add_video_stream_abstract(
304304
dimension_order: Optional[str] = None,
305305
stream_index: Optional[int] = None,
306306
device: str = "cpu",
307-
device_variant: str = "default",
307+
device_variant: str = "ffmpeg",
308308
transform_specs: str = "",
309309
custom_frame_mappings: Optional[
310310
tuple[torch.Tensor, torch.Tensor, torch.Tensor]
@@ -322,7 +322,7 @@ def add_video_stream_abstract(
322322
dimension_order: Optional[str] = None,
323323
stream_index: Optional[int] = None,
324324
device: str = "cpu",
325-
device_variant: str = "default",
325+
device_variant: str = "ffmpeg",
326326
transform_specs: str = "",
327327
custom_frame_mappings: Optional[
328328
tuple[torch.Tensor, torch.Tensor, torch.Tensor]

src/torchcodec/decoders/_video_decoder.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ def __init__(
147147
device = str(device)
148148

149149
device_variant = _get_cuda_backend()
150-
if device_variant == "ffmpeg":
151-
# TODONVDEC P2 rename 'default' into 'ffmpeg' everywhere.
152-
device_variant = "default"
153150

154151
# Legacy support for device="cuda:0:beta" syntax
155152
# TODONVDEC P2: remove support for this everywhere. This will require

test/test_decoders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ def test_10bit_videos(self, device, asset):
13031303
# RuntimeError: Codec configuration not supported on this GPU.
13041304
# Codec: 4, chroma format: 1, bit depth: 10
13051305
#
1306-
# It works on the default interface because FFmpeg fallsback to the
1306+
# It works on the ffmpeg interface because FFmpeg fallsback to the
13071307
# CPU, while the BETA interface doesn't.
13081308
pytest.skip("Asset not supported by NVDEC")
13091309

@@ -1692,8 +1692,8 @@ def test_beta_cuda_interface_backwards(self, asset, seek_mode):
16921692
@needs_cuda
16931693
def test_beta_cuda_interface_small_h265(self):
16941694
# Test to illustrate current difference in behavior between the BETA and
1695-
# the default interface: this video isn't supported by NVDEC, but in the
1696-
# default interface, FFMPEG fallsback to the CPU while we don't.
1695+
# the ffmpeg interface: this video isn't supported by NVDEC, but in the
1696+
# ffmpeg interface, FFMPEG fallsback to the CPU while we don't.
16971697

16981698
VideoDecoder(H265_VIDEO.path, device="cuda").get_frame_at(0)
16991699
with pytest.raises(

test/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def unsplit_device_str(device_str: str) -> str:
4444
if device_str == "cuda:0:beta":
4545
return "cuda", "beta"
4646
else:
47-
return device_str, "default"
47+
return device_str, "ffmpeg"
4848

4949

5050
def get_ffmpeg_major_version():

0 commit comments

Comments
 (0)