fix(record): fix compilation error in GIF palette generation#859
fix(record): fix compilation error in GIF palette generation#859add-uos wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
c6fac65 to
7c87590
Compare
Replaces QThreadPool::start() with QtConcurrent::run() to properly execute lambda functions in background threads for palette generation. Adds explicit capture of 'this' and 'cachePalette' variables for thread-safe callback execution via queued connection. Resolves compilation issue in the newly added GIF recording method with palette support. log: fix compilation error in GIF palette generation bug: https://pms.uniontech.com/bug-view-362851.html
deepin pr auto review你好!我是CodeGeeX,你的智能编程助手。我已经仔细审查了你提供的Git Diff。 这次代码变更的主要目的是优化录屏转码(MP4转GIF)的流程,引入了FFmpeg的两步转码法(先生成调色板,再合成GIF)以提升GIF画质,并将耗时的调色板生成过程放到了 整体改进思路非常好,但在语法逻辑、代码质量、性能和安全性方面,还有一些需要改进和注意的地方。以下是详细的审查意见: 1. 语法与逻辑问题
2. 代码质量
3. 代码性能
4. 代码安全
改进后的参考代码片段针对 void RecordProcess::onStartTranscode()
{
qInfo() << __LINE__ << __func__ << "正在转码视频(mp4 to gif)...";
QString captureTempDir = saveTempDir;
QString captureSavePath = savePath;
// 建议使用 QFutureWatcher 来管理异步任务,而不是裸用 QtConcurrent::run + QPointer
// 这里为了最小化改动,仍沿用你的结构,但修复了路径拼接和日志问题
QtConcurrent::run([captureTempDir, captureSavePath, this]() {
QString cachePalette = QDir(captureTempDir).filePath("deepin_screen_recorder_palette.png");
QProcess paletteProcess;
// 注意:如果路径含空格,QProcess的stringlist模式能安全处理
paletteProcess.start("ffmpeg", {"-i", captureSavePath, "-vf", "select=not(mod(n\\,30)),palettegen=stats_mode=diff", cachePalette, "-y"});
// 建议根据视频大小给更合理的超时时间
if (!paletteProcess.waitForFinished(5 * 60 * 1000)) {
qWarning() << "Convert palette failed or timeout!" << paletteProcess.errorString()
<< "\nStderr:" << paletteProcess.readAllStandardError();
cachePalette.clear(); // 退化标志
}
// 回到主线程执行
QMetaObject::invokeMethod(this, [this, cachePalette]() {
// 检查对象是否正在关闭,如果正在关闭则不再继续
if (this->isClosingOrDeleted()) { // 假设有类似的状态标志
qWarning() << "RecordProcess is closing, abort transcode.";
return;
}
this->onTranscodePaletteFinished(cachePalette);
}, Qt::QueuedConnection);
});
}
void RecordProcess::onTranscodePaletteFinished(const QString &palettePng)
{
QProcess *transcodeProcess = new QProcess(this);
// 统一在 lambda 中处理清理逻辑
auto cleanupProcess = [transcodeProcess]() {
transcodeProcess->deleteLater();
};
connect(transcodeProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[this, cleanupProcess](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "exitCode: " << exitCode << " exitStatus: " << exitStatus;
cleanupProcess();
if (exitStatus == QProcess::ExitStatus::NormalExit) {
onTranscodeFinish();
} else {
qWarning() << "transcodeProcess is CrashExit!";
// 建议增加错误状态通知,避免UI一直显示转码中
emit transcodeFailed();
}
});
connect(transcodeProcess, &QProcess::errorOccurred, [cleanupProcess](QProcess::ProcessError processError) {
qWarning() << "transcodeProcess error:" << processError;
cleanupProcess();
emit transcodeFailed();
});
QStringList arg;
arg << "-i" << savePath;
if (!palettePng.isEmpty()) {
arg << "-i" << palettePng;
arg << "-filter_complex";
arg << "fps=12,paletteuse=dither=none:diff_mode=rectangle";
} else {
arg << "-r" << "12";
}
// 使用规范的路径拼接
QFileInfo fileInfo(savePath);
QString gifPath = QDir(fileInfo.absolutePath()).filePath(fileInfo.completeBaseName() + ".gif");
arg << gifPath;
transcodeProcess->start("ffmpeg", arg);
// 增加启动失败判断
if (!transcodeProcess->waitForStarted(3000)) {
qWarning() << "Failed to start ffmpeg:" << transcodeProcess->errorString();
cleanupProcess();
emit transcodeFailed();
return;
}
#if defined(__aarch64__)
if (Utils::isWaylandMode) {
qDebug() << "watting transcode gif end!";
transcodeProcess->waitForFinished(-1);
}
#endif
}希望这些审查意见对你有所帮助!如果有任何疑问,欢迎随时提问。 |
Replaces QThreadPool::start() with QtConcurrent::run() to properly execute lambda functions in background threads for palette generation. Adds explicit capture of 'this' and 'cachePalette' variables for thread-safe callback execution via queued connection. Resolves compilation issue in the newly added GIF recording method with palette support.
log: fix compilation error in GIF palette generation
bug: https://pms.uniontech.com/bug-view-362851.html