Skip to content

Commit 1670dc6

Browse files
committed
Merge branch 'main' of github.com:pytorch/torchcodec into get_key_indices
2 parents ef644f9 + f46f64a commit 1670dc6

File tree

4 files changed

+12
-33
lines changed

4 files changed

+12
-33
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,21 +318,6 @@ void VideoDecoder::initializeDecoder() {
318318
initialized_ = true;
319319
}
320320

321-
std::unique_ptr<VideoDecoder> VideoDecoder::createFromFilePath(
322-
const std::string& videoFilePath,
323-
SeekMode seekMode) {
324-
return std::unique_ptr<VideoDecoder>(
325-
new VideoDecoder(videoFilePath, seekMode));
326-
}
327-
328-
std::unique_ptr<VideoDecoder> VideoDecoder::createFromBuffer(
329-
const void* buffer,
330-
size_t length,
331-
SeekMode seekMode) {
332-
return std::unique_ptr<VideoDecoder>(
333-
new VideoDecoder(buffer, length, seekMode));
334-
}
335-
336321
void VideoDecoder::createFilterGraph(
337322
StreamInfo& streamInfo,
338323
int expectedOutputHeight,

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ class VideoDecoder {
2929

3030
enum class SeekMode { exact, approximate };
3131

32-
explicit VideoDecoder(const std::string& videoFilePath, SeekMode seekMode);
33-
explicit VideoDecoder(const void* buffer, size_t length, SeekMode seekMode);
34-
3532
// Creates a VideoDecoder from the video at videoFilePath.
36-
static std::unique_ptr<VideoDecoder> createFromFilePath(
33+
explicit VideoDecoder(
3734
const std::string& videoFilePath,
3835
SeekMode seekMode = SeekMode::exact);
3936

4037
// Creates a VideoDecoder from a given buffer. Note that the buffer is not
4138
// owned by the VideoDecoder.
42-
static std::unique_ptr<VideoDecoder> createFromBuffer(
39+
explicit VideoDecoder(
4340
const void* buffer,
4441
size_t length,
4542
SeekMode seekMode = SeekMode::exact);

src/torchcodec/decoders/_core/VideoDecoderOps.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ at::Tensor create_from_file(
119119
}
120120

121121
std::unique_ptr<VideoDecoder> uniqueDecoder =
122-
VideoDecoder::createFromFilePath(filenameStr, realSeek);
122+
std::make_unique<VideoDecoder>(filenameStr, realSeek);
123123

124124
return wrapDecoderPointerToTensor(std::move(uniqueDecoder));
125125
}
@@ -136,9 +136,9 @@ at::Tensor create_from_tensor(
136136
realSeek = seekModeFromString(seek_mode.value());
137137
}
138138

139-
std::unique_ptr<VideoDecoder> videoDecoder =
140-
VideoDecoder::createFromBuffer(buffer, length, realSeek);
141-
return wrapDecoderPointerToTensor(std::move(videoDecoder));
139+
std::unique_ptr<VideoDecoder> uniqueDecoder =
140+
std::make_unique<VideoDecoder>(buffer, length, realSeek);
141+
return wrapDecoderPointerToTensor(std::move(uniqueDecoder));
142142
}
143143

144144
at::Tensor create_from_buffer(
@@ -151,7 +151,7 @@ at::Tensor create_from_buffer(
151151
}
152152

153153
std::unique_ptr<VideoDecoder> uniqueDecoder =
154-
VideoDecoder::createFromBuffer(buffer, length, realSeek);
154+
std::make_unique<VideoDecoder>(buffer, length, realSeek);
155155
return wrapDecoderPointerToTensor(std::move(uniqueDecoder));
156156
}
157157

test/decoders/VideoDecoderTest.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class VideoDecoderTest : public testing::TestWithParam<bool> {
5050
content_ = outputStringStream.str();
5151
void* buffer = content_.data();
5252
size_t length = outputStringStream.str().length();
53-
return VideoDecoder::createFromBuffer(
53+
return std::make_unique<VideoDecoder>(
5454
buffer, length, VideoDecoder::SeekMode::approximate);
5555
} else {
56-
return VideoDecoder::createFromFilePath(
56+
return std::make_unique<VideoDecoder>(
5757
filepath, VideoDecoder::SeekMode::approximate);
5858
}
5959
}
@@ -94,8 +94,7 @@ TEST_P(VideoDecoderTest, ReturnsFpsAndDurationForVideoInMetadata) {
9494

9595
TEST(VideoDecoderTest, MissingVideoFileThrowsException) {
9696
EXPECT_THROW(
97-
VideoDecoder::createFromFilePath("/this/file/does/not/exist"),
98-
std::invalid_argument);
97+
VideoDecoder("/this/file/does/not/exist"), std::invalid_argument);
9998
}
10099

101100
void dumpTensorToDisk(
@@ -145,8 +144,7 @@ double computeAverageCosineSimilarity(
145144

146145
TEST(VideoDecoderTest, RespectsWidthAndHeightFromOptions) {
147146
std::string path = getResourcePath("nasa_13013.mp4");
148-
std::unique_ptr<VideoDecoder> decoder =
149-
VideoDecoder::createFromFilePath(path);
147+
std::unique_ptr<VideoDecoder> decoder = std::make_unique<VideoDecoder>(path);
150148
VideoDecoder::VideoStreamOptions videoStreamOptions;
151149
videoStreamOptions.width = 100;
152150
videoStreamOptions.height = 120;
@@ -157,8 +155,7 @@ TEST(VideoDecoderTest, RespectsWidthAndHeightFromOptions) {
157155

158156
TEST(VideoDecoderTest, RespectsOutputTensorDimensionOrderFromOptions) {
159157
std::string path = getResourcePath("nasa_13013.mp4");
160-
std::unique_ptr<VideoDecoder> decoder =
161-
VideoDecoder::createFromFilePath(path);
158+
std::unique_ptr<VideoDecoder> decoder = std::make_unique<VideoDecoder>(path);
162159
VideoDecoder::VideoStreamOptions videoStreamOptions;
163160
videoStreamOptions.dimensionOrder = "NHWC";
164161
decoder->addVideoStreamDecoder(-1, videoStreamOptions);

0 commit comments

Comments
 (0)