Debian Codegraph @

cvd/videoreader.h

raw symbols SCIP
1 #ifndef LIBCVD_VIDEOREADER_H
2 #define LIBCVD_VIDEOREADER_H
3
4 #include "image.h"
5 #include "image_ref.h"
6 #include "rgba.h"
7 #include "videoffmpeg.h"
8
9 #include <libavutil/rational.h>
10
11 #include <cstdint>
12 #include <memory>
13 #include <string>
14 #include <utility>
15
16 namespace CVD
17 {
18 namespace internal
19 {
20 class Scaler;
21 }
22
23 // Reads video files using FFmpeg as RGBA frames.
24 class VideoReader
25 {
26 public:
27 VideoReader(const std::string& filename, int threads = 1);
28 ~VideoReader();
29
30 // Convert an FFmpeg timestamp from the video stream to seconds since the start of the video.
31 double timebase_to_seconds(std::int64_t pts) const;
32 // Get the timebase of the video.
33 AVRational timebase() const;
34 // Get the size of each video frame, in pixels.
35 ImageRef size() const;
36 // Get the frame rate of the video.
37 AVRational frame_rate() const;
38 // Get the duration of the video, in the video timebase.
39 std::int64_t duration() const;
40 // Read the next frame from the video as an RGBA frame and timestamp in the video timebase.
41 // Returns an empty image if there are no more frames in the video.
42 std::pair<Image<Rgba<std::uint8_t>>, std::int64_t> get_frame();
43
44 private:
45 std::unique_ptr<AVFormatContext, internal::AVFormatContextCloser> m_format_context;
46 std::unique_ptr<AVCodecContext, internal::AVCodecContextCloser> m_codec_context;
47 std::unique_ptr<internal::Scaler> m_scaler;
48 std::unique_ptr<AVFrame, internal::AVFrameDeleter> m_raw_frame;
49 int m_stream_index = -1;
50 };
51
52 }
53
54 #endif