Add some checks to max audio level calculation

parent 3770fe80
Pipeline #36298 failed with stage
in 60 minutes and 55 seconds
......@@ -220,17 +220,19 @@ void ProjectClip::updateAudioThumbnail()
#else
args << QStringLiteral("/dev/stdout");
#endif
qDebug()<<"=== STARTING COMMAND: "<<args;
QObject::connect(&ffmpeg, &QProcess::readyReadStandardOutput, [&ffmpeg, this]() {
QString output = ffmpeg.readAllStandardOutput();
if (output.contains(QLatin1String("max_volume"))) {
qDebug()<<"===== GOT FFFMPEG OUTPUT:\n"<<output<<"\n.........................";
output = output.section(QLatin1String("max_volume:"), 1).simplified();
output = output.section(QLatin1Char(' '), 0, 0);
int aMax = qMax(1, qAbs(qRound(output.toDouble())));
qDebug()<<"===== GOT CLIP AMAX: "<<aMax;
qDebug()<<"===== GOT CLIP FINAL AMAX: "<<aMax;
setProducerProperty(QStringLiteral("kdenlive:audio_max"), aMax);
bool ok;
double maxVolume = output.toDouble(&ok);
if (ok) {
int aMax = qMax(1, qAbs(qRound(maxVolume)));
setProducerProperty(QStringLiteral("kdenlive:audio_max"), aMax);
} else {
setProducerProperty(QStringLiteral("kdenlive:audio_max"), -1);
}
}
});
ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
......@@ -726,6 +728,7 @@ std::shared_ptr<Mlt::Producer> ProjectClip::getTimelineProducer(int trackId, int
// We need to get an video producer, if none exists
if (m_videoProducers.count(trackId) == 0) {
m_videoProducers[trackId] = cloneProducer(true);
// Let audio enabled so that we can use audio visualization filters ?
m_videoProducers[trackId]->set("set.test_audio", 1);
m_videoProducers[trackId]->set("set.test_image", 0);
m_effectStack->addService(m_videoProducers[trackId]);
......@@ -1404,6 +1407,7 @@ void ProjectClip::discardAudioThumb()
QFile::remove(audioThumbPath);
}
}
resetProducerProperty(QStringLiteral("kdenlive:audio_max"));
m_audioThumbCreated = false;
refreshAudioInfo();
}
......
......@@ -409,7 +409,8 @@ double ProjectItemModel::getAudioMaxLevel(const QString &binId)
for (const auto &clip : m_allItems) {
auto c = std::static_pointer_cast<AbstractProjectItem>(clip.second.lock());
if (c->itemType() == AbstractProjectItem::ClipItem && c->clipId() == binId) {
return qSqrt(std::static_pointer_cast<ProjectClip>(c)->getProducerIntProperty(QStringLiteral("kdenlive:audio_max")));
int volume = std::static_pointer_cast<ProjectClip>(c)->getProducerIntProperty(QStringLiteral("kdenlive:audio_max"));
return volume > 1 ? qSqrt(volume) : volume;
}
}
return 0;
......
......@@ -166,7 +166,7 @@ public:
}
painter->setPen(pen);
double scaleFactor = 255;
if (m_audioMax > 0) {
if (m_audioMax > 1) {
scaleFactor *= m_audioMax;
}
int startPos = m_inPoint / indicesPrPixel;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment