2
2
3
3
#include < Python.h>
4
4
5
+ #include " ../decoder/memory_buffer.h"
6
+ #include " ../decoder/sync_decoder.h"
7
+
5
8
// If we are in a Windows environment, we need to define
6
9
// initialization functions for the _custom_ops extension
7
10
#ifdef _WIN32
@@ -11,11 +14,13 @@ PyMODINIT_FUNC PyInit_video_reader(void) {
11
14
}
12
15
#endif
13
16
14
- using namespace std ;
15
17
using namespace ffmpeg ;
16
18
19
+ namespace vision {
17
20
namespace video_reader {
18
21
22
+ namespace {
23
+
19
24
const AVPixelFormat defaultVideoPixelFormat = AV_PIX_FMT_RGB24;
20
25
const AVSampleFormat defaultAudioSampleFormat = AV_SAMPLE_FMT_FLT;
21
26
const AVRational timeBaseQ = AVRational{1 , AV_TIME_BASE};
@@ -413,95 +418,6 @@ torch::List<torch::Tensor> readVideo(
413
418
return result;
414
419
}
415
420
416
- torch::List<torch::Tensor> readVideoFromMemory (
417
- torch::Tensor input_video,
418
- double seekFrameMargin,
419
- int64_t getPtsOnly,
420
- int64_t readVideoStream,
421
- int64_t width,
422
- int64_t height,
423
- int64_t minDimension,
424
- int64_t maxDimension,
425
- int64_t videoStartPts,
426
- int64_t videoEndPts,
427
- int64_t videoTimeBaseNum,
428
- int64_t videoTimeBaseDen,
429
- int64_t readAudioStream,
430
- int64_t audioSamples,
431
- int64_t audioChannels,
432
- int64_t audioStartPts,
433
- int64_t audioEndPts,
434
- int64_t audioTimeBaseNum,
435
- int64_t audioTimeBaseDen) {
436
- return readVideo (
437
- false ,
438
- input_video,
439
- " " , // videoPath
440
- seekFrameMargin,
441
- getPtsOnly,
442
- readVideoStream,
443
- width,
444
- height,
445
- minDimension,
446
- maxDimension,
447
- videoStartPts,
448
- videoEndPts,
449
- videoTimeBaseNum,
450
- videoTimeBaseDen,
451
- readAudioStream,
452
- audioSamples,
453
- audioChannels,
454
- audioStartPts,
455
- audioEndPts,
456
- audioTimeBaseNum,
457
- audioTimeBaseDen);
458
- }
459
-
460
- torch::List<torch::Tensor> readVideoFromFile (
461
- std::string videoPath,
462
- double seekFrameMargin,
463
- int64_t getPtsOnly,
464
- int64_t readVideoStream,
465
- int64_t width,
466
- int64_t height,
467
- int64_t minDimension,
468
- int64_t maxDimension,
469
- int64_t videoStartPts,
470
- int64_t videoEndPts,
471
- int64_t videoTimeBaseNum,
472
- int64_t videoTimeBaseDen,
473
- int64_t readAudioStream,
474
- int64_t audioSamples,
475
- int64_t audioChannels,
476
- int64_t audioStartPts,
477
- int64_t audioEndPts,
478
- int64_t audioTimeBaseNum,
479
- int64_t audioTimeBaseDen) {
480
- torch::Tensor dummy_input_video = torch::ones ({0 });
481
- return readVideo (
482
- true ,
483
- dummy_input_video,
484
- videoPath,
485
- seekFrameMargin,
486
- getPtsOnly,
487
- readVideoStream,
488
- width,
489
- height,
490
- minDimension,
491
- maxDimension,
492
- videoStartPts,
493
- videoEndPts,
494
- videoTimeBaseNum,
495
- videoTimeBaseDen,
496
- readAudioStream,
497
- audioSamples,
498
- audioChannels,
499
- audioStartPts,
500
- audioEndPts,
501
- audioTimeBaseNum,
502
- audioTimeBaseDen);
503
- }
504
-
505
421
torch::List<torch::Tensor> probeVideo (
506
422
bool isReadFile,
507
423
const torch::Tensor& input_video,
@@ -646,6 +562,97 @@ torch::List<torch::Tensor> probeVideo(
646
562
return result;
647
563
}
648
564
565
+ } // namespace
566
+
567
+ torch::List<torch::Tensor> readVideoFromMemory (
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> readVideoFromFile (
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
+
649
656
torch::List<torch::Tensor> probeVideoFromMemory (torch::Tensor input_video) {
650
657
return probeVideo (false , input_video, " " );
651
658
}
@@ -655,11 +662,12 @@ torch::List<torch::Tensor> probeVideoFromFile(std::string videoPath) {
655
662
return probeVideo (true , dummy_input_video, videoPath);
656
663
}
657
664
658
- } // namespace video_reader
659
-
660
665
TORCH_LIBRARY_FRAGMENT (video_reader, m) {
661
- m.def (" read_video_from_memory" , video_reader:: readVideoFromMemory);
662
- m.def (" read_video_from_file" , video_reader:: readVideoFromFile);
663
- m.def (" probe_video_from_memory" , video_reader:: probeVideoFromMemory);
664
- m.def (" probe_video_from_file" , video_reader:: probeVideoFromFile);
666
+ m.def (" read_video_from_memory" , readVideoFromMemory);
667
+ m.def (" read_video_from_file" , readVideoFromFile);
668
+ m.def (" probe_video_from_memory" , probeVideoFromMemory);
669
+ m.def (" probe_video_from_file" , probeVideoFromFile);
665
670
}
671
+
672
+ } // namespace video_reader
673
+ } // namespace vision
0 commit comments