48 bool open(
const std::string &filename);
52 [[nodiscard]]
bool is_open()
const {
return formatCtx !=
nullptr && codecCtx !=
nullptr; }
63 bool readRgba(std::vector<uint8_t> &rgba,
int &
width,
int &
height,
int &pitch,
bool flipY =
false);
72 bool readGpuRgba(cv::cuda::GpuMat &rgba, cv::cuda::Stream &stream,
bool flipY =
false);
76 [[nodiscard]]
int width()
const {
return frameWidth; }
78 [[nodiscard]]
int height()
const {
return frameHeight; }
80 [[nodiscard]]
double fps()
const {
return frameFps; }
85 static AVPixelFormat chooseHwFormat(AVCodecContext *ctx,
const AVPixelFormat *formats);
86 [[nodiscard]] AVPixelFormat selectHwFormat(
const AVPixelFormat *formats)
const;
87 bool initHardwareDevice(
const AVCodec *decoder);
88 bool decodeNextFrame();
89 bool convertFrameToRgba(
const AVFrame *decodedFrame, std::vector<uint8_t> &rgba,
int &
width,
int &
height,
int &pitch,
bool flipY);
91 bool convertFrameToGpuRgba(
const AVFrame *decodedFrame, cv::cuda::GpuMat &rgba, cv::cuda::Stream &stream,
bool flipY);
93 void flipRows(std::vector<uint8_t> &rgba,
int pitch)
const;
95 AVFormatContext *formatCtx =
nullptr;
96 AVCodecContext *codecCtx =
nullptr;
97 AVPacket *packet =
nullptr;
98 AVFrame *frame =
nullptr;
99 AVFrame *swFrame =
nullptr;
100 AVBufferRef *hwDeviceCtx =
nullptr;
101 SwsContext *swsCtx =
nullptr;
102 int videoStream = -1;
105 double frameFps = 30.0;
106 AVPixelFormat hwPixFmt = AV_PIX_FMT_NONE;
107 bool hardwareDecode =
false;
109 cv::cuda::GpuMat gpuNv12{};
110 cv::cuda::GpuMat gpuRgb{};
111 cv::cuda::GpuMat gpuRgba{};
112 cv::cuda::GpuMat gpuFlippedRgba{};
bool readRgba(std::vector< uint8_t > &rgba, int &width, int &height, int &pitch, bool flipY=false)
Decode the next frame as tightly packed RGBA8.