49 bool open(
const std::string &filename);
57 bool open(
const std::string &filename,
int cuda_device);
77 [[nodiscard]]
bool is_open()
const {
return formatCtx !=
nullptr && codecCtx !=
nullptr; }
88 bool readRgba(std::vector<uint8_t> &rgba,
int &
width,
int &
height,
int &pitch,
bool flipY =
false);
101 bool readRgba16(std::vector<uint16_t> &rgba,
int &
width,
int &
height,
int &pitch,
bool flipY =
false);
110 bool readGpuRgba(cv::cuda::GpuMat &rgba, cv::cuda::Stream &stream,
bool flipY =
false);
114 [[nodiscard]]
int width()
const {
return frameWidth; }
116 [[nodiscard]]
int height()
const {
return frameHeight; }
118 [[nodiscard]]
double fps()
const {
return frameFps; }
125 static AVPixelFormat chooseHwFormat(AVCodecContext *ctx,
const AVPixelFormat *formats);
126 [[nodiscard]] AVPixelFormat selectHwFormat(
const AVPixelFormat *formats)
const;
127 bool initHardwareDevice(
const AVCodec *decoder,
int cuda_device);
128 bool decodeNextFrame();
129 bool convertFrameToRgba(
const AVFrame *decodedFrame, std::vector<uint8_t> &rgba,
int &
width,
int &
height,
int &pitch,
bool flipY);
130 bool convertFrameToRgba16(
const AVFrame *decodedFrame, std::vector<uint16_t> &rgba,
int &
width,
int &
height,
int &pitch,
bool flipY);
132 bool convertFrameToGpuRgba(
const AVFrame *decodedFrame, cv::cuda::GpuMat &rgba, cv::cuda::Stream &stream,
bool flipY);
134 void flipRows(std::vector<uint8_t> &rgba,
int pitch)
const;
136 AVFormatContext *formatCtx =
nullptr;
137 AVCodecContext *codecCtx =
nullptr;
138 AVPacket *packet =
nullptr;
139 AVFrame *frame =
nullptr;
140 AVFrame *swFrame =
nullptr;
141 AVBufferRef *hwDeviceCtx =
nullptr;
142 SwsContext *swsCtx =
nullptr;
143 bool rgba16_conversion_logged =
false;
144 int videoStream = -1;
147 double frameFps = 30.0;
148 AVPixelFormat hwPixFmt = AV_PIX_FMT_NONE;
149 bool hardwareDecode =
false;
150 int hardwareDecodeDevice = -1;
152 cv::cuda::GpuMat gpuNv12{};
153 cv::cuda::GpuMat gpuRgb{};
154 cv::cuda::GpuMat gpuRgba{};
155 cv::cuda::GpuMat gpuFlippedRgba{};
156 cudaEvent_t decoder_surface_copy_event =
nullptr;
157 bool decoder_surface_barrier_logged =
false;
bool readRgba16(std::vector< uint16_t > &rgba, int &width, int &height, int &pitch, bool flipY=false)
Decode the next frame as native-endian RGBA16.
bool readRgba(std::vector< uint8_t > &rgba, int &width, int &height, int &pitch, bool flipY=false)
Decode the next frame as tightly packed RGBA8.