This repository has been archived by the owner on Dec 11, 2018. It is now read-only.
forked from Aseman-Land/TelegramQML
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mp3converterengine.cpp
110 lines (90 loc) · 2.06 KB
/
mp3converterengine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "mp3converterengine.h"
#include <QProcess>
#include <QFileInfo>
#include <QCoreApplication>
#include <QPointer>
class MP3ConverterEnginePrivate
{
public:
QPointer<QProcess> process;
QString source;
QString destination;
};
MP3ConverterEngine::MP3ConverterEngine(QObject *parent) :
QObject(parent)
{
p = new MP3ConverterEnginePrivate;
p->process = 0;
}
void MP3ConverterEngine::setSource(const QString &source)
{
if(p->source == source)
return;
p->source = source;
Q_EMIT sourceChanged();
}
QString MP3ConverterEngine::source() const
{
return p->source;
}
void MP3ConverterEngine::setDestination(const QString &destination)
{
if(p->destination == destination)
return;
p->destination = destination;
Q_EMIT destinationChanged();
}
QString MP3ConverterEngine::destination() const
{
return p->destination;
}
bool MP3ConverterEngine::running() const
{
return p->process;
}
void MP3ConverterEngine::start()
{
if(p->process)
return;
QStringList args;
args << "-i";
args << p->source;
args << "-acodec";
args << "libmp3lame";
args << "-ac";
args << "2";
args << "-ab";
args << "64k";
args << "-ar";
args << "44100";
args << p->destination;
QString ffmpegPath;
#ifdef Q_OS_WIN
ffmpegPath = QCoreApplication::applicationDirPath() + "/ffmpeg.exe";
#else
#ifdef Q_OS_MAC
ffmpegPath = QCoreApplication::applicationDirPath() + "/ffmpeg";
#else
if(QFileInfo::exists("/usr/bin/avconv"))
ffmpegPath = "/usr/bin/avconv";
else
ffmpegPath = "ffmpeg";
#endif
#endif
p->process = new QProcess(this);
connect(p->process, SIGNAL(error(QProcess::ProcessError)), SIGNAL(error()));
connect(p->process, SIGNAL(finished(int)), SLOT(finished_prv()));
p->process->start(ffmpegPath, args);
Q_EMIT runningChanged();
}
void MP3ConverterEngine::finished_prv()
{
p->process->deleteLater();
p->process = 0;
Q_EMIT finished();
Q_EMIT runningChanged();
}
MP3ConverterEngine::~MP3ConverterEngine()
{
delete p;
}