-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Restructure the video/video_reader C++ codebase #3311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f202440
94a8192
5828cfd
9f8ca89
4802cde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
#include "VideoReader.h" | ||
#include <ATen/ATen.h> | ||
#include "video_reader.h" | ||
|
||
#include <Python.h> | ||
#include <c10/util/Logging.h> | ||
#include <exception> | ||
#include "memory_buffer.h" | ||
#include "sync_decoder.h" | ||
|
||
using namespace std; | ||
using namespace ffmpeg; | ||
#include "../decoder/memory_buffer.h" | ||
#include "../decoder/sync_decoder.h" | ||
|
||
// If we are in a Windows environment, we need to define | ||
// initialization functions for the _custom_ops extension | ||
|
@@ -18,8 +14,13 @@ PyMODINIT_FUNC PyInit_video_reader(void) { | |
} | ||
#endif | ||
|
||
using namespace ffmpeg; | ||
|
||
namespace vision { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow similar pattern as |
||
namespace video_reader { | ||
|
||
namespace { | ||
|
||
const AVPixelFormat defaultVideoPixelFormat = AV_PIX_FMT_RGB24; | ||
const AVSampleFormat defaultAudioSampleFormat = AV_SAMPLE_FMT_FLT; | ||
const AVRational timeBaseQ = AVRational{1, AV_TIME_BASE}; | ||
|
@@ -417,95 +418,6 @@ torch::List<torch::Tensor> readVideo( | |
return result; | ||
} | ||
|
||
torch::List<torch::Tensor> readVideoFromMemory( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving out of the anonymous namespace. |
||
torch::Tensor input_video, | ||
double seekFrameMargin, | ||
int64_t getPtsOnly, | ||
int64_t readVideoStream, | ||
int64_t width, | ||
int64_t height, | ||
int64_t minDimension, | ||
int64_t maxDimension, | ||
int64_t videoStartPts, | ||
int64_t videoEndPts, | ||
int64_t videoTimeBaseNum, | ||
int64_t videoTimeBaseDen, | ||
int64_t readAudioStream, | ||
int64_t audioSamples, | ||
int64_t audioChannels, | ||
int64_t audioStartPts, | ||
int64_t audioEndPts, | ||
int64_t audioTimeBaseNum, | ||
int64_t audioTimeBaseDen) { | ||
return readVideo( | ||
false, | ||
input_video, | ||
"", // videoPath | ||
seekFrameMargin, | ||
getPtsOnly, | ||
readVideoStream, | ||
width, | ||
height, | ||
minDimension, | ||
maxDimension, | ||
videoStartPts, | ||
videoEndPts, | ||
videoTimeBaseNum, | ||
videoTimeBaseDen, | ||
readAudioStream, | ||
audioSamples, | ||
audioChannels, | ||
audioStartPts, | ||
audioEndPts, | ||
audioTimeBaseNum, | ||
audioTimeBaseDen); | ||
} | ||
|
||
torch::List<torch::Tensor> readVideoFromFile( | ||
std::string videoPath, | ||
double seekFrameMargin, | ||
int64_t getPtsOnly, | ||
int64_t readVideoStream, | ||
int64_t width, | ||
int64_t height, | ||
int64_t minDimension, | ||
int64_t maxDimension, | ||
int64_t videoStartPts, | ||
int64_t videoEndPts, | ||
int64_t videoTimeBaseNum, | ||
int64_t videoTimeBaseDen, | ||
int64_t readAudioStream, | ||
int64_t audioSamples, | ||
int64_t audioChannels, | ||
int64_t audioStartPts, | ||
int64_t audioEndPts, | ||
int64_t audioTimeBaseNum, | ||
int64_t audioTimeBaseDen) { | ||
torch::Tensor dummy_input_video = torch::ones({0}); | ||
return readVideo( | ||
true, | ||
dummy_input_video, | ||
videoPath, | ||
seekFrameMargin, | ||
getPtsOnly, | ||
readVideoStream, | ||
width, | ||
height, | ||
minDimension, | ||
maxDimension, | ||
videoStartPts, | ||
videoEndPts, | ||
videoTimeBaseNum, | ||
videoTimeBaseDen, | ||
readAudioStream, | ||
audioSamples, | ||
audioChannels, | ||
audioStartPts, | ||
audioEndPts, | ||
audioTimeBaseNum, | ||
audioTimeBaseDen); | ||
} | ||
|
||
torch::List<torch::Tensor> probeVideo( | ||
bool isReadFile, | ||
const torch::Tensor& input_video, | ||
|
@@ -650,20 +562,112 @@ torch::List<torch::Tensor> probeVideo( | |
return result; | ||
} | ||
|
||
torch::List<torch::Tensor> probeVideoFromMemory(torch::Tensor input_video) { | ||
} // namespace | ||
|
||
torch::List<torch::Tensor> read_video_from_memory( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "public" methods. |
||
torch::Tensor input_video, | ||
double seekFrameMargin, | ||
int64_t getPtsOnly, | ||
int64_t readVideoStream, | ||
int64_t width, | ||
int64_t height, | ||
int64_t minDimension, | ||
int64_t maxDimension, | ||
int64_t videoStartPts, | ||
int64_t videoEndPts, | ||
int64_t videoTimeBaseNum, | ||
int64_t videoTimeBaseDen, | ||
int64_t readAudioStream, | ||
int64_t audioSamples, | ||
int64_t audioChannels, | ||
int64_t audioStartPts, | ||
int64_t audioEndPts, | ||
int64_t audioTimeBaseNum, | ||
int64_t audioTimeBaseDen) { | ||
return readVideo( | ||
false, | ||
input_video, | ||
"", // videoPath | ||
seekFrameMargin, | ||
getPtsOnly, | ||
readVideoStream, | ||
width, | ||
height, | ||
minDimension, | ||
maxDimension, | ||
videoStartPts, | ||
videoEndPts, | ||
videoTimeBaseNum, | ||
videoTimeBaseDen, | ||
readAudioStream, | ||
audioSamples, | ||
audioChannels, | ||
audioStartPts, | ||
audioEndPts, | ||
audioTimeBaseNum, | ||
audioTimeBaseDen); | ||
} | ||
|
||
torch::List<torch::Tensor> read_video_from_file( | ||
std::string videoPath, | ||
double seekFrameMargin, | ||
int64_t getPtsOnly, | ||
int64_t readVideoStream, | ||
int64_t width, | ||
int64_t height, | ||
int64_t minDimension, | ||
int64_t maxDimension, | ||
int64_t videoStartPts, | ||
int64_t videoEndPts, | ||
int64_t videoTimeBaseNum, | ||
int64_t videoTimeBaseDen, | ||
int64_t readAudioStream, | ||
int64_t audioSamples, | ||
int64_t audioChannels, | ||
int64_t audioStartPts, | ||
int64_t audioEndPts, | ||
int64_t audioTimeBaseNum, | ||
int64_t audioTimeBaseDen) { | ||
torch::Tensor dummy_input_video = torch::ones({0}); | ||
return readVideo( | ||
true, | ||
dummy_input_video, | ||
videoPath, | ||
seekFrameMargin, | ||
getPtsOnly, | ||
readVideoStream, | ||
width, | ||
height, | ||
minDimension, | ||
maxDimension, | ||
videoStartPts, | ||
videoEndPts, | ||
videoTimeBaseNum, | ||
videoTimeBaseDen, | ||
readAudioStream, | ||
audioSamples, | ||
audioChannels, | ||
audioStartPts, | ||
audioEndPts, | ||
audioTimeBaseNum, | ||
audioTimeBaseDen); | ||
} | ||
|
||
torch::List<torch::Tensor> probe_video_from_memory(torch::Tensor input_video) { | ||
return probeVideo(false, input_video, ""); | ||
} | ||
|
||
torch::List<torch::Tensor> probeVideoFromFile(std::string videoPath) { | ||
torch::List<torch::Tensor> probe_video_from_file(std::string videoPath) { | ||
torch::Tensor dummy_input_video = torch::ones({0}); | ||
return probeVideo(true, dummy_input_video, videoPath); | ||
} | ||
|
||
} // namespace video_reader | ||
|
||
TORCH_LIBRARY_FRAGMENT(video_reader, m) { | ||
m.def("read_video_from_memory", video_reader::readVideoFromMemory); | ||
m.def("read_video_from_file", video_reader::readVideoFromFile); | ||
m.def("probe_video_from_memory", video_reader::probeVideoFromMemory); | ||
m.def("probe_video_from_file", video_reader::probeVideoFromFile); | ||
m.def("read_video_from_memory", read_video_from_memory); | ||
m.def("read_video_from_file", read_video_from_file); | ||
m.def("probe_video_from_memory", probe_video_from_memory); | ||
m.def("probe_video_from_file", probe_video_from_file); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Registration of methods within the namespaces at the end of the file. |
||
} | ||
|
||
} // namespace video_reader | ||
} // namespace vision |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from register.cpp