Skip to content

Commit 4d894d5

Browse files
authored
Remove VideoStreamOptions string constructor (#577)
1 parent 3b473a3 commit 4d894d5

File tree

3 files changed

+11
-78
lines changed

3 files changed

+11
-78
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,6 @@ int64_t secondsToClosestPts(double seconds, const AVRational& timeBase) {
4343
return static_cast<int64_t>(std::round(seconds * timeBase.den));
4444
}
4545

46-
std::vector<std::string> splitStringWithDelimiters(
47-
const std::string& str,
48-
const std::string& delims) {
49-
std::vector<std::string> result;
50-
if (str.empty()) {
51-
return result;
52-
}
53-
54-
std::string::size_type start = 0, end = 0;
55-
while ((end = str.find_first_of(delims, start)) != std::string::npos) {
56-
result.push_back(str.substr(start, end - start));
57-
start = end + 1;
58-
}
59-
result.push_back(str.substr(start));
60-
return result;
61-
}
62-
6346
} // namespace
6447

6548
// --------------------------------------------------------------------------
@@ -395,57 +378,6 @@ torch::Tensor VideoDecoder::getKeyFrameIndices() {
395378
// ADDING STREAMS API
396379
// --------------------------------------------------------------------------
397380

398-
VideoDecoder::VideoStreamOptions::VideoStreamOptions(
399-
const std::string& optionsString) {
400-
std::vector<std::string> tokens =
401-
splitStringWithDelimiters(optionsString, ",");
402-
for (auto token : tokens) {
403-
std::vector<std::string> pairs = splitStringWithDelimiters(token, "=");
404-
if (pairs.size() != 2) {
405-
throw std::runtime_error(
406-
"Invalid option: " + token +
407-
". Options must be in the form 'option=value'.");
408-
}
409-
std::string key = pairs[0];
410-
std::string value = pairs[1];
411-
if (key == "ffmpeg_thread_count") {
412-
ffmpegThreadCount = std::stoi(value);
413-
if (ffmpegThreadCount < 0) {
414-
throw std::runtime_error(
415-
"Invalid ffmpeg_thread_count=" + value +
416-
". ffmpeg_thread_count must be >= 0.");
417-
}
418-
} else if (key == "dimension_order") {
419-
if (value != "NHWC" && value != "NCHW") {
420-
throw std::runtime_error(
421-
"Invalid dimension_order=" + value +
422-
". dimensionOrder must be either NHWC or NCHW.");
423-
}
424-
dimensionOrder = value;
425-
} else if (key == "width") {
426-
width = std::stoi(value);
427-
} else if (key == "height") {
428-
height = std::stoi(value);
429-
} else if (key == "color_conversion_library") {
430-
if (value == "filtergraph") {
431-
colorConversionLibrary = ColorConversionLibrary::FILTERGRAPH;
432-
} else if (value == "swscale") {
433-
colorConversionLibrary = ColorConversionLibrary::SWSCALE;
434-
} else {
435-
throw std::runtime_error(
436-
"Invalid color_conversion_library=" + value +
437-
". color_conversion_library must be either "
438-
"filtergraph or swscale.");
439-
}
440-
} else {
441-
throw std::runtime_error(
442-
"Invalid option: " + key +
443-
". Valid options are: "
444-
"ffmpeg_thread_count=<int>,dimension_order=<string>");
445-
}
446-
}
447-
}
448-
449381
void VideoDecoder::addStream(
450382
int streamIndex,
451383
AVMediaType mediaType,

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ class VideoDecoder {
121121
struct VideoStreamOptions {
122122
VideoStreamOptions() {}
123123

124-
explicit VideoStreamOptions(const std::string& optionsString);
125124
// Number of threads we pass to FFMPEG for decoding.
126125
// 0 means FFMPEG will choose the number of threads automatically to fully
127126
// utilize all cores. If not set, it will be the default FFMPEG behavior for

test/decoders/VideoDecoderTest.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ TEST_P(VideoDecoderTest, DecodesFramesInABatchInNHWC) {
227227
ourDecoder->scanFileAndUpdateMetadataAndIndex();
228228
int bestVideoStreamIndex =
229229
*ourDecoder->getContainerMetadata().bestVideoStreamIndex;
230-
ourDecoder->addVideoStream(
231-
bestVideoStreamIndex,
232-
VideoDecoder::VideoStreamOptions("dimension_order=NHWC"));
230+
VideoDecoder::VideoStreamOptions videoStreamOptions;
231+
videoStreamOptions.dimensionOrder = "NHWC";
232+
ourDecoder->addVideoStream(bestVideoStreamIndex, videoStreamOptions);
233233
// Frame with index 180 corresponds to timestamp 6.006.
234234
auto output = ourDecoder->getFramesAtIndices({0, 180});
235235
auto tensor = output.data;
@@ -392,9 +392,10 @@ TEST_P(VideoDecoderTest, PreAllocatedTensorFilterGraph) {
392392
ourDecoder->scanFileAndUpdateMetadataAndIndex();
393393
int bestVideoStreamIndex =
394394
*ourDecoder->getContainerMetadata().bestVideoStreamIndex;
395-
ourDecoder->addVideoStream(
396-
bestVideoStreamIndex,
397-
VideoDecoder::VideoStreamOptions("color_conversion_library=filtergraph"));
395+
VideoDecoder::VideoStreamOptions videoStreamOptions;
396+
videoStreamOptions.colorConversionLibrary =
397+
VideoDecoder::ColorConversionLibrary::FILTERGRAPH;
398+
ourDecoder->addVideoStream(bestVideoStreamIndex, videoStreamOptions);
398399
auto output =
399400
ourDecoder->getFrameAtIndexInternal(0, preAllocatedOutputTensor);
400401
EXPECT_EQ(output.data.data_ptr(), preAllocatedOutputTensor.data_ptr());
@@ -409,9 +410,10 @@ TEST_P(VideoDecoderTest, PreAllocatedTensorSwscale) {
409410
ourDecoder->scanFileAndUpdateMetadataAndIndex();
410411
int bestVideoStreamIndex =
411412
*ourDecoder->getContainerMetadata().bestVideoStreamIndex;
412-
ourDecoder->addVideoStream(
413-
bestVideoStreamIndex,
414-
VideoDecoder::VideoStreamOptions("color_conversion_library=swscale"));
413+
VideoDecoder::VideoStreamOptions videoStreamOptions;
414+
videoStreamOptions.colorConversionLibrary =
415+
VideoDecoder::ColorConversionLibrary::SWSCALE;
416+
ourDecoder->addVideoStream(bestVideoStreamIndex, videoStreamOptions);
415417
auto output =
416418
ourDecoder->getFrameAtIndexInternal(0, preAllocatedOutputTensor);
417419
EXPECT_EQ(output.data.data_ptr(), preAllocatedOutputTensor.data_ptr());

0 commit comments

Comments
 (0)