@@ -216,7 +216,22 @@ bool VideoDecoder::SwsContextKey::operator!=(
216216 return !(*this == other);
217217}
218218
219- VideoDecoder::VideoDecoder () {}
219+ VideoDecoder::VideoDecoder (const std::string& videoFilePath) {
220+ AVInput input = createAVFormatContextFromFilePath (videoFilePath);
221+ formatContext_ = std::move (input.formatContext );
222+
223+ initializeDecoder ();
224+ }
225+
226+ VideoDecoder::VideoDecoder (const void * buffer, size_t length) {
227+ TORCH_CHECK (buffer != nullptr , " Video buffer cannot be nullptr!" );
228+
229+ AVInput input = createAVFormatContextFromBuffer (buffer, length);
230+ formatContext_ = std::move (input.formatContext );
231+ ioBytesContext_ = std::move (input.ioBytesContext );
232+
233+ initializeDecoder ();
234+ }
220235
221236void VideoDecoder::initializeDecoder () {
222237 // Some formats don't store enough info in the header so we read/decode a few
@@ -275,28 +290,14 @@ void VideoDecoder::initializeDecoder() {
275290}
276291
277292std::unique_ptr<VideoDecoder> VideoDecoder::createFromFilePath (
278- const std::string& videoFilePath,
279- const VideoDecoder::DecoderOptions& options) {
280- AVInput input = createAVFormatContextFromFilePath (videoFilePath);
281- std::unique_ptr<VideoDecoder> decoder (new VideoDecoder ());
282- decoder->formatContext_ = std::move (input.formatContext );
283- decoder->options_ = options;
284- decoder->initializeDecoder ();
285- return decoder;
293+ const std::string& videoFilePath) {
294+ return std::unique_ptr<VideoDecoder>(new VideoDecoder (videoFilePath));
286295}
287296
288297std::unique_ptr<VideoDecoder> VideoDecoder::createFromBuffer (
289298 const void * buffer,
290- size_t length,
291- const VideoDecoder::DecoderOptions& options) {
292- TORCH_CHECK (buffer != nullptr , " Video buffer cannot be nullptr!" );
293- AVInput input = createAVFormatContextFromBuffer (buffer, length);
294- std::unique_ptr<VideoDecoder> decoder (new VideoDecoder ());
295- decoder->formatContext_ = std::move (input.formatContext );
296- decoder->ioBytesContext_ = std::move (input.ioBytesContext );
297- decoder->options_ = options;
298- decoder->initializeDecoder ();
299- return decoder;
299+ size_t length) {
300+ return std::unique_ptr<VideoDecoder>(new VideoDecoder (buffer, length));
300301}
301302
302303void VideoDecoder::initializeFilterGraph (
0 commit comments