]> git.sesse.net Git - kdenlive/blob - testingArea/audioOffset.cpp
Audio envelope calculation extracted into own class, mean and standard deviation...
[kdenlive] / testingArea / audioOffset.cpp
1 /***************************************************************************
2  *   Copyright (C) 2012 by Simon Andreas Eugster (simon.eu@gmail.com)      *
3  *   This file is part of kdenlive. See www.kdenlive.org.                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10
11
12 #include <QMap>
13 #include <QFile>
14 #include <QTime>
15 #include <QImage>
16 #include <QFileInfo>
17 #include <QDateTime>
18 #include <mlt++/Mlt.h>
19 #include <iostream>
20 #include <cstdlib>
21 #include <cmath>
22
23 #include "audioInfo.h"
24 #include "audioStreamInfo.h"
25 #include "audioEnvelope.h"
26
27 int main(int argc, char *argv[])
28 {
29     char *fileMain;
30     char *fileSub;
31     if (argc > 2) {
32         fileMain = argv[1];
33         fileSub = argv[2];
34     } else {
35         std::cout << "Usage: " << argv[0] << " <main audio file> <second audio file>" << std::endl;
36         return 0;
37     }
38     std::cout << "Trying to align (1)\n\t" << fileSub << "\nto fit on (2)\n\t" << fileMain
39               << "\n, result will indicate by how much (1) has to be moved." << std::endl;
40
41     // Initialize MLT
42     Mlt::Factory::init(NULL);
43
44     // Load an arbitrary profile
45     Mlt::Profile prof("hdv_1080_25p");
46
47     // Load the MLT producers
48     Mlt::Producer prodMain(prof, fileMain);
49     if (!prodMain.is_valid()) {
50         std::cout << fileMain << " is invalid." << std::endl;
51         return 2;
52     }
53     Mlt::Producer profSub(prof, fileSub);
54     if (!profSub.is_valid()) {
55         std::cout << fileSub << " is invalid." << std::endl;
56         return 2;
57     }
58
59     AudioInfo infoMain(&prodMain);
60     AudioInfo infoSub(&profSub);
61     infoMain.dumpInfo();
62     infoSub.dumpInfo();
63
64     prodMain.get_fps();
65
66
67     int framesToFetch = prodMain.get_length();
68     std::cout << "Length: " << framesToFetch
69               << " (Seconds: " << framesToFetch/prodMain.get_fps() << ")"
70               << std::endl;
71     if (framesToFetch > 5000) {
72         framesToFetch = 5000;
73     }
74
75     AudioEnvelope envelopeMain(&prodMain);
76     envelopeMain.loadEnvelope();
77     envelopeMain.loadStdDev();
78     envelopeMain.dumpInfo();
79
80
81     QString outImg = QString("envelope-%1.png")
82             .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd-hh:mm:ss"));
83     envelopeMain.drawEnvelope().save(outImg);
84     std::cout << "Saved volume envelope as "
85               << QFileInfo(outImg).absoluteFilePath().toStdString()
86               << std::endl;
87
88
89     return 0;
90
91 }
92
93
94