1- #include " VideoReader .h"
2- # include < ATen/ATen.h >
1+ #include " video_reader .h"
2+
33#include < Python.h>
4- #include < c10/util/Logging.h>
5- #include < exception>
6- #include " memory_buffer.h"
7- #include " sync_decoder.h"
84
9- using namespace std ;
10- using namespace ffmpeg ;
5+ # include " ../decoder/memory_buffer.h "
6+ # include " ../decoder/sync_decoder.h "
117
128// If we are in a Windows environment, we need to define
139// initialization functions for the _custom_ops extension
@@ -18,8 +14,13 @@ PyMODINIT_FUNC PyInit_video_reader(void) {
1814}
1915#endif
2016
17+ using namespace ffmpeg ;
18+
19+ namespace vision {
2120namespace video_reader {
2221
22+ namespace {
23+
2324const AVPixelFormat defaultVideoPixelFormat = AV_PIX_FMT_RGB24;
2425const AVSampleFormat defaultAudioSampleFormat = AV_SAMPLE_FMT_FLT;
2526const AVRational timeBaseQ = AVRational{1 , AV_TIME_BASE};
@@ -417,95 +418,6 @@ torch::List<torch::Tensor> readVideo(
417418 return result;
418419}
419420
420- torch::List<torch::Tensor> readVideoFromMemory (
421- torch::Tensor input_video,
422- double seekFrameMargin,
423- int64_t getPtsOnly,
424- int64_t readVideoStream,
425- int64_t width,
426- int64_t height,
427- int64_t minDimension,
428- int64_t maxDimension,
429- int64_t videoStartPts,
430- int64_t videoEndPts,
431- int64_t videoTimeBaseNum,
432- int64_t videoTimeBaseDen,
433- int64_t readAudioStream,
434- int64_t audioSamples,
435- int64_t audioChannels,
436- int64_t audioStartPts,
437- int64_t audioEndPts,
438- int64_t audioTimeBaseNum,
439- int64_t audioTimeBaseDen) {
440- return readVideo (
441- false ,
442- input_video,
443- " " , // videoPath
444- seekFrameMargin,
445- getPtsOnly,
446- readVideoStream,
447- width,
448- height,
449- minDimension,
450- maxDimension,
451- videoStartPts,
452- videoEndPts,
453- videoTimeBaseNum,
454- videoTimeBaseDen,
455- readAudioStream,
456- audioSamples,
457- audioChannels,
458- audioStartPts,
459- audioEndPts,
460- audioTimeBaseNum,
461- audioTimeBaseDen);
462- }
463-
464- torch::List<torch::Tensor> readVideoFromFile (
465- std::string videoPath,
466- double seekFrameMargin,
467- int64_t getPtsOnly,
468- int64_t readVideoStream,
469- int64_t width,
470- int64_t height,
471- int64_t minDimension,
472- int64_t maxDimension,
473- int64_t videoStartPts,
474- int64_t videoEndPts,
475- int64_t videoTimeBaseNum,
476- int64_t videoTimeBaseDen,
477- int64_t readAudioStream,
478- int64_t audioSamples,
479- int64_t audioChannels,
480- int64_t audioStartPts,
481- int64_t audioEndPts,
482- int64_t audioTimeBaseNum,
483- int64_t audioTimeBaseDen) {
484- torch::Tensor dummy_input_video = torch::ones ({0 });
485- return readVideo (
486- true ,
487- dummy_input_video,
488- videoPath,
489- seekFrameMargin,
490- getPtsOnly,
491- readVideoStream,
492- width,
493- height,
494- minDimension,
495- maxDimension,
496- videoStartPts,
497- videoEndPts,
498- videoTimeBaseNum,
499- videoTimeBaseDen,
500- readAudioStream,
501- audioSamples,
502- audioChannels,
503- audioStartPts,
504- audioEndPts,
505- audioTimeBaseNum,
506- audioTimeBaseDen);
507- }
508-
509421torch::List<torch::Tensor> probeVideo (
510422 bool isReadFile,
511423 const torch::Tensor& input_video,
@@ -650,20 +562,112 @@ torch::List<torch::Tensor> probeVideo(
650562 return result;
651563}
652564
653- torch::List<torch::Tensor> probeVideoFromMemory (torch::Tensor input_video) {
565+ } // namespace
566+
567+ torch::List<torch::Tensor> read_video_from_memory (
568+ torch::Tensor input_video,
569+ double seekFrameMargin,
570+ int64_t getPtsOnly,
571+ int64_t readVideoStream,
572+ int64_t width,
573+ int64_t height,
574+ int64_t minDimension,
575+ int64_t maxDimension,
576+ int64_t videoStartPts,
577+ int64_t videoEndPts,
578+ int64_t videoTimeBaseNum,
579+ int64_t videoTimeBaseDen,
580+ int64_t readAudioStream,
581+ int64_t audioSamples,
582+ int64_t audioChannels,
583+ int64_t audioStartPts,
584+ int64_t audioEndPts,
585+ int64_t audioTimeBaseNum,
586+ int64_t audioTimeBaseDen) {
587+ return readVideo (
588+ false ,
589+ input_video,
590+ " " , // videoPath
591+ seekFrameMargin,
592+ getPtsOnly,
593+ readVideoStream,
594+ width,
595+ height,
596+ minDimension,
597+ maxDimension,
598+ videoStartPts,
599+ videoEndPts,
600+ videoTimeBaseNum,
601+ videoTimeBaseDen,
602+ readAudioStream,
603+ audioSamples,
604+ audioChannels,
605+ audioStartPts,
606+ audioEndPts,
607+ audioTimeBaseNum,
608+ audioTimeBaseDen);
609+ }
610+
611+ torch::List<torch::Tensor> read_video_from_file (
612+ std::string videoPath,
613+ double seekFrameMargin,
614+ int64_t getPtsOnly,
615+ int64_t readVideoStream,
616+ int64_t width,
617+ int64_t height,
618+ int64_t minDimension,
619+ int64_t maxDimension,
620+ int64_t videoStartPts,
621+ int64_t videoEndPts,
622+ int64_t videoTimeBaseNum,
623+ int64_t videoTimeBaseDen,
624+ int64_t readAudioStream,
625+ int64_t audioSamples,
626+ int64_t audioChannels,
627+ int64_t audioStartPts,
628+ int64_t audioEndPts,
629+ int64_t audioTimeBaseNum,
630+ int64_t audioTimeBaseDen) {
631+ torch::Tensor dummy_input_video = torch::ones ({0 });
632+ return readVideo (
633+ true ,
634+ dummy_input_video,
635+ videoPath,
636+ seekFrameMargin,
637+ getPtsOnly,
638+ readVideoStream,
639+ width,
640+ height,
641+ minDimension,
642+ maxDimension,
643+ videoStartPts,
644+ videoEndPts,
645+ videoTimeBaseNum,
646+ videoTimeBaseDen,
647+ readAudioStream,
648+ audioSamples,
649+ audioChannels,
650+ audioStartPts,
651+ audioEndPts,
652+ audioTimeBaseNum,
653+ audioTimeBaseDen);
654+ }
655+
656+ torch::List<torch::Tensor> probe_video_from_memory (torch::Tensor input_video) {
654657 return probeVideo (false , input_video, " " );
655658}
656659
657- torch::List<torch::Tensor> probeVideoFromFile (std::string videoPath) {
660+ torch::List<torch::Tensor> probe_video_from_file (std::string videoPath) {
658661 torch::Tensor dummy_input_video = torch::ones ({0 });
659662 return probeVideo (true , dummy_input_video, videoPath);
660663}
661664
662- } // namespace video_reader
663-
664665TORCH_LIBRARY_FRAGMENT (video_reader, m) {
665- m.def (" read_video_from_memory" , video_reader::readVideoFromMemory );
666- m.def (" read_video_from_file" , video_reader::readVideoFromFile );
667- m.def (" probe_video_from_memory" , video_reader::probeVideoFromMemory );
668- m.def (" probe_video_from_file" , video_reader::probeVideoFromFile );
666+ m.def (" read_video_from_memory" , read_video_from_memory );
667+ m.def (" read_video_from_file" , read_video_from_file );
668+ m.def (" probe_video_from_memory" , probe_video_from_memory );
669+ m.def (" probe_video_from_file" , probe_video_from_file );
669670}
671+
672+ } // namespace video_reader
673+ } // namespace vision
0 commit comments