Skip to content
This repository was archived by the owner on Feb 9, 2019. It is now read-only.

Commit 4184fb5

Browse files
YuanYuanYuanYuan
authored andcommitted
1. For incorrect json file, the import no longer crashes but warn the user of wrong json file.
2. For MP4 format, check all its audios are in AAC/AC3 format. 3. Basic AC3 support. Currently, AC3 audios are always extract as is, regardless of any other settings. 4. VERY Basic PGS support. add "IncludeSub" to json file. Works for MKV only. No language infomation is written.
1 parent c2b1c1e commit 4184fb5

File tree

6 files changed

+89
-12
lines changed

6 files changed

+89
-12
lines changed

OKEGui/OKEGui/Gui/WizardWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
<ComboBox Name="AudioFormat" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="2">
225225
<ComboBoxItem x:Name="FLACAudio" IsSelected="True" Content="FLAC" />
226226
<ComboBoxItem x:Name="AACAudio" Content="AAC" />
227+
<ComboBoxItem x:Name="AC3Audio" Content="AC3" />
227228
<!--<ComboBoxItem Content="ALAC" />-->
228229
</ComboBox>
229230
<CheckBox IsChecked="{Binding Path=IsExtAudioOnly}" VerticalAlignment="Center" Visibility="Hidden">音频仅抽取</CheckBox>

OKEGui/OKEGui/Gui/WizardWindow.xaml.cs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public string VideoFormat
148148
}
149149
}
150150

151-
// FLAC, AAC(m4a)
151+
// FLAC, AAC(m4a), "AC3", "ALAC"
152152
private string audioFormat;
153153

154154
public string AudioFormat
@@ -229,6 +229,17 @@ public string EncoderInfo
229229
}
230230
}
231231

232+
private bool includeSub;
233+
234+
public bool IncludeSub
235+
{
236+
get { return includeSub; }
237+
set {
238+
includeSub = value;
239+
OnPropertyChanged(new PropertyChangedEventArgs("IncludeSub"));
240+
}
241+
}
242+
232243
public event PropertyChangedEventHandler PropertyChanged;
233244

234245
public void OnPropertyChanged(PropertyChangedEventArgs e)
@@ -453,14 +464,21 @@ public class JsonProfile
453464
public string VideoFormat { get; set; }
454465
public List<JobDetails.AudioInfo> AudioTracks { get; set; }
455466
public string InputScript { get; set; }
467+
public bool IncludeSub { get; set; }
456468
}
457469

458470
private bool LoadJsonProfile(string profile)
459471
{
460472
// TODO: 测试
461473
// TODO: FLAC -> lossless(auto)
462474
string profileStr = File.ReadAllText(profile);
463-
JsonProfile okeProj = JsonConvert.DeserializeObject<JsonProfile>(profileStr);
475+
JsonProfile okeProj;
476+
try {
477+
okeProj = JsonConvert.DeserializeObject<JsonProfile>(profileStr);
478+
} catch (Exception e) {
479+
System.Windows.MessageBox.Show(e.ToString(), "json文件写错了诶");
480+
return false;
481+
}
464482
DirectoryInfo projDir = new DirectoryInfo(wizardInfo.ProjectFile).Parent;
465483

466484
// 检查参数
@@ -481,14 +499,16 @@ private bool LoadJsonProfile(string profile)
481499
}
482500

483501
wizardInfo.EncoderParam = okeProj.EncoderParam;
502+
wizardInfo.IncludeSub = okeProj.IncludeSub;
484503

485504
Dictionary<string, ComboBoxItem> comboItems = new Dictionary<string, ComboBoxItem>() {
486505
{ "MKV", MKVContainer},
487506
{ "MP4", MP4Container },
488507
{ "HEVC", HEVCVideo},
489508
{ "AVC", AVCVideo },
490509
{ "FLAC", FLACAudio },
491-
{ "AAC", AACAudio},
510+
{ "AAC", AACAudio },
511+
{ "AC3", AC3Audio },
492512
};
493513

494514
// 设置封装格式
@@ -517,7 +537,7 @@ private bool LoadJsonProfile(string profile)
517537
}
518538

519539
if (wizardInfo.AudioFormat != "FLAC" && wizardInfo.AudioFormat != "AAC" &&
520-
wizardInfo.AudioFormat != "ALAC") {
540+
wizardInfo.AudioFormat != "AC3") {
521541
return false;
522542
}
523543
comboItems[wizardInfo.AudioFormat].IsSelected = true;
@@ -781,9 +801,10 @@ private void OpenInputFile_Click(object sender, RoutedEventArgs e)
781801
}
782802

783803
foreach (var filename in ofd.FileNames) {
784-
// TODO: 重复文件处理
785804
if (!wizardInfo.InputFile.Contains(filename)) {
786805
wizardInfo.InputFile.Add(filename);
806+
} else {
807+
System.Windows.MessageBox.Show(filename + "被重复选择,已取消添加。", "新建任务向导", MessageBoxButton.OK, MessageBoxImage.Warning);
787808
}
788809
}
789810

@@ -837,10 +858,20 @@ private void SelectFormat_Leave(object sender, RoutedEventArgs e)
837858
container = "";
838859
}
839860

840-
// 简单检查
841-
if (container == "MP4" && audio == "FLAC") {
842-
System.Windows.MessageBox.Show("格式选择错误!\nMP4不能封装FLAC格式。音频格式将改为AAC。", "新建任务向导", MessageBoxButton.OK, MessageBoxImage.Error);
843-
audio = "AAC";
861+
// 确保MP4封装的音轨只可能是AAC或者AC3
862+
if (container == "MP4") {
863+
bool hasFLAC = false;
864+
foreach (var audioTrack in wizardInfo.AudioTracks)
865+
if (audioTrack.Format.ToUpper() == "FLAC" && !audioTrack.SkipMuxing) {
866+
hasFLAC = true;
867+
audioTrack.Format = "AAC";
868+
audioTrack.Bitrate = 256;
869+
}
870+
if (hasFLAC) {
871+
System.Windows.MessageBox.Show("格式选择错误!\nMP4不能封装FLAC格式。音频格式将改为AAC。", "新建任务向导", MessageBoxButton.OK, MessageBoxImage.Error);
872+
audio = "AAC";
873+
}
874+
844875
}
845876

846877
wizardInfo.ContainerFormat = container;
@@ -904,6 +935,8 @@ private void WizardFinish(object sender, RoutedEventArgs e)
904935
td.VideoFormat = wizardInfo.VideoFormat;
905936
td.AudioFormat = wizardInfo.AudioFormat;
906937

938+
td.IncludeSub = wizardInfo.IncludeSub;
939+
907940
foreach (var audio in wizardInfo.AudioTracks) {
908941
td.AudioTracks.Add(audio);
909942
}

OKEGui/OKEGui/JobDetails.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ public bool IsExtAudioOnly
308308
}
309309
}
310310

311+
private bool includeSub;
312+
313+
public bool IncludeSub {
314+
get { return includeSub; }
315+
set {
316+
includeSub = value;
317+
OnPropertyChanged(new PropertyChangedEventArgs("IncludeSub"));
318+
}
319+
}
320+
311321
#endregion JobConfig
312322

313323
public JobDetails()

OKEGui/OKEGui/JobProcessor/Demuxer/EACDemuxer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,16 @@ private void DetectFileTracks(string line)
205205
if (string.IsNullOrEmpty(line)) return;
206206

207207
if (Regex.IsMatch(line, @"^\d*?: .*$")) {
208+
209+
//原盘没有信息的PGS字幕
210+
if (line.Contains("PGS") && !line.Contains(","))
211+
line += ", Japanese";
212+
208213
var match = Regex.Match(line, @"^(\d*?): (.*?), (.*?)$");
209-
if (match.Groups.Count < 4) return;
214+
215+
if (match.Groups.Count < 4) {
216+
return;
217+
}
210218

211219
var trackInfo = new TrackInfo {
212220
Index = Convert.ToInt32(match.Groups[1].Value),

OKEGui/OKEGui/JobProcessor/Muxer/AutoMuxer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private string GenerateMp4MergeParameter(Episode episode)
164164

165165
foreach (var audioFile in episode.AudioFiles) {
166166
FileInfo ainfo = new FileInfo(audioFile);
167-
if (ainfo.Extension.ToLower() == ".aac" || ainfo.Extension.ToLower() == ".m4a") {
167+
if (ainfo.Extension.ToLower() == ".aac" || ainfo.Extension.ToLower() == ".m4a" || ainfo.Extension.ToLower() == ".ac3") {
168168
parameters.Add($"-i {audioFile}?language={episode.AudioLanguage}");
169169
}
170170
}

OKEGui/OKEGui/Worker/JobWorker.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Windows;
45

56
namespace OKEGui
67
{
@@ -56,7 +57,12 @@ public void Start()
5657
// 音频转码
5758
List<string> audioFile = new List<string>();
5859
foreach (var track in vjob.config.AudioTracks) {
60+
if (track.TrackId >= audioTracks.Count)
61+
continue;
5962
var audioOutput = audioTracks[track.TrackId];
63+
if (audioOutput.Type == EACDemuxer.TrackType.PGS) {
64+
continue;
65+
}
6066
string audioOutpath = audioOutput.OutFileName;
6167

6268
if (track.Format.ToUpper() == "AAC") {
@@ -72,14 +78,18 @@ public void Start()
7278
AudioJob aEncode = new AudioJob("AAC");
7379
aEncode.Input = "-";
7480
aEncode.Output = Path.ChangeExtension(audioOutpath, ".aac");
75-
QAACEncoder qaac = new QAACEncoder(".\\tools\\qaac\\qaac.exe", aEncode, track.Bitrate);
81+
QAACEncoder qaac = new QAACEncoder(".\\tools\\qaac\\qaac.exe", aEncode, track.Bitrate > 0 ? track.Bitrate : 256);
7682

7783
CMDPipeJobProcessor cmdpipe = CMDPipeJobProcessor.NewCMDPipeJobProcessor(flac, qaac);
7884
cmdpipe.start();
7985
cmdpipe.waitForFinish();
8086

8187
audioOutpath = aEncode.Output;
8288
}
89+
90+
if (audioOutput.FileExtension == ".ac3") {
91+
track.Format = "AC3";
92+
}
8393
}
8494

8595
var audioFileInfo = new FileInfo(audioOutpath);
@@ -95,6 +105,21 @@ public void Start()
95105
}
96106
}
97107

108+
//实际上,不判断是否是MKV都不影响;MP4的封装过程自动过滤了*.sup...
109+
if (vjob.config.IncludeSub && vjob.config.ContainerFormat.ToUpper() == "MKV")
110+
foreach (var track in audioTracks) {
111+
if (track.Type == EACDemuxer.TrackType.PGS) {
112+
var subFileInfo = new FileInfo(track.OutFileName);
113+
if (subFileInfo.Length < 1024) {
114+
// 无效字幕
115+
// TODO: 提示用户不能封装
116+
File.Move(track.OutFileName, Path.ChangeExtension(track.OutFileName, ".bak") + subFileInfo.Extension);
117+
continue;
118+
}
119+
audioFile.Add(track.OutFileName);
120+
}
121+
}
122+
98123
vjob.config.Status = "获取信息中";
99124
IJobProcessor processor = x265Encoder.init(vjob, vjob.config.EncoderParam);
100125

0 commit comments

Comments
 (0)