video.h 1.61 KB
Newer Older
1
2
#pragma once

3
#include <torch/types.h>
4

5
6
7
#include "../decoder/defs.h"
#include "../decoder/memory_buffer.h"
#include "../decoder/sync_decoder.h"
8
9
10

using namespace ffmpeg;

11
12
13
namespace vision {
namespace video {

14
15
16
17
18
struct Video : torch::CustomClassHolder {
  std::tuple<std::string, long> current_stream; // stream type, id
  // global video metadata
  c10::Dict<std::string, c10::Dict<std::string, std::vector<double>>>
      streamsMetadata;
19
  int64_t numThreads_{0};
20
21

 public:
22
  Video(std::string videoPath, std::string stream, int64_t numThreads);
23
24
25
  std::tuple<std::string, int64_t> getCurrentStream() const;
  c10::Dict<std::string, c10::Dict<std::string, std::vector<double>>>
  getStreamMetadata() const;
26
  void Seek(double ts, bool fastSeek);
27
  bool setCurrentStream(std::string stream);
28
29
30
31
32
33
34
35
36
37
38
39
40
  std::tuple<torch::Tensor, double> Next();

 private:
  bool succeeded = false; // decoder init flag
  // seekTS and doSeek act as a flag - if it's not set, next function simply
  // retruns the next frame. If it's set, we look at the global seek
  // time in comination with any_frame settings
  double seekTS = -1;

  void _getDecoderParams(
      double videoStartS,
      int64_t getPtsOnly,
      std::string stream,
41
      long stream_id,
42
      bool fastSeek,
43
      bool all_streams,
44
      int64_t num_threads,
45
      double seekFrameMarginUs); // this needs to be improved
46
47
48
49
50
51
52
53
54
55
56

  std::map<std::string, std::vector<double>> streamTimeBase; // not used

  DecoderInCallback callback = nullptr;
  std::vector<DecoderMetadata> metadata;

 protected:
  SyncDecoder decoder;
  DecoderParameters params;

}; // struct Video
57
58
59

} // namespace video
} // namespace vision