-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffmpegcapabilities.cpp
More file actions
182 lines (150 loc) · 4.86 KB
/
ffmpegcapabilities.cpp
File metadata and controls
182 lines (150 loc) · 4.86 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
Copyright (C) 2009-2014 jakago
Copyright (C) 2018-2026 CSReviser Team
This file is part of CaptureStream2, the recorder to support HLS for
NHK radio language courses.
CaptureStream2 is a modified version of CaptureStream, originally
developed by jakago.
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/gpl-2.0.html>.
*/
#include "ffmpegcapabilities.h"
#include <QDir>
#include <QProcess>
#include <QFileInfo>
#include <QCoreApplication>
FfmpegCapabilities FfmpegCapabilities::detect(const QString& ffmpegPath)
{
FfmpegCapabilities caps;
QProcess process;
process.setProgram(ffmpegPath);
process.setArguments({
"-http_seekable", "0", "-version", "0"
/*
"-http_seekable", "0",
"-f", "lavfi",
"-i", "anullsrc",
"-t", "0.1",
"-f", "null",
"-"
*/
});
process.start();
process.waitForFinished();
QString err = process.readAllStandardError();
// if (!err.contains("Option not found", Qt::CaseInsensitive) &&
// !err.contains("Unrecognized option", Qt::CaseInsensitive))
if (!err.contains("Option not found", Qt::CaseInsensitive) )
{
caps.httpSeekableSupported = true;
}
return caps;
}
QString FfmpegCapabilities::autoDetectFfmpeg()
{
QProcess process;
QString ffmpegPath;
ffmpegPath = QCoreApplication::applicationDirPath();
if (QFile::exists(ffmpegPath))
return QFileInfo(ffmpegPath).absolutePath();
#ifdef Q_OS_WIN
process.start("cmd.exe", QStringList() << "/c" << "where" << "ffmpeg");
#else
process.start("which", QStringList() << "ffmpeg");
#endif
process.waitForFinished();
ffmpegPath = QString::fromUtf8(process.readAllStandardOutput())
.split("\n").first().trimmed();
if (!QFileInfo::exists(ffmpegPath)) {
#ifdef Q_OS_MAC
QString arch = QSysInfo::buildCpuArchitecture();
if (arch == "x86_64") {
ffmpegPath = "/usr/local/bin/ffmpeg";
} else if (arch == "arm64") {
ffmpegPath = "/opt/homebrew/bin/ffmpeg";
if (!QFile::exists(ffmpegPath))
ffmpegPath = "/usr/local/bin/ffmpeg";
}
#elif defined(Q_OS_LINUX)
ffmpegPath = "/usr/bin/ffmpeg";
#elif defined(Q_OS_WIN)
ffmpegPath = "C:\\Program Files\\ffmpeg\\bin\\ffmpeg.exe";
if (!QFile::exists(ffmpegPath))
ffmpegPath = "C:\\ffmpeg\\bin\\ffmpeg.exe";
#endif
}
if (QFile::exists(ffmpegPath))
return QFileInfo(ffmpegPath).absolutePath();
return QString();
}
bool FfmpegCapabilities::isValidFfmpegFolder(const QString& folder)
{
if (folder.isEmpty())
return false;
QDir dir(folder);
if (!dir.exists())
return false;
#ifdef Q_OS_WIN
QString exe = dir.filePath("ffmpeg.exe");
#else
QString exe = dir.filePath("ffmpeg");
#endif
if (!QFileInfo::exists(exe))
return false;
return canExecuteFfmpeg(exe);
}
bool FfmpegCapabilities::canExecuteFfmpeg(const QString& ffmpegPath)
{
QProcess p;
p.start(ffmpegPath, {"-version"});
if (!p.waitForFinished(1500)) // タイムアウト短めでOK
return false;
return (p.exitStatus() == QProcess::NormalExit);
}
QString FfmpegCapabilities::detectFfmpegFolder()
{
return autoDetectFfmpeg(); // private 関数を内部で呼ぶ
}
QString FfmpegCapabilities::findFfmpegPath() {
QProcess process;
QString ffmpegPath;
#ifdef Q_OS_WIN
process.start("cmd.exe", QStringList() << "/c" << "where" << "ffmpeg");
#else
process.start("which", QStringList() << "ffmpeg");
#endif
process.waitForFinished();
ffmpegPath = QString::fromUtf8(process.readAllStandardOutput()).split("\n").first().trimmed();
if (!QFileInfo::exists(ffmpegPath)) {
#ifdef Q_OS_MAC
QString arch = QSysInfo::buildCpuArchitecture();
if (arch == "x86_64") {
ffmpegPath = "/usr/local/bin/ffmpeg";
} else if (arch == "arm64") {
ffmpegPath = "/opt/homebrew/bin/ffmpeg";
if (!QFile::exists(ffmpegPath)) {
ffmpegPath = "/usr/local/bin/ffmpeg";
}
}
#elif defined(Q_OS_LINUX)
ffmpegPath = "/usr/bin/ffmpeg";
#elif defined(Q_OS_WIN)
ffmpegPath = "C:\\Program Files\\ffmpeg\\bin\\ffmpeg.exe";
if (!QFile::exists(ffmpegPath)) {
ffmpegPath = "C:\\ffmpeg\\bin\\ffmpeg.exe";
}
#endif
}
if (QFile::exists(ffmpegPath)) {
return QFileInfo(ffmpegPath).absolutePath();
}
return QString();
}