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);
97 bool readGpuRgba(cv::cuda::GpuMat &rgba, cv::cuda::Stream &stream,
bool flipY =
false);
101 [[nodiscard]]
int width()
const {
return frameWidth; }
103 [[nodiscard]]
int height()
const {
return frameHeight; }
105 [[nodiscard]]
double fps()
const {
return frameFps; }
112 static AVPixelFormat chooseHwFormat(AVCodecContext *ctx,
const AVPixelFormat *formats);
113 [[nodiscard]] AVPixelFormat selectHwFormat(
const AVPixelFormat *formats)
const;
114 bool initHardwareDevice(
const AVCodec *decoder,
int cuda_device);
115 bool decodeNextFrame();
116 bool convertFrameToRgba(
const AVFrame *decodedFrame, std::vector<uint8_t> &rgba,
int &
width,
int &
height,
int &pitch,
bool flipY);
118 bool convertFrameToGpuRgba(
const AVFrame *decodedFrame, cv::cuda::GpuMat &rgba, cv::cuda::Stream &stream,
bool flipY);
120 void flipRows(std::vector<uint8_t> &rgba,
int pitch)
const;
122 AVFormatContext *formatCtx =
nullptr;
123 AVCodecContext *codecCtx =
nullptr;
124 AVPacket *packet =
nullptr;
125 AVFrame *frame =
nullptr;
126 AVFrame *swFrame =
nullptr;
127 AVBufferRef *hwDeviceCtx =
nullptr;
128 SwsContext *swsCtx =
nullptr;
129 int videoStream = -1;
132 double frameFps = 30.0;
133 AVPixelFormat hwPixFmt = AV_PIX_FMT_NONE;
134 bool hardwareDecode =
false;
135 int hardwareDecodeDevice = -1;
137 cv::cuda::GpuMat gpuNv12{};
138 cv::cuda::GpuMat gpuRgb{};
139 cv::cuda::GpuMat gpuRgba{};
140 cv::cuda::GpuMat gpuFlippedRgba{};
141 cudaEvent_t decoder_surface_copy_event =
nullptr;
142 bool decoder_surface_barrier_logged =
false;
bool readRgba(std::vector< uint8_t > &rgba, int &width, int &height, int &pitch, bool flipY=false)
Decode the next frame as tightly packed RGBA8.