Skip to content

Commit 7a41bfd

Browse files
committed
Removes width and height from StreamOptions
1 parent 30622a7 commit 7a41bfd

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

src/torchcodec/_core/CpuDeviceInterface.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ void CpuDeviceInterface::initialize(
7676
// https://stackoverflow.com/questions/74351955/turn-off-sw-scale-conversion-to-planar-yuv-32-byte-alignment-requirements
7777
bool isWidthSwScaleCompatible = (outputDims_.width % 32) == 0;
7878

79-
bool userRequestedSwScale =
80-
videoStreamOptions_.colorConversionLibrary.has_value() &&
81-
videoStreamOptions_.colorConversionLibrary.value() ==
82-
ColorConversionLibrary::SWSCALE;
79+
bool userRequestedSwScale = videoStreamOptions_.colorConversionLibrary ==
80+
ColorConversionLibrary::SWSCALE;
8381

8482
// Note that we treat the transform limitation differently from the width
8583
// limitation. That is, we consider the transforms being compatible with

src/torchcodec/_core/Encoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ void VideoEncoder::initializeEncoder(
603603

604604
// Use specified dimensions or input dimensions
605605
// TODO-VideoEncoder: Allow height and width to be set
606-
outWidth_ = videoStreamOptions.width.value_or(inWidth_);
607-
outHeight_ = videoStreamOptions.height.value_or(inHeight_);
606+
outWidth_ = inWidth_;
607+
outHeight_ = inHeight_;
608608

609609
// Use YUV420P as default output format
610610
// TODO-VideoEncoder: Enable other pixel formats

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,6 @@ void SingleStreamDecoder::addVideoStream(
499499
streamIndex, customFrameMappings.value());
500500
}
501501

502-
TORCH_CHECK(
503-
!videoStreamOptions.width.has_value(), "width should have no value!");
504-
TORCH_CHECK(
505-
!videoStreamOptions.height.has_value(), "height should have no value!");
506502
outputDims_ =
507503
FrameDims(streamMetadata.width.value(), streamMetadata.height.value());
508504
for (auto& transform : transforms) {

src/torchcodec/_core/StreamOptions.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace facebook::torchcodec {
1414

1515
enum ColorConversionLibrary {
16-
// TODO: Add an AUTO option later.
1716
// Use the libavfilter library for color conversion.
1817
FILTERGRAPH,
1918
// Use the libswscale library for color conversion.
@@ -28,12 +27,17 @@ struct VideoStreamOptions {
2827
// utilize all cores. If not set, it will be the default FFMPEG behavior for
2928
// the given codec.
3029
std::optional<int> ffmpegThreadCount;
30+
3131
// Currently the dimension order can be either NHWC or NCHW.
3232
// H=height, W=width, C=channel.
3333
std::string dimensionOrder = "NCHW";
34-
std::optional<int> width;
35-
std::optional<int> height;
36-
std::optional<ColorConversionLibrary> colorConversionLibrary;
34+
35+
// By default we have to use filtergraph, as it is more general. We can only
36+
// use swscale when we have met strict requirements. See
37+
// CpuDeviceInterface::initialze() for the logic.
38+
ColorConversionLibrary colorConversionLibrary =
39+
ColorConversionLibrary::FILTERGRAPH;
40+
3741
// By default we use CPU for decoding for both C++ and python users.
3842
torch::Device device = torch::kCPU;
3943

0 commit comments

Comments
 (0)