2 Star 0 Fork 1

南风博文/QtForOpenCV4Tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
BinaryFileReader.h 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
DBF-DEV-103 提交于 2025-05-22 17:00 +08:00 . 使用ffmpeg+sdl2播放H264/H265裸数据文件
#pragma
#ifndef BINARYFILE_READER_H
#define BINARYFILE_READER_H
#include <iostream>
#include <fstream>
#include <string>
#include <QDebug>
using namespace std;
class BinaryFileReader {
private:
int bytesCount = 0;//读取的字节数
public:
//视频的宽高
int width = 400;
int height = 300;
//文件名
string filename;
//
ifstream in;
public:
bool Init()
{
Close();
in.open(filename, std::ios::binary);
if (!in.is_open())
{
qDebug() << "无法打开文件";
return false;
}
return true;
}
bool Close()
{
if (in) {
in.close();
}
return true;
}
//空间需要外部申请
bool ReadRGB24(char* data)
{
int dataSize = width * height * 3;
in.read(data, dataSize);
if (in.gcount() == 0) {
// 未读取任何字节:可能已到文件结尾或出现错误
if (in.eof()) {
qDebug() << "已到达文件结尾";
return false;
}
else if (in.fail()) {
qDebug() << "读取失败(非EOF原因)";
return false;
}
}
return true;
}
/// <summary>
/// 读取yuv数据
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
bool ReadYUV420P(char* yuv)
{
int dataSize = width * height * 1.5;
in.read(yuv, dataSize);
if (in.gcount() == 0) {
// 未读取任何字节:可能已到文件结尾或出现错误
if (in.eof()) {
qDebug() << "已到达文件结尾";
return false;
}
else if (in.fail()) {
qDebug() << "读取失败(非EOF原因)";
return false;
}
}
return true;
}
bool Read(char* data, int linesize)
{
in.read(data, linesize);
bytesCount = in.gcount();
if (bytesCount == 0) {
// 未读取任何字节:可能已到文件结尾或出现错误
if (in.eof()) {
qDebug() << "已到达文件结尾";
return false;
}
else if (in.fail()) {
qDebug() << "读取失败(非EOF原因)";
return false;
}
}
return true;
}
int getBytesCount()
{
return bytesCount;
}
static BinaryFileReader* Get()
{
static BinaryFileReader reader;
return &reader;
}
static BinaryFileReader* Create()
{
return new BinaryFileReader();
}
protected:
BinaryFileReader() {};
~BinaryFileReader() {}
};
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ywtony/qt-for-open-cv4-tool.git
git@gitee.com:ywtony/qt-for-open-cv4-tool.git
ywtony
qt-for-open-cv4-tool
QtForOpenCV4Tool
master

搜索帮助