修改分包接收前板发的YUV数据,取图成功后保存YUV图和JPG图
This commit is contained in:
@@ -11,16 +11,16 @@ FFmpegDecoder::FFmpegDecoder(QObject* parent) :
|
||||
frame(nullptr),
|
||||
packet(nullptr),
|
||||
swsContext(nullptr),
|
||||
videoStreamIndex(-1) // 初始化成员变量
|
||||
videoStreamIndex(-1)
|
||||
{
|
||||
av_log_set_level(AV_LOG_QUIET); // 设置日志级别为安静模式
|
||||
avformat_network_init(); // 初始化网络
|
||||
qDebug() << "FFmpegDecoder created";
|
||||
qDebug() << "FFmpegDecoder thread created";
|
||||
}
|
||||
|
||||
FFmpegDecoder::~FFmpegDecoder()
|
||||
{
|
||||
qDebug() << "Destroying FFmpegDecoder";
|
||||
qDebug() << "Destroying FFmpegDecoder thread";
|
||||
mutex.lock();
|
||||
abort = true;
|
||||
condition.wakeOne();
|
||||
@@ -28,7 +28,7 @@ FFmpegDecoder::~FFmpegDecoder()
|
||||
wait();
|
||||
cleanup();
|
||||
avformat_network_deinit(); // 反初始化网络
|
||||
qDebug() << "FFmpegDecoder destroyed";
|
||||
qDebug() << "FFmpegDecoder thread destroyed";
|
||||
}
|
||||
|
||||
void FFmpegDecoder::processVideo(int itemIndex)
|
||||
@@ -72,7 +72,7 @@ void FFmpegDecoder::stopFFmpegDecoder()
|
||||
{
|
||||
mutex.lock();
|
||||
abort = true;
|
||||
condition.wakeOne(); // 唤醒等待的线程
|
||||
condition.wakeOne();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
@@ -134,10 +134,8 @@ void FFmpegDecoder::run()
|
||||
if (currentFileSize > fileSize) {
|
||||
fileSize = currentFileSize;
|
||||
file.seek(fileSize); // 设置文件读取位置到末尾
|
||||
//qDebug() << "---------------1---------------";
|
||||
// 读取并处理数据包
|
||||
while (av_read_frame(formatContext, packet) >= 0) {
|
||||
//qDebug() << "---------------2---------------";
|
||||
if (packet->stream_index == videoStreamIndex) {
|
||||
int ret = avcodec_send_packet(codecContext, packet);
|
||||
if (ret < 0) {
|
||||
@@ -145,7 +143,6 @@ void FFmpegDecoder::run()
|
||||
av_packet_unref(packet);
|
||||
continue;
|
||||
}
|
||||
//qDebug() << "---------------3---------------";
|
||||
while (ret >= 0) {
|
||||
ret = avcodec_receive_frame(codecContext, frame);
|
||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
|
||||
@@ -156,31 +153,23 @@ void FFmpegDecoder::run()
|
||||
qWarning() << "Error during decoding";
|
||||
break;
|
||||
}
|
||||
//qDebug() << "---------------4---------------";
|
||||
QImage img = avFrameToQImage(frame);
|
||||
//qDebug() << "---------------5---------------";
|
||||
QImage scaledImage = img.scaled(labelSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
//qDebug() << "---------------6---------------";
|
||||
currentVideoLabel->setPixmap(QPixmap::fromImage(scaledImage));
|
||||
QThread::msleep(10); // Simulate 25 FPS frame rate
|
||||
//qDebug() << "---------------7---------------";
|
||||
}
|
||||
}
|
||||
av_packet_unref(packet);
|
||||
//qDebug() << "---------------8---------------";
|
||||
}
|
||||
}
|
||||
//qDebug() << "---------------9---------------";
|
||||
mutex.lock();
|
||||
if (restart) {
|
||||
restart = false;
|
||||
mutex.unlock();
|
||||
break;
|
||||
}
|
||||
//qDebug() << "---------------10---------------";
|
||||
mutex.unlock();
|
||||
}
|
||||
//qDebug() << "---------------11---------------";
|
||||
cleanup();
|
||||
file.close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user