-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffmpegcommandbuilder.cpp
More file actions
155 lines (129 loc) · 4.46 KB
/
ffmpegcommandbuilder.cpp
File metadata and controls
155 lines (129 loc) · 4.46 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
/*
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 "ffmpegcommandbuilder.h"
#include "thumbnailoptionsbuilder.h"
#include <QDir>
#include <QUrl>
QStringList FfmpegCommandBuilder::build(
const RecordingRequest& req,
const FfmpegCapabilities& caps,
const QString& outputPath = QString())
{
QStringList args;
// =========================
// 入力
// =========================
args << "-y"; // 上書き許可(開発中は必須)
if (req.input.httpSeekable && caps.httpSeekableSupported) {
args << "-http_seekable" << "0";
}
if (req.input.inputPath.isEmpty()) {
return {}; // 異常
}
QUrl url(req.input.inputPath);
if (url.isValid() && url.scheme().startsWith("http")) {
args << "-i" << req.input.inputPath;
} else {
args << "-i" << QDir::toNativeSeparators(req.input.inputPath);
}
// サムネイル埋め込み
args << ThumbnailOptionsBuilder::buildInput(req);
// =========================
// コンテナチェック(最小)
// =========================
if (req.container != Container::MP3 &&
req.container != Container::M4A &&
req.container != Container::AAC) {
return {};
}
// =========================
// 音声エンコード
// =========================
if (req.format.copyCodec) {
args << "-c:a" << "copy";
} else {
args << "-c:a" << req.format.codec;
// ビットレート
if (!req.format.bitrate.isEmpty()) {
args << "-b:a" << req.format.bitrate;
}
// チャンネル
if (req.format.channels > 0) {
args << "-ac" << QString::number(req.format.channels);
}
// サンプルレート(指定があれば)
if (!req.format.sampleRate.isEmpty()) {
args << "-ar" << req.format.sampleRate;
}
}
// =========================
// M4Aコンテナオプション
// =========================
if (req.container == Container::M4A &&
req.format.copyCodec) {
args << "-bsf:a" << "aac_adtstoasc";
}
// =========================
// メタデータ
// =========================
if (!req.meta.title.isEmpty()) {
args << "-metadata" << "title=" + req.meta.title;
}
if (!req.meta.artist.isEmpty()) {
args << "-metadata" << "artist=" + req.meta.artist;
}
if (!req.meta.album.isEmpty()) {
args << "-metadata" << "album=" + req.meta.album;
}
if (!req.meta.date.isEmpty()) {
args << "-metadata" << "date=" + req.meta.date;
}
if (!req.meta.genre.isEmpty()) {
args << "-metadata" << "genre=" + req.meta.genre;
}
// =========================
// サムネイル埋め込み
// =========================
args << ThumbnailOptionsBuilder::buildOutput(req);
// =========================
// MP3コンテナオプション(出力直前へ移動)
// =========================
if (req.container == Container::MP3) {
if (req.useId3v2) {
args << "-id3v2_version" << "3";
}
if (!req.writeXing) {
args << "-write_xing" << "0";
}
}
// =========================
// 追加オプションフック(将来用)
// =========================
if (!req.extraOutputOptions.isEmpty()) {
args << req.extraOutputOptions;
}
// =========================
// 出力
// =========================
if (req.includeOutputPath) {
if (outputPath.isEmpty()) return {};
args << QDir::toNativeSeparators(outputPath);
}
return args;
}