Repository navigation
Expand file tree
/
Copy pathPlayerMenus.cpp
More file actions
336 lines (335 loc) · 44.6 KB
/
Copy pathPlayerMenus.cpp
File metadata and controls
336 lines (335 loc) · 44.6 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include "player/PlayerBuiltinProfiles.h"
#include "player/PlayerWindow.h"
#include "player/PlayerAiSubtitles.h"
#include "player/PlayerMenu.h"
#include "player/PlayerDiscMenu.h"
#include "player/PlayerTracks.h"
#include "player/PlayerSubtitles.h"
#include "player/PlayerMediaMatching.h"
#include "player/PlayerPng.h"
#include "backend/ThreeFpPlayer.h"
#include "backend/LavPlayback.h"
#include "graph/PresetStore.h"
#include "ui/PreviewPane.h"
#include <QSettings>
#include <QMenu>
#include <QMessageBox>
#include <QActionGroup>
#include <QCoreApplication>
#include <QDir>
#include <QDirIterator>
#include <QFileInfo>
#include <QFile>
#include <QDateTime>
#include <QFileDialog>
#include <QProcess>
#include <QPainter>
#include <QColorSpace>
#include <QLabel>
#include <QDialog>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFontComboBox>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QComboBox>
#include <QCheckBox>
#include <QColorDialog>
#include <QPushButton>
#include <QSlider>
#include <QMessageBox>
#include <QJsonArray>
#include <QJsonDocument>
#include <algorithm>
#include <QFutureWatcher>
#include <QtConcurrentRun>
namespace vsr {
namespace {
QVariantMap subtitleStyle(QSettings &settings) {QVariantMap out;for(const auto &key:settings.allKeys())if(key.startsWith("subtitle/style/"))out.insert(key.mid(15),settings.value(key));return out;}
}
void PlayerWindow::selectSubtitle(int slot,int stream) {
if(slot==0)primarySubtitle_=stream;else secondarySubtitle_=stream;
settings_->setValue(slot==0?"subtitle/primary":"subtitle/secondary",stream);
if(stream==-1) {subtitles_->load(slot,{},-1,{},{});return;}
const auto external=slot==0?externalSubtitle_:externalSecondarySubtitle_;
if(stream==-2 && !external.isEmpty()) {QString codec=QFileInfo(external).suffix().toLower();for(const auto &entry:externalSubtitleTracks_[slot])if(entry.toObject().value("index").toInt()==externalSubtitleIndex_[slot])codec=entry.toObject().value("codec_name").toString();subtitles_->load(slot,external,externalSubtitleIndex_[slot],codec,subtitleStyle(*settings_));return;}
QString codec;for(const auto &entry:media_.value("streams").toArray()){const auto item=entry.toObject();if(item.value("index").toInt()==stream){codec=item.value("codec").toString();break;}}
subtitles_->load(slot,mediaInput_,stream,codec,subtitleStyle(*settings_));
}
void PlayerWindow::attachSubtitle(const QString &path,int slot) {
if(!deferred_.isEmpty()) {deferredSubtitle_=path;deferredSubtitleSlot_=slot;return;}
if(!QFileInfo(path).isFile() || imageMode_)return;
(slot==0?externalSubtitle_:externalSecondarySubtitle_)=QFileInfo(path).absoluteFilePath();
externalSubtitleTracks_[slot]={};externalSubtitleIndex_[slot]=-1;
if(QFileInfo(path).suffix().compare("mks",Qt::CaseInsensitive)==0){const auto source=source_;auto *watcher=new QFutureWatcher<QJsonObject>(this);connect(watcher,&QFutureWatcher<QJsonObject>::finished,this,[this,watcher,path,slot,source]{const auto probe=watcher->result();watcher->deleteLater();if(source_!=source || (slot==0?externalSubtitle_:externalSecondarySubtitle_)!=QFileInfo(path).absoluteFilePath())return;
for(const auto &entry:probe.value("streams").toArray())if(entry.toObject().value("codec_type").toString()=="subtitle")externalSubtitleTracks_[slot]<<entry;
if(externalSubtitleTracks_[slot].isEmpty()){setError(tr("MKS 中未找到字幕轨。"));return;}bool remembered=false;for(const auto &entry:externalSubtitleTracks_[slot])remembered|=entry.toObject().value("index").toInt()==externalSubtitleIndex_[slot];if(!remembered)externalSubtitleIndex_[slot]=externalSubtitleTracks_[slot].first().toObject().value("index").toInt();
externalChapters_={};for(const auto &value:probe.value("chapters").toArray()){const auto c=value.toObject();externalChapters_<<QJsonObject{{"start100ns",double(qRound64(c.value("start_time").toString().toDouble()*10000000))},{"title",c.value("tags").toObject().value("title").toString()}};}applyBlurayMetadata();timeline_->setProperty("chapters",media_.value("chapters").toArray());selectSubtitle(slot,-2);showStatus(tr("已挂载 MKS:%1 · %2 轨 · %3 章节").arg(QFileInfo(path).fileName()).arg(externalSubtitleTracks_[slot].size()).arg(externalChapters_.size()));
});watcher->setFuture(QtConcurrent::run([path]{return PlayerAudioMetadata::probe(path);}));return;}
selectSubtitle(slot,-2);showStatus(tr("已挂载字幕:%1").arg(QFileInfo(path).fileName()));
}
void PlayerWindow::showContextMenu(const QPoint &position) {
if(!imageMode_){const auto refreshed=QJsonDocument::fromJson(clock_->mediaInfo().toUtf8()).object();if(!refreshed.isEmpty())media_=refreshed;}
applyBlurayMetadata();
auto *menu=new PlayerMenu(this);menu->setObjectName("playerContextMenu");menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addAction(tr("打开文件…"),this,&PlayerWindow::chooseFiles);
menu->addAction(tr("打开文件夹…"),this,&PlayerWindow::chooseFolder);
menu->addAction(tr("打开 BD 文件夹…"),this,&PlayerWindow::chooseBluRay);
menu->addAction(tr("打开 BD 光盘镜像…"),this,[this]{const auto path=QFileDialog::getOpenFileName(this,tr("打开 BD 光盘镜像用于播放"),{},"Disc image (*.iso *.img *.vhd *.vhdx)");if(!path.isEmpty())openBluRay(path);});
menu->addAction(tr("打开链接…"),this,&PlayerWindow::chooseLink);
addLoopMenu(menu);
if(!discRoot_.isEmpty())menu->addAction(tr("BD 主菜单 / 弹出菜单"),this,&PlayerWindow::returnToDiscMenu);
if(discMenu_ && discMenu_->active()){menu->addAction(tr("切回节目列表模式 (3FP)"),this,[this]{if(!files_.isEmpty())openFile(files_.first());});
for(bool audio:{true,false}){auto *tracks=PlayerMenu::add(menu,audio?tr("音轨"):tr("字幕"));for(const auto &track:discMenu_->tracks(audio))tracks->addAction(track.second,this,[this,audio,id=track.first]{discMenu_->selectTrack(audio,id);});}
menu->addAction(tr("设置…"),this,&PlayerWindow::showSettings);menu->addAction(tr("全屏 / 退出全屏"),this,&PlayerWindow::toggleFullscreen);menu->popup(position);return;
}
auto *playlist=menu->addAction(tr("播放列表"));playlist->setCheckable(true);playlist->setChecked(playlistPinned_);connect(playlist,&QAction::toggled,this,&PlayerWindow::setPlaylistPinned);
auto *wheel=PlayerMenu::add(menu,tr("鼠标滚轮"));auto *wheelGroup=new QActionGroup(wheel);for(const auto &mode:QStringList{"volume","zoom"}){auto *action=wheel->addAction(mode=="volume"?tr("音量调节"):imageMode_?tr("放大图片"):tr("放大视频"));action->setCheckable(true);action->setChecked((imageMode_?QString("zoom"):settings_->value("player/wheel","volume").toString())==mode);action->setEnabled(!imageMode_ || mode=="zoom");wheelGroup->addAction(action);connect(action,&QAction::triggered,this,[this,mode]{settings_->setValue("player/wheel",mode);});}
menu->addSeparator();
auto *shaders=PlayerMenu::add(menu,tr("自定义 GLSL/HLSL 着色器"));shaders->setObjectName("playerCustomShaders");
shaders->addAction(tr("导入着色器…"),this,[this]{const auto path=QFileDialog::getOpenFileName(this,tr("导入 GLSL/HLSL 着色器"),customShaderDirectory(),"Shaders (*.hlsl *.glsl *.hook)");if(!path.isEmpty())importCustomShader(path);});
shaders->addAction(tr("存储路径(浏览)…"),this,[this]{const auto directory=QFileDialog::getExistingDirectory(this,tr("着色器存储路径"),customShaderDirectory());if(!directory.isEmpty())settings_->setValue("render/shaderDirectory",directory);});
const QDir shaderDirectory(customShaderDirectory());
for(const auto &name:shaderDirectory.entryList({"*.hlsl","*.glsl","*.hook"},QDir::Files,QDir::Name)){
const auto path=shaderDirectory.filePath(name);auto *action=shaders->addAction(name,this,[this,path]{importCustomShader(path);});action->setCheckable(true);action->setChecked(QFileInfo(settings_->value("render/customShader").toString())==QFileInfo(path));
}
shaders->addSeparator();shaders->addAction(tr("关闭自定义着色器"),this,[this]{settings_->remove("render/customShader");customShaderPackage_.clear();hlslParameters_.clear();clock_->setCustomShader({});output_->setCustomShader({});if(!source_.isEmpty())refreshScript();else applyScaling();});
shaders->setEnabled(!imageMode_ && !audioMode_ && !madvrMode() && !networkSource());
#ifndef VSR_LITE_PLAYER
auto *presets=PlayerMenu::add(menu,tr("VapourSynth 预设"));
const auto presetMenu=[&](const QString &title,const QString &directory) {
auto *list=PlayerMenu::add(presets,title);
QDirIterator files(directory,{"*.vpy"},QDir::Files|QDir::NoSymLinks,QDirIterator::Subdirectories);
while(files.hasNext()) {
const auto path=files.next();const auto relative=QDir(directory).relativeFilePath(path);
if(relative.startsWith("builtin/") || relative.startsWith("Community/",Qt::CaseInsensitive))continue;
auto *action=list->addAction(relative,this,[this,path]{loadPreset(path);});
action->setToolTip(PresetStore::description(path));
action->setCheckable(true);action->setChecked(QFileInfo(preset_)==QFileInfo(path));
}
if(list->isEmpty())list->addAction(tr("暂无预设"))->setEnabled(false);
return list;
};
auto *user=presetMenu(tr("用户自定义"),PresetStore::directory());
presetMenu(tr("社区下载"),QDir(PresetStore::directory()).filePath("Community"));
user->addSeparator();auto *hlsl=user->addAction(tr("以 HLSL 执行"));hlsl->setObjectName("playerVpyHlsl");hlsl->setCheckable(true);hlsl->setChecked(settings_->value("render/hlsl",true).toBool());
connect(hlsl,&QAction::toggled,this,[this](bool enabled){settings_->setValue("render/hlsl",enabled);hlslFailed_=false;hlslFallback_.clear();if(!source_.isEmpty())refreshScript();});
user->addAction(tr("加载 VPY 文件…"),this,[this]{const auto path=QFileDialog::getOpenFileName(this,tr("加载 VPY"),PresetStore::directory(),"VapourSynth (*.vpy)");if(!path.isEmpty())loadPreset(path);});
presets->setEnabled(!imageMode_);
#endif
QFile descriptions(
#ifdef VSR_LITE_PLAYER
QDir(QFileInfo(settings_->fileName()).absolutePath()).filePath("preset-descriptions.json")
#else
QDir(PresetStore::directory()).filePath("preset-descriptions.json")
#endif
);QJsonObject notes;if(descriptions.open(QIODevice::ReadOnly))notes=QJsonDocument::fromJson(descriptions.readAll()).object();
QFile defaultsFile(":/filters/player-menu-descriptions.json");if(defaultsFile.open(QIODevice::ReadOnly)){const auto defaults=QJsonDocument::fromJson(defaultsFile.readAll()).object();for(auto it=defaults.begin();it!=defaults.end();++it)if(!notes.contains(it.key()))notes.insert(it.key(),it.value());}
const auto description=[&](const QString &key){return notes.value(key).toString();};
const auto describeCategory=[&](QMenu *folder,const QString &key){const auto text=description(key);folder->menuAction()->setToolTip(text);folder->menuAction()->setProperty("playerDescription",text);};
auto *processing=PlayerMenu::add(menu,tr("图像处理"));processing->setObjectName("playerProcessing");describeCategory(processing,"menu/processing");
auto *scalingFilters=PlayerMenu::add(processing,tr("上采样滤镜"));scalingFilters->setObjectName("playerUpsampling");describeCategory(scalingFilters,"menu/upsampling");
auto *scalingGroup=new QActionGroup(scalingFilters);
const auto animeFiles=builtinAnimeFiles();
const auto scaleChoice=[&](QMenu *folder,int stage){
const auto path=QDir(PresetStore::directory()).filePath("builtin/"+animeFiles[stage]);
auto *action=folder->addAction(qualityNames().at(stage),this,[this,path]{loadPreset(path);});
action->setObjectName(QString("playerAnimeStage%1").arg(stage));
action->setToolTip(description(stage==4 || stage==5 || stage==10?"builtin/"+animeFiles[stage]:"anime/"+QString::number(stage)));action->setCheckable(true);
action->setChecked(fixedAnimeStage()==stage);scalingGroup->addAction(action);
if(stage!=4 && stage!=5 && !animeSourceSupported())action->setEnabled(false);
};
const auto autoPath=QDir(PresetStore::directory()).filePath("builtin/Anime.vpy");
auto *automatic=scalingFilters->addAction(tr("自动切换(推荐)"),this,[this,autoPath]{loadPreset(autoPath);});
automatic->setToolTip(PresetStore::description(autoPath));automatic->setCheckable(true);automatic->setChecked(profile()=="Anime" && fixedAnimeStage()<0);scalingGroup->addAction(automatic);
auto *moesrMenu=PlayerMenu::add(scalingFilters,QStringLiteral("MoeSR"));moesrMenu->setObjectName("playerMoeSRFilters");scaleChoice(moesrMenu,10);
auto *animeMenu=PlayerMenu::add(scalingFilters,QStringLiteral("Anime4K"));animeMenu->setObjectName("playerAnimeFilters");describeCategory(animeMenu,"menu/anime4k");
for(int stage:{8,9,0,1,6,7})scaleChoice(animeMenu,stage);
scalingFilters->addSeparator();auto *passThroughFilters=PlayerMenu::add(scalingFilters,tr("常规直通模式"));passThroughFilters->setObjectName("playerPassthroughFilters");describeCategory(passThroughFilters,"menu/passThrough");
const QStringList algorithmNames{"Nearest","Bilinear","Bicubic","Lanczos3","Jinc (Anti-Alias)","Spline36","Super-XBR","D3D11","Lanczos4","","","","","","","OpenNGU"};
const QStringList algorithmKeys{"scaling/Nearest","scaling/Bilinear","scaling/Bicubic","scaling/Lanczos3","builtin/Anime-4-Jinc.vpy","scaling/Spline36","scaling/SuperXbr","builtin/Anime-5-D3D11.vpy","scaling/Lanczos4","","","","","","","scaling/OpenNGU"};
const auto algorithms=[&](QMenu *folder,const QString &key,const QString &id,bool primary){
auto *group=new QActionGroup(folder);
const QList<int> order=primary?QList<int>{15,4,7,3,8,5,2,1,0,6}:
key=="render/secondUpscale"?QList<int>{4,7,15,3,8,5,2,1,0,6}:QList<int>{4,7,3,8,5,2,1,0,6};
for(int algorithm:order){
auto *action=folder->addAction(algorithmNames[algorithm]);action->setObjectName(id+QString::number(algorithm));
action->setToolTip(description(algorithmKeys[algorithm]));
action->setCheckable(true);action->setChecked(settings_->value(key,primary?15:4).toInt()==algorithm && (!primary || direct_ && (!nativeAnime_ || qualityStage_==4 || qualityStage_==5)));group->addAction(action);
connect(action,&QAction::triggered,this,[this,key,algorithm,primary]{
if(primary)loadPreset(QDir(PresetStore::directory()).filePath(algorithm==4?"builtin/Anime-4-Jinc.vpy":"builtin/Anime-5-D3D11.vpy"));
settings_->setValue(key,algorithm);applyScaling();(direct_?clock_:output_)->redraw();
});
}
};
algorithms(passThroughFilters,"render/upscale","playerPrimaryScale",true);
auto *second=PlayerMenu::add(processing,tr("第二上采样滤镜"));second->setObjectName("playerSecondUpsampling");describeCategory(second,"menu/secondUpsampling");
algorithms(second,"render/secondUpscale","playerSecondScale",false);
auto *down=PlayerMenu::add(processing,tr("下采样"));down->setObjectName("playerDownsampling");describeCategory(down,"menu/downsampling");
algorithms(down,"render/downscale","playerDownscale",false);
#ifndef VSR_LITE_PLAYER
auto *interpolation=PlayerMenu::add(processing,tr("补帧"));interpolation->setObjectName("playerInterpolation");describeCategory(interpolation,"menu/interpolation");auto *interpolationGroup=new QActionGroup(interpolation);
const auto interpolationChoice=[&](QMenu *folder,const QString &name,int stage,bool automatic,int renderer){
auto *action=folder->addAction(name,this,[this,stage,automatic,renderer]{setInterpolation(stage,automatic,renderer);});
action->setObjectName(automatic?QString("playerInterpolationAuto%1").arg(renderer?"D3D11":"Jinc"):QString("playerInterpolation%1%2").arg(renderer?"D3D11":"Jinc").arg(stage));
action->setCheckable(true);action->setChecked(interpolationStage()==stage && interpolationAuto_==automatic && interpolationRenderer()==renderer);interpolationGroup->addAction(action);
const QStringList files{"Interpolation-0-RIFE.vpy","Interpolation-1-RIFE-Half.vpy","Interpolation-2-MVTools-HQ.vpy","Interpolation-3-MVTools.vpy"};
auto nameFile=files[stage];if(renderer)nameFile.replace(".vpy","-D3D11.vpy");action->setToolTip(automatic?description(renderer?"interpolation/auto/D3D11":"interpolation/auto/Jinc"):PresetStore::description(QDir(PresetStore::directory()).filePath("builtin/"+nameFile)));return action;
};
auto *autoInterpolation=PlayerMenu::add(interpolation,tr("自动切换"));autoInterpolation->setObjectName("playerInterpolationAuto");describeCategory(autoInterpolation,"menu/interpolationAuto");
for(int renderer=0;renderer<2;++renderer)interpolationChoice(autoInterpolation,renderer?tr("D3D11 模式"):tr("Jinc 模式"),0,true,renderer)->setEnabled(!interpolationStages(renderer).isEmpty());
for(int renderer=0;renderer<2;++renderer){interpolation->addSeparator();auto *folder=PlayerMenu::add(interpolation,renderer?tr("D3D11 模式"):tr("Jinc 模式"));folder->setObjectName(renderer?"playerInterpolationD3D11":"playerInterpolationJinc");describeCategory(folder,renderer?"menu/interpolationD3D11":"menu/interpolationJinc");for(int stage=0;stage<4;++stage)interpolationChoice(folder,interpolationNames().at(stage),stage,false,renderer);}
interpolation->addSeparator();interpolation->addAction(tr("关闭"),this,[this]{setInterpolation(-1,false);});
auto *super=PlayerMenu::add(processing,tr("超分补帧组合"));super->setObjectName("playerSuperInterpolation");describeCategory(super,"menu/superInterpolation");
const QStringList superFiles{"Super-0-A4K-RIFE-A4K.vpy","Super-1-A4K-RIFE-Jinc.vpy","Super-2-A4K-RIFE-D3D11.vpy","Super-3-RIFE-A4K.vpy"};
const QStringList superNames{tr("Anime4K 2160 → RIFE 整帧540p → Anime4K 2160"),tr("Anime4K 2160 → RIFE 整帧540p → Jinc 2160"),tr("Anime4K 2160 → RIFE 整帧540p → D3D11 2160"),tr("1080 → RIFE 半尺寸推理/保留原帧 → Anime4K 2160")};
for(int stage=0;stage<superFiles.size();++stage){const auto path=QDir(PresetStore::directory()).filePath("builtin/"+superFiles[stage]);auto *action=super->addAction(superNames[stage],this,[this,path]{loadPreset(path);});action->setCheckable(true);action->setChecked(superInterpolationStage()==stage);action->setToolTip(PresetStore::description(path));}
#endif
bool hasVideo=false;for(const auto &entry:media_.value("streams").toArray())if(entry.toObject().value("type").toString()=="video")hasVideo=true;
processing->setEnabled(!imageMode_ && !madvrMode() && !networkSource() && (source_.isEmpty() || hasVideo));
auto *hdrMapping=PlayerMenu::add(processing,tr("HDR 映射"));
auto *hdrEnable=hdrMapping->addAction(tr("RTX TrueHDR · SDR→HDR"));hdrEnable->setCheckable(true);hdrEnable->setChecked(settings_->value("render/trueHdr",false).toBool());
connect(hdrEnable,&QAction::triggered,this,[this](bool enabled){
if(enabled && (!direct_ || scalingAlgorithm()!=7)){QMessageBox::information(this,tr("HDR 映射"),tr("请切换到d3d11模式"));return;}
settings_->setValue("render/trueHdr",enabled);applyScaling();(direct_?clock_:output_)->redraw();
});
const auto hdrState=(direct_?clock_:output_)->videoEnhancementStatus(true);
const QStringList hdrReasons{tr("已就绪"),tr("尚未请求"),tr("当前显卡不是 NVIDIA"),tr("驱动不支持"),tr("源视频不是 SDR"),tr("当前输出不是 HDR"),tr("源像素格式不支持"),tr("驱动拒绝处理")};
auto *hdrStatus=hdrMapping->addAction(hdrState.active?tr("状态:内核已启用"):tr("状态:未生效 · %1").arg(hdrReasons.value(int(hdrState.reason),tr("未知状态"))));hdrStatus->setEnabled(false);
hdrMapping->addAction(tr("详细配置…"),this,[this]{setProperty("settingsPage",5);showSettings();});
auto *vsr=processing->addAction(tr("RTX Video Super Resolution"));vsr->setCheckable(true);vsr->setChecked(settings_->value("render/rtxVsr",false).toBool());
connect(vsr,&QAction::triggered,this,[this](bool enabled){if(enabled){QMessageBox::information(this,tr("RTX Super Resolution"),tr("将禁用内置滤镜,切换至 D3D11 直通。"));settings_->setValue("render/upscale",7);settings_->remove("render/customShader");customShaderPackage_.clear();loadPreset(QDir(PresetStore::directory()).filePath("builtin/Anime-5-D3D11.vpy"));}settings_->setValue("render/rtxVsr",enabled);applyScaling();(direct_?clock_:output_)->redraw();});
auto *audio=PlayerMenu::add(menu,tr("音频设置"));audio->setEnabled(!imageMode_ && !source_.isEmpty());
auto *audioTracks=PlayerMenu::add(audio,tr("声音轨道"));auto *audioGroup=new QActionGroup(audioTracks);
const auto selected=clock_->snapshot().selectedAudioStream;
int audioOrdinal=0;
for(const auto &entry:media_.value("streams").toArray()){const auto stream=entry.toObject();if(stream.value("type").toString()!="audio")continue;const int index=stream.value("index").toInt();auto *action=audioTracks->addAction(playerTrackLabel(stream,audioOrdinal++),this,[this,index]{selectAudio(index);});action->setToolTip(QString("%1 · %2 ch · stream 0:%3").arg(stream.value("codec").toString()).arg(stream.value("channels").toInt()).arg(index));action->setCheckable(true);action->setChecked(externalAudio_.isEmpty() && selected==index);audioGroup->addAction(action);}
if(!externalAudio_.isEmpty()){auto *mounted=audioTracks->addAction(tr("挂载:%1").arg(QFileInfo(externalAudio_).fileName()));mounted->setCheckable(true);mounted->setChecked(true);audioGroup->addAction(mounted);audioTracks->addAction(tr("卸载外部音频"),this,[this]{if(clock_->clearExternalAudio())externalAudio_.clear();});}
audioTracks->addSeparator();audioTracks->addAction(tr("挂载音频文件…"),this,[this]{const auto path=QFileDialog::getOpenFileName(this,tr("挂载音频"),{},"Audio (*.mka *.aac *.ac3 *.dts *.eac3 *.flac *.m4a *.mp3 *.ogg *.opus *.wav *.wma)");if(!path.isEmpty())attachAudio(path);})->setEnabled(!audioMode_);
auto *sync=PlayerMenu::add(audio,tr("声音同步"));sync->addAction(tr("复位"),this,[this]{audioDelay_=0;applyAudioEffects();});sync->addAction(tr("滞后 0.1s"),this,[this]{audioDelay_+=1000000;applyAudioEffects();});sync->addAction(tr("提前 0.1s"),this,[this]{audioDelay_-=1000000;applyAudioEffects();});auto *offset=sync->addAction(tr("当前偏移:%1 s").arg(audioDelay_/10000000.0,0,'f',1));offset->setEnabled(false);
auto *muted=audio->addAction(tr("静音"));muted->setCheckable(true);muted->setChecked(mute_->isChecked());connect(muted,&QAction::toggled,mute_,&QPushButton::setChecked);
audio->addAction(tr("均衡器…"),this,&PlayerWindow::showEqualizer);
auto *normalize=audio->addAction(tr("动态响度标准化(低延迟)"));normalize->setObjectName("playerLoudnessNormalization");normalize->setCheckable(true);normalize->setChecked(settings_->value("audio/normalize",false).toBool());connect(normalize,&QAction::toggled,this,[this](bool enabled){settings_->setValue("audio/normalize",enabled);applyAudioEffects();});
auto *subtitles=PlayerMenu::add(menu,tr("字幕设置"));
#ifndef VSR_LITE_PLAYER
auto *ai=subtitles->addAction(tr("AI 实时字幕"));ai->setCheckable(true);ai->setChecked(aiSubtitles_ && aiSubtitles_->active());
ai->setEnabled(!source_.isEmpty() && !madvrMode());
connect(ai,&QAction::triggered,this,[this](bool enabled){
if(!aiSubtitles_){
aiSubtitles_=new PlayerAiSubtitles(this);
aiCaption_=new QLabel(pane_->surface());aiCaption_->setObjectName("playerAiCaption");aiCaption_->setAttribute(Qt::WA_NativeWindow);aiCaption_->setAttribute(Qt::WA_TransparentForMouseEvents);aiCaption_->setTextFormat(Qt::PlainText);aiCaption_->setWordWrap(true);aiCaption_->setAlignment(Qt::AlignCenter);aiCaption_->setStyleSheet("background:rgba(0,0,0,170);color:white;font-size:24px;padding:8px;");aiCaption_->hide();
connect(aiSubtitles_,&PlayerAiSubtitles::status,message_,&QLabel::setText);
connect(aiSubtitles_,&PlayerAiSubtitles::caption,this,[this](const QString &text){const auto size=pane_->surface()->size();aiCaption_->setGeometry(24,qMax(0,size.height()-180),qMax(1,size.width()-48),120);aiCaption_->setText(text);aiCaption_->setVisible(!text.isEmpty() && subtitleVisible_);aiCaption_->raise();});
}
if(!enabled){aiSubtitles_->stop();return;}
const auto package=settings_->value("ai/package",QDir(QCoreApplication::applicationDirPath()).filePath("runtime/ai-subtitles/ai-subtitles.json")).toString();
QJsonObject data;const auto validation=PlayerAiSubtitles::validatePackage(package,&data);if(!validation.isEmpty()){setError(validation);return;}
const auto fingerprint=data.value("executableFingerprint").toString();
if(settings_->value("ai/trustedExecutableFingerprint").toString()!=fingerprint){
if(QMessageBox::question(this,tr("运行 AI 字幕扩展包"),tr("此扩展包将以当前用户权限运行外部 Python 和脚本。仅运行你信任来源的完整扩展包。\nPython:%1\nWorker:%2\n执行文件 SHA-256:%3\n是否信任并启动?").arg(data.value("python").toString(),data.value("worker").toString(),fingerprint),QMessageBox::Yes|QMessageBox::No,QMessageBox::No)!=QMessageBox::Yes)return;
settings_->setValue("ai/trustedExecutableFingerprint",fingerprint);
}
const auto error=aiSubtitles_->start(clock_.get(),package,fingerprint);
if(!error.isEmpty()){setError(error);setProperty("settingsPage",8);showSettings();}
});
#endif
const auto matchedSubtitles=networkSource() || imageMode_ || audioMode_ || source_.isEmpty()?QStringList{}:playerMatchingSubtitles(source_);
const auto tracks=[&](const QString &title,int slot) {auto *list=PlayerMenu::add(subtitles,title);auto *group=new QActionGroup(list);group->setExclusive(true);auto *off=list->addAction(tr("无"),this,[this,slot]{selectSubtitle(slot,-1);});off->setCheckable(true);off->setChecked((slot==0?primarySubtitle_:secondarySubtitle_)==-1);group->addAction(off);
const auto external=slot==0?externalSubtitle_:externalSecondarySubtitle_;
if(!external.isEmpty()) {auto *mounted=list->addAction(tr("挂载:%1").arg(QFileInfo(external).fileName()),this,[this,slot]{selectSubtitle(slot,-2);});mounted->setCheckable(true);mounted->setChecked((slot==0?primarySubtitle_:secondarySubtitle_)==-2);group->addAction(mounted);}
for(const auto &path:matchedSubtitles)if(path!=external){auto *action=list->addAction(QFileInfo(path).fileName(),this,[this,path,slot]{attachSubtitle(path,slot);});action->setToolTip(path);action->setCheckable(true);group->addAction(action);}
for(const auto &entry:externalSubtitleTracks_[slot]){const auto track=entry.toObject();const int index=track.value("index").toInt();auto *action=list->addAction(tr("MKS 轨 %1 · %2 · %3").arg(index+1).arg(track.value("codec_name").toString(),track.value("tags").toObject().value("language").toString()),this,[this,slot,index]{externalSubtitleIndex_[slot]=index;selectSubtitle(slot,-2);});action->setCheckable(true);action->setChecked((slot==0?primarySubtitle_:secondarySubtitle_)==-2 && externalSubtitleIndex_[slot]==index);group->addAction(action);}
int ordinal=0;
for(const auto &entry:media_.value("streams").toArray()){const auto stream=entry.toObject();if(stream.value("type").toString()!="subtitle")continue;const int index=stream.value("index").toInt();auto *action=list->addAction(playerTrackLabel(stream,ordinal++),this,[this,slot,index]{selectSubtitle(slot,index);});action->setToolTip(QString("%1 · stream 0:%2").arg(stream.value("codec").toString()).arg(index));action->setCheckable(true);action->setChecked((slot==0?primarySubtitle_:secondarySubtitle_)==index);group->addAction(action);}
};
tracks(tr("选择字幕 · 底部"),0);tracks(tr("选择次字幕 · 顶部"),1);
auto *visible=subtitles->addAction(tr("显示字幕"));visible->setCheckable(true);visible->setChecked(subtitleVisible_);connect(visible,&QAction::toggled,this,[this](bool on){subtitleVisible_=on;settings_->setValue("subtitle/visible",on);if(aiCaption_)aiCaption_->setVisible(on && !aiCaption_->text().isEmpty());});
subtitles->addAction(tr("切换首 / 次字幕"),this,[this]{{const auto primary=primarySubtitle_;std::swap(externalSubtitle_,externalSecondarySubtitle_);std::swap(externalSubtitleTracks_[0],externalSubtitleTracks_[1]);std::swap(externalSubtitleIndex_[0],externalSubtitleIndex_[1]);selectSubtitle(0,secondarySubtitle_);selectSubtitle(1,primary);}});
subtitles->addAction(tr("挂载字幕文件…"),this,[this]{const auto path=QFileDialog::getOpenFileName(this,tr("挂载字幕"),{},"Subtitles (*.ass *.ssa *.srt *.sup *.mks)");if(!path.isEmpty())attachSubtitle(path);});
subtitles->addAction(tr("卸载挂载字幕,恢复内置选择"),this,[this]{externalSubtitle_.clear();externalSecondarySubtitle_.clear();externalSubtitleTracks_[0]={};externalSubtitleTracks_[1]={};externalSubtitleIndex_[0]=externalSubtitleIndex_[1]=-1;externalChapters_={};media_=QJsonDocument::fromJson(clock_->mediaInfo().toUtf8()).object();applyBlurayMetadata();timeline_->setProperty("chapters",media_.value("chapters").toArray());audioSubtitle_->hide();selectSubtitle(0,-1);selectSubtitle(1,-1);})->setEnabled(!externalSubtitle_.isEmpty() || !externalSecondarySubtitle_.isEmpty());
subtitles->addAction(tr("字幕样式设置…(SRT)"),this,&PlayerWindow::showSubtitleStyle);
subtitles->setEnabled(!imageMode_);
if(!media_.value("chapters").toArray().isEmpty()){auto *chapters=PlayerMenu::add(menu,tr("章节"));for(const auto &value:media_.value("chapters").toArray()){const auto chapter=value.toObject();const auto at=qint64(chapter.value("start100ns").toDouble());chapters->addAction(chapter.value("title").toString()+QString(" · %1 s").arg(at/10000000.,0,'f',3),this,[this,at]{seekTime(at);});}}
auto *capture=PlayerMenu::add(menu,tr("图像截取"));
auto *captureTo=PlayerMenu::add(menu,tr("截图到指定路径…"));
for(const auto &format:QStringList{"png","avif","jxl"}) {
const auto label=format=="jxl"?tr("JXL · 16-bit 无损 / HDR"):format=="avif"?tr("AVIF · 质量 70"):tr("PNG · 16-bit 无损");
auto *normal=PlayerMenu::add(capture,label),*specified=PlayerMenu::add(captureTo,label);
for(bool source:{true,false}) {
const auto text=source?(imageMode_?tr("图片原始像素"):direct_?tr("当前源画面"):tr("当前源画面 · VS 处理后")):tr("实画面 · 含字幕及显示效果");
normal->addAction(text,this,[this,source,format]{captureImage(source,{},format);})->setEnabled(!source || !madvrMode() || imageMode_);
specified->addAction(text,this,[this,source,format]{const auto directory=QFileDialog::getExistingDirectory(this,tr("选择截图保存文件夹"),screenshotDirectory());if(!directory.isEmpty())captureImage(source,directory,format);})->setEnabled(!source || !madvrMode() || imageMode_);
}
}
menu->addSeparator();menu->addAction(isFullScreen()?tr("退出全屏 · Enter / Esc"):tr("全屏 · Enter"),this,&PlayerWindow::toggleFullscreen);menu->addAction(tr("设置…"),this,&PlayerWindow::showSettings);menu->popup(position);
}
void PlayerWindow::showSubtitleStyle() {
QDialog dialog(this);dialog.setObjectName("playerSubtitleStyle");dialog.setWindowTitle(tr("字幕样式 · 仅 SRT"));dialog.resize(720,550);auto *outer=new QVBoxLayout(&dialog);outer->addWidget(new QLabel(tr("SRT 使用以下样式;ASS/SSA 保留原始高级样式与特效,SUP 保留位图。"),&dialog));auto *body=new QHBoxLayout;outer->addLayout(body);
auto *fontGroup=new QGroupBox(tr("字体"),&dialog);auto *fontForm=new QFormLayout(fontGroup);body->addWidget(fontGroup);
auto *font=new QFontComboBox(&dialog);font->setCurrentFont(QFont(settings_->value("subtitle/style/font","Comic Sans MS").toString()));fontForm->addRow(tr("默认字体"),font);
QHash<QString,QSpinBox *> numbers;
const auto number=[&](QFormLayout *form,const QString &key,const QString &label,int value,int min,int max){auto *box=new QSpinBox(&dialog);box->setRange(min,max);box->setValue(settings_->value("subtitle/style/"+key,value).toInt());form->addRow(label,box);numbers.insert(key,box);return box;};
number(fontForm,"size",tr("字号(1080p 基准)"),36,8,200);number(fontForm,"spacing",tr("字间距"),0,-20,100);number(fontForm,"scaleX",tr("平面宽度 %"),100,10,300);number(fontForm,"scaleY",tr("平面高度 %"),100,10,300);
auto *bold=new QCheckBox(tr("粗体"),&dialog);bold->setChecked(settings_->value("subtitle/style/bold",false).toBool());fontForm->addRow(bold);auto *italic=new QCheckBox(tr("斜体"),&dialog);italic->setChecked(settings_->value("subtitle/style/italic",false).toBool());fontForm->addRow(italic);
auto *position=new QGroupBox(tr("位置与比例"),&dialog);auto *positionForm=new QFormLayout(position);body->addWidget(position);auto *alignment=new QComboBox(&dialog);alignment->addItem(tr("底部居中"),2);alignment->addItem(tr("底部靠左"),1);alignment->addItem(tr("底部靠右"),3);alignment->setCurrentIndex(qMax(0,alignment->findData(settings_->value("subtitle/style/alignment",2).toInt())));positionForm->addRow(tr("段落对齐"),alignment);
number(positionForm,"left",tr("左侧间距"),40,0,500);number(positionForm,"right",tr("右侧间距"),40,0,500);number(positionForm,"margin",tr("底部 / 次字幕顶部间距"),48,0,500);
auto *colors=new QGroupBox(tr("颜色、透明度、边框与阴影"),&dialog);auto *colorForm=new QFormLayout(colors);outer->addWidget(colors);QHash<QString,QPushButton *> choices;
const QStringList keys{"color","outlineColor","shadowColor"};const QStringList names{tr("默认"),tr("边框"),tr("阴影")};
for(int n=0;n<3;++n){auto *row=new QWidget(&dialog);auto *line=new QHBoxLayout(row);line->setContentsMargins(0,0,0,0);auto *pick=new QPushButton(&dialog);pick->setProperty("color",settings_->value("subtitle/style/"+keys[n],n?"#000000":"#ffffff"));pick->setText(pick->property("color").toString());line->addWidget(pick);choices.insert(keys[n],pick);auto *opacity=new QSpinBox(&dialog);opacity->setRange(0,100);opacity->setSuffix(" % 不透明");opacity->setValue(settings_->value("subtitle/style/"+keys[n]+"Opacity",100).toInt());line->addWidget(opacity);numbers.insert(keys[n]+"Opacity",opacity);colorForm->addRow(names[n],row);connect(pick,&QPushButton::clicked,&dialog,[pick,&dialog]{const auto color=QColorDialog::getColor(QColor(pick->property("color").toString()),&dialog);if(color.isValid()){pick->setProperty("color",color.name());pick->setText(color.name());}});}
number(colorForm,"outline",tr("边框尺寸"),2,0,12);number(colorForm,"shadow",tr("阴影深度"),2,0,12);auto *box=new QCheckBox(tr("不透明背景框"),&dialog);box->setChecked(settings_->value("subtitle/style/box",false).toBool());colorForm->addRow(box);
auto *buttons=new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel,&dialog);outer->addWidget(buttons);connect(buttons,&QDialogButtonBox::accepted,&dialog,&QDialog::accept);connect(buttons,&QDialogButtonBox::rejected,&dialog,&QDialog::reject);
if(dialog.exec()==QDialog::Accepted){settings_->setValue("subtitle/style/font",font->currentFont().family());settings_->setValue("subtitle/style/bold",bold->isChecked());settings_->setValue("subtitle/style/italic",italic->isChecked());settings_->setValue("subtitle/style/alignment",alignment->currentData());settings_->setValue("subtitle/style/box",box->isChecked());for(auto it=numbers.begin();it!=numbers.end();++it)settings_->setValue("subtitle/style/"+it.key(),it.value()->value());for(auto it=choices.begin();it!=choices.end();++it)settings_->setValue("subtitle/style/"+it.key(),it.value()->property("color"));selectSubtitle(0,primarySubtitle_);selectSubtitle(1,secondarySubtitle_);settings_->sync();}
}
void PlayerWindow::saveScreenshot(const QString &path,const QImage &image,const QJsonObject &metadata){
auto *watcher=new QFutureWatcher<QString>(this);connect(watcher,&QFutureWatcher<QString>::finished,this,[this,watcher,path]{const auto error=watcher->result();watcher->deleteLater();screenshotPending_=false;setError(error.isEmpty()?tr("已保存 %1 截图:%2").arg(QFileInfo(path).suffix().toUpper(),path):tr("截图失败:%1").arg(error));});
watcher->setFuture(QtConcurrent::run([path,image,metadata]{return writeScreenshot(path,image,metadata);}));
}
QString PlayerWindow::screenshotDirectory() const {const auto path=settings_->value("screenshot/path").toString().trimmed();return path.isEmpty()?QDir(QCoreApplication::applicationDirPath()).filePath("screenshots"):QFileInfo(path).absoluteFilePath();}
void PlayerWindow::captureImage(bool source,const QString &directory,const QString &extension) {
if(screenshotPending_){setError(tr("正在保存截图,请稍候。"));return;}
if(source && !imageMode_ && !direct_ && displayedFrame_.planes[0].isEmpty()) {setError(tr("还没有可截取的 VS 帧。"));return;}
const QDir dir(directory.isEmpty()?screenshotDirectory():directory);QDir().mkpath(dir.absolutePath());const auto name=QString("%1-%2-%3.%4").arg(QFileInfo(source_).completeBaseName(),QDateTime::currentDateTime().toString("yyyyMMdd-HHmmss-zzz"),source?(imageMode_ || direct_?"source":"VS"):"display",extension);const QString file=dir.filePath(name);
QJsonObject metadata{{"sourceFile",source_},{"stage",source?"source":"display"},{"position100ns",double(position())},{"hdr",false},{"encoding","encoded-RGB"}};
if(imageMode_){const auto image=source?pane_->image():pane_->captureImage();if(image.isNull()){setError(tr("没有可截取画面。"));return;}const auto transfer=image.colorSpace().transferFunction();const auto format=image.format();const bool floating=format==QImage::Format_RGBA32FPx4 || format==QImage::Format_RGBA16FPx4 || format==QImage::Format_RGBX32FPx4 || format==QImage::Format_RGBX16FPx4;metadata["hdr"]=floating || transfer==QColorSpace::TransferFunction::St2084 || transfer==QColorSpace::TransferFunction::Hlg;if(transfer==QColorSpace::TransferFunction::Linear)metadata["encoding"]="linear-RGB";metadata["inputBitDepthPerChannel"]=image.pixelFormat().bitsPerPixel()/std::max(1,int(image.pixelFormat().channelCount()));screenshotPending_=true;saveScreenshot(file,image,metadata);return;}
if(!source){auto *renderer=direct_?clock_.get():output_.get();const auto status=renderer->colorStatus();auto image=madvrMode()&&lav_?lav_->capture():renderer->captureFloat();if(image.isNull()){setError(tr("当前渲染器未返回可截取画面。"));return;}
metadata["hdr"]=!madvrMode() && status.outputHdr;metadata["inputBitDepthPerChannel"]=madvrMode()?8:int(status.outputBits);metadata["renderer"]=madvrMode()?"madVR 8-bit capture interface":QString::fromUtf8(status.engine);metadata["qtInfoOverlay"]=infoVisible_;metadata["readbackBitDepth"]=image.text("readbackBitDepth").toInt();metadata["outputHdr"]=bool(status.outputHdr);metadata["tone"]=int(status.tone);metadata["gamut"]=int(status.gamut);metadata["dither"]=int(status.dither);metadata["targetPeakNits"]=status.targetPeak;metadata["iccProfile"]=QString::fromUtf8(status.profile);metadata["lutActive"]=bool(status.lutActive);
if(status.outputHdr && !madvrMode()){metadata["encoding"]="scRGB-linear";metadata["linearUnitNits"]=80;image.setColorSpace(QColorSpace(QColorSpace::SRgbLinear));}
else if(status.activeEngine==1 && status.iccState==1){QFile profile(QString::fromUtf8(status.profile));if(profile.open(QIODevice::ReadOnly))image.setColorSpace(QColorSpace::fromIccProfile(profile.readAll()));}
else{metadata["pngPrimaries"]=1;metadata["pngTransfer"]=status.activeEngine==1 || madvrMode()?13:1;}
if(infoVisible_){QPainter painter(&image);const auto ratio=pane_->surface()->devicePixelRatioF();painter.scale(ratio,ratio);info_->render(&painter,info_->pos());}
screenshotPending_=true;saveScreenshot(file,image,metadata);return;}
const auto frame=displayedFrame_;QString format;int bytes=1,subW=0,subH=0;const unsigned value=static_cast<unsigned>(frame.format);
if(value<10){format=value==1?"gray":"gray16le";bytes=value==1?1:2;}
else {const int depth=value%10;bytes=depth?2:1;const int bits=depth==0?8:depth==1?10:depth==2?12:16;
if(value>=40)format=bits==8?"gbrp":QString("gbrp%1le").arg(bits);
else {const auto sampling=value>=30?"444":value>=20?"422":"420";format=QString("yuv%1p").arg(sampling)+(bits==8?QString():QString::number(bits)+"le");subW=value<30?1:0;subH=value<20?1:0;}}
const auto status=clock_->colorStatus();const auto snap=clock_->snapshot();const int width=direct_?int(snap.videoWidth):frame.width,height=direct_?int(snap.videoHeight):frame.height;
if(width<=0 || height<=0){setError(tr("还没有可截取的源帧。"));return;}
QJsonObject stream;if(direct_)for(const auto &entry:QJsonDocument::fromJson(clock_->mediaInfo().toUtf8()).object().value("streams").toArray())if(entry.toObject().value("index").toInt()==snap.selectedVideoStream){stream=entry.toObject();break;}
const int primaries=direct_?(status.sourceKind?int(status.sourcePrimaries):stream.value("colorPrimaries").toInt(2)):int(frame.colorPrimaries),transfer=direct_?(status.sourceKind?int(status.sourceTransfer):stream.value("colorTransfer").toInt(2)):int(frame.colorTransfer);
metadata["hdr"]=transfer==16 || transfer==18;metadata["pngPrimaries"]=primaries;metadata["pngTransfer"]=transfer;metadata["inputBitDepthPerChannel"]=direct_?(status.sourceKind?int(status.sourceBits):stream.value("bitDepth").toInt()):value<10?(value==1?8:16):(value%10==0?8:value%10==1?10:value%10==2?12:16);
const int matrix=direct_?(status.sourceKind?int(status.sourceMatrix):stream.value("colorSpace").toInt(2)):int(frame.colorMatrix);
metadata["sourceMatrix"]=matrix;metadata["sourceRange"]=direct_?(status.sourceKind?int(status.sourceRange):stream.value("colorRange").toInt()):int(frame.colorRange);metadata["frameIndex"]=double(direct_?snap.frameIndex:frame.frameIndex);
QString conversion="zscale=matrix=gbr:range=full";
if(matrix==2 || (!direct_ && value<40 && matrix==0)){const auto fallback=direct_ && stream.value("colorModel").toString()=="RGB"?0:primaries==9 || transfer==16 || transfer==18?9:width>=1280?1:6;conversion+=QString(":matrixin=%1").arg(fallback);metadata["conversionMatrixFallback"]=fallback;}
else if(direct_)conversion+=QString(":matrixin=%1").arg(matrix);
auto *process=new QProcess(this);process->setObjectName("playerScreenshotProcess");connect(process,&QProcess::errorOccurred,this,[this,process](QProcess::ProcessError error){if(error==QProcess::FailedToStart){screenshotPending_=false;setError(tr("截图进程无法启动:%1").arg(process->errorString()));process->deleteLater();}});
connect(process,&QProcess::finished,this,[this,process,file,metadata,width,height](int code){const auto data=process->readAllStandardOutput();const auto error=QString::fromUtf8(process->readAllStandardError());process->deleteLater();if(code!=0 || data.size()!=qint64(width)*height*12){screenshotPending_=false;setError(tr("截图失败:%1").arg(error));return;}
QImage image(width,height,QImage::Format_RGBA32FPx4);const auto *planes=reinterpret_cast<const float *>(data.constData());const qsizetype samples=qsizetype(width)*height;for(int y=0;y<height;++y){auto *row=reinterpret_cast<float *>(image.scanLine(y));for(int x=0;x<width;++x){const qsizetype at=qsizetype(y)*width+x;row[x*4]=planes[samples*2+at];row[x*4+1]=planes[at];row[x*4+2]=planes[samples+at];row[x*4+3]=1;}}
saveScreenshot(file,image,metadata);
});
QStringList arguments{"-v","error","-f","rawvideo","-pixel_format",format,"-video_size",QString("%1x%2").arg(frame.width).arg(frame.height)};
if(value>=10 && value<40) {const QHash<unsigned,QString> matrices{{1,"bt709"},{5,"bt470bg"},{6,"smpte170m"},{9,"bt2020nc"},{10,"bt2020c"}};if(matrices.contains(frame.colorMatrix))arguments<<"-colorspace"<<matrices.value(frame.colorMatrix);if(frame.colorRange)arguments<<"-color_range"<<(frame.colorRange==2?"pc":"tv");}
if(direct_){arguments={"-v","error","-ss",QString::number(std::max<qint64>(0,snap.position100ns)/10000000.0,'f',7)};if(mediaInput_.endsWith(".ffconcat",Qt::CaseInsensitive))arguments<<"-safe"<<"0";arguments<<"-i"<<(mediaInput_.isEmpty()?source_:mediaInput_)<<"-map"<<QString("0:%1").arg(snap.selectedVideoStream);}
else arguments<<"-i"<<"pipe:0";
arguments<<"-frames:v"<<"1"<<"-vf"<<conversion+",format=gbrpf32le"<<"-pix_fmt"<<"gbrpf32le"<<"-f"<<"rawvideo"<<"pipe:1";
screenshotPending_=true;
const auto bundled=QDir(QCoreApplication::applicationDirPath()).filePath("ffmpeg.exe");
process->start(QFileInfo::exists(bundled)?bundled:QStringLiteral("ffmpeg.exe"),arguments);
if(direct_)return;
for(int plane=0;plane<4;++plane)if(!frame.planes[plane].isEmpty()){const int width=plane>0&&value<40?(frame.width+(1<<subW)-1)>>subW:frame.width;const int height=plane>0&&value<40?(frame.height+(1<<subH)-1)>>subH:frame.height;for(int y=0;y<height;++y)process->write(frame.planes[plane].constData()+y*frame.strides[plane],width*bytes);}process->closeWriteChannel();
}
}