Skip to content

Commit 14cbbab

Browse files
committed
add read from memory with constructor overload
1 parent 23eff89 commit 14cbbab

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ def get_extensions():
351351
# FIXME: causes crash. See the following GitHub issues for more details.
352352
# FIXME: https://github.com/pytorch/pytorch/issues/65000
353353
# FIXME: https://github.com/pytorch/vision/issues/3367
354-
if sys.platform != "linux" or (sys.version_info.major == 3 and sys.version_info.minor == 9):
355-
has_ffmpeg = False
354+
# if sys.platform != "linux" or (sys.version_info.major == 3 and sys.version_info.minor == 9):
355+
# has_ffmpeg = False
356356
if has_ffmpeg:
357357
try:
358358
# This is to check if ffmpeg is installed properly.

torchvision/csrc/io/video/video.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void Video::_getDecoderParams(
156156

157157
} // _get decoder params
158158

159-
Video::Video(std::string videoPath, std::string stream, int64_t numThreads) {
159+
void Video::_init(std::string stream, int64_t numThreads) {
160160
C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.video.video.Video");
161161
// set number of threads global
162162
numThreads_ = numThreads;
@@ -173,13 +173,6 @@ Video::Video(std::string videoPath, std::string stream, int64_t numThreads) {
173173
numThreads_ // global number of Threads for decoding
174174
);
175175

176-
std::string logMessage, logType;
177-
178-
// TODO: add read from memory option
179-
params.uri = videoPath;
180-
logType = "file";
181-
logMessage = videoPath;
182-
183176
// locals
184177
std::vector<double> audioFPS, videoFPS;
185178
std::vector<double> audioDuration, videoDuration, ccDuration, subsDuration;
@@ -232,7 +225,18 @@ Video::Video(std::string videoPath, std::string stream, int64_t numThreads) {
232225
<< "Stream index set to " << std::get<1>(current_stream)
233226
<< ". If you encounter trouble, consider switching it to automatic stream discovery. \n";
234227
}
235-
} // video
228+
} // Video::Init
229+
230+
231+
Video::Video(torch::Tensor videoData, std::string stream, int64_t numThreads) {
232+
callback = MemoryBuffer::getCallback(videoData.data_ptr<uint8_t>(), videoData.size(0));
233+
Video::_init(stream, numThreads);
234+
}
235+
236+
Video::Video(std::string videoPath, std::string stream, int64_t numThreads) {
237+
params.uri = videoPath;
238+
Video::_init(stream, numThreads);
239+
}
236240

237241
bool Video::setCurrentStream(std::string stream = "video") {
238242
if ((!stream.empty()) && (_parseStream(stream) != current_stream)) {

torchvision/csrc/io/video/video.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct Video : torch::CustomClassHolder {
2020

2121
public:
2222
Video(std::string videoPath, std::string stream, int64_t numThreads);
23+
Video(torch::Tensor videoData, std::string stream, int64_t numThreads);
24+
2325
std::tuple<std::string, int64_t> getCurrentStream() const;
2426
c10::Dict<std::string, c10::Dict<std::string, std::vector<double>>>
2527
getStreamMetadata() const;
@@ -34,6 +36,8 @@ struct Video : torch::CustomClassHolder {
3436
// time in comination with any_frame settings
3537
double seekTS = -1;
3638

39+
void _init(std::string stream, int64_t numThreads);
40+
3741
void _getDecoderParams(
3842
double videoStartS,
3943
int64_t getPtsOnly,

0 commit comments

Comments
 (0)