| 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 |
|
| 24 |
class VideoReader |
| 25 |
{ |
| 26 |
public: |
| 27 |
VideoReader(const std::string& filename, int threads = 1); |
| 28 |
~VideoReader(); |
| 29 |
|
| 30 |
|
| 31 |
double timebase_to_seconds(std::int64_t pts) const; |
| 32 |
|
| 33 |
AVRational timebase() const; |
| 34 |
|
| 35 |
ImageRef size() const; |
| 36 |
|
| 37 |
AVRational frame_rate() const; |
| 38 |
|
| 39 |
std::int64_t duration() const; |
| 40 |
|
| 41 |
|
| 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 |