X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=testingArea%2FaudioOffset.cpp;h=f71b105231abff9bf53893809ab33cd9e3d836c2;hb=f2fe0d6c467877c59f3fa4eb7f20cf79d1814b66;hp=842096aa61c4113c0748925197730f352760f474;hpb=753c45e28c73b1366b08ff846d27cba897881420;p=kdenlive diff --git a/testingArea/audioOffset.cpp b/testingArea/audioOffset.cpp index 842096aa..f71b1052 100644 --- a/testingArea/audioOffset.cpp +++ b/testingArea/audioOffset.cpp @@ -1,13 +1,12 @@ -/*************************************************************************** - * Copyright (C) 2012 by Simon Andreas Eugster (simon.eu@gmail.com) * - * This file is part of kdenlive. See www.kdenlive.org. * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - ***************************************************************************/ +/* +Copyright (C) 2012 Simon A. Eugster (Granjow) +This file is part of kdenlive. See www.kdenlive.org. +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. +*/ #include #include @@ -23,17 +22,22 @@ #include #include -#include "audioInfo.h" -#include "audioStreamInfo.h" -#include "audioEnvelope.h" -#include "audioCorrelation.h" +#include "../src/lib/audio/audioInfo.h" +#include "../src/lib/audio/audioStreamInfo.h" +#include "../src/lib/audio/audioEnvelope.h" +#include "../src/lib/audio/audioCorrelation.h" void printUsage(const char *path) { - std::cout << "Usage: " << path << "
" << std::endl - << "\t-h, --help\tDisplay this help" << std::endl - << "\t--profile=\tUse the given profile for calculation (run: melt -query profiles)" << std::endl - << "\t--no-images\tDo not save envelope and correlation images" << std::endl + std::cout << "This executable takes two audio/video files A and B and determines " << std::endl + << "how much B needs to be shifted in order to be synchronized with A." << std::endl << std::endl + << path << "
" << std::endl + << "\t-h, --help\n\t\tDisplay this help" << std::endl + << "\t--fft\n\t\tUse Fourier Transform (FFT) to calculate the offset. This only takes" << std::endl + << "\t\tO(n log n) time compared to O(n²) when using normal correlation and should be " << std::endl + << "\t\tfaster for large data (several minutes)." << std::endl + << "\t--profile=\n\t\tUse the given profile for calculation (run: melt -query profiles)" << std::endl + << "\t--no-images\n\t\tDo not save envelope and correlation images" << std::endl ; } @@ -45,9 +49,10 @@ int main(int argc, char *argv[]) std::string profile = "atsc_1080p_24"; bool saveImages = true; + bool useFFT = false; // Load arguments - foreach (QString str, args) { + foreach (const QString &str, args) { if (str.startsWith("--profile=")) { QString s = str; @@ -62,6 +67,10 @@ int main(int argc, char *argv[]) } else if (str == "--no-images") { saveImages = false; args.removeOne(str); + + } else if (str == "--fft") { + useFFT = true; + args.removeOne(str); } } @@ -93,6 +102,9 @@ int main(int argc, char *argv[]) << "\n, result will indicate by how much (2) has to be moved." << std::endl << "Profile used: " << profile << std::endl ; + if (useFFT) { + std::cout << "Will use FFT based correlation." << std::endl; + } // Initialize MLT @@ -115,47 +127,40 @@ int main(int argc, char *argv[]) // Build the audio envelopes for the correlation - AudioEnvelope envelopeMain(&prodMain); - envelopeMain.loadEnvelope(); - envelopeMain.loadStdDev(); - envelopeMain.dumpInfo(); - - AudioEnvelope envelopeSub(&prodSub); - envelopeSub.loadEnvelope(); - envelopeSub.loadStdDev(); - envelopeSub.dumpInfo(); - - - - + AudioEnvelope *envelopeMain = new AudioEnvelope(fileMain.c_str(), &prodMain); + envelopeMain->loadEnvelope(); + envelopeMain->loadStdDev(); + envelopeMain->dumpInfo(); + AudioEnvelope *envelopeSub = new AudioEnvelope(fileSub.c_str(), &prodSub); + envelopeSub->loadEnvelope(); + envelopeSub->loadStdDev(); + envelopeSub->dumpInfo(); // Calculate the correlation and hereby the audio shift - AudioCorrelation corr(&envelopeMain); - int index = corr.addChild(&envelopeSub); + AudioCorrelation corr(envelopeMain); + int index = corr.addChild(envelopeSub, useFFT); int shift = corr.getShift(index); - std::cout << fileSub << " should be shifted by " << shift << " frames" << std::endl + std::cout << " Should be shifted by " << shift << " frames: " << fileSub << std::endl << "\trelative to " << fileMain << std::endl - << "\tin a " << prodMain.get_fps() << " fps profile (" << profile << ")." << std::endl - ; + << "\tin a " << prodMain.get_fps() << " fps profile (" << profile << ")." << std::endl; if (saveImages) { - QString outImg; - outImg = QString("envelope-main-%1.png") + QString outImg = QString::fromLatin1("envelope-main-%1.png") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd-hh:mm:ss")); - envelopeMain.drawEnvelope().save(outImg); + envelopeMain->drawEnvelope().save(outImg); std::cout << "Saved volume envelope as " << QFileInfo(outImg).absoluteFilePath().toStdString() << std::endl; - outImg = QString("envelope-sub-%1.png") + outImg = QString::fromLatin1("envelope-sub-%1.png") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd-hh:mm:ss")); - envelopeSub.drawEnvelope().save(outImg); + envelopeSub->drawEnvelope().save(outImg); std::cout << "Saved volume envelope as " << QFileInfo(outImg).absoluteFilePath().toStdString() << std::endl; - outImg = QString("correlation-%1.png") + outImg = QString::fromLatin1("correlation-%1.png") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd-hh:mm:ss")); corr.info(index)->toImage().save(outImg); std::cout << "Saved correlation image as " @@ -164,6 +169,9 @@ int main(int argc, char *argv[]) } + // Mlt::Factory::close(); + + return 0; }