eac3to cleanup

This commit is contained in:
Grigory Chudov
2018-02-18 11:05:48 -05:00
parent 774e732f04
commit 7295a9e688
2 changed files with 135 additions and 153 deletions

View File

@@ -43,7 +43,7 @@ namespace CUETools.Processor
private static void AddPluginDirectory(string plugins_path)
{
foreach (string plugin_path in Directory.GetFiles(plugins_path, "*.dll", SearchOption.TopDirectoryOnly))
foreach (string plugin_path in Directory.GetFiles(plugins_path, "CUETools.*.dll", SearchOption.TopDirectoryOnly))
{
try
{

View File

@@ -126,21 +126,24 @@ namespace CUETools.eac3to
{
audioSource = new MPLSReader(sourceFile, null);
Console.ForegroundColor = ConsoleColor.White;
int maxVideo = 0, maxAudio = 0, frameRate = 0;
int frameRate = 0;
bool interlaced = false;
var chapters = audioSource.MPLSHeader.Chapters;
audioSource.MPLSHeader.play_item.ForEach(i => maxVideo = Math.Max(maxVideo, i.video.Count));
audioSource.MPLSHeader.play_item.ForEach(i => maxAudio = Math.Max(maxAudio, i.audio.Count));
audioSource.MPLSHeader.play_item.ForEach(i => i.video.ForEach(v => frameRate = v.FrameRate));
audioSource.MPLSHeader.play_item.ForEach(i => i.video.ForEach(v => interlaced = v.Interlaced));
Console.Error.WriteLine("M2TS, {0} video track{1}, {2} audio track{3}, {4}, {5}{6}", maxVideo, maxVideo > 1 ? "s" : "", maxAudio, maxAudio > 1 ? "s" : "",
var videos = new List<MPLSStream>();
var audios = new List<MPLSStream>();
audioSource.MPLSHeader.play_item.ForEach(i => i.video.ForEach(v => { if (!videos.Exists(v1 => v1.pid == v.pid)) videos.Add(v); }));
audioSource.MPLSHeader.play_item.ForEach(i => i.audio.ForEach(v => { if (!audios.Exists(v1 => v1.pid == v.pid)) audios.Add(v); }));
videos.ForEach(v => { frameRate = v.FrameRate; interlaced = v.Interlaced; });
Console.Error.WriteLine("M2TS, {0} video track{1}, {2} audio track{3}, {4}, {5}{6}",
videos.Count, videos.Count > 1 ? "s" : "",
audios.Count, audios.Count > 1 ? "s" : "",
CDImageLayout.TimeToString(audioSource.Duration, "{0:0}:{1:00}:{2:00}"), frameRate * (interlaced ? 2 : 1), interlaced ? "i" : "p");
//foreach (var item in audioSource.MPLSHeader.play_item)
//Console.Error.WriteLine("{0}.m2ts", item.clip_id);
{
Console.ForegroundColor = ConsoleColor.Gray;
int id = 1;
if (audioSource.MPLSHeader.mark_count > 2)
if (chapters.Count > 1)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Error.Write(id++);
@@ -148,9 +151,7 @@ namespace CUETools.eac3to
Console.ForegroundColor = ConsoleColor.Gray;
Console.Error.WriteLine("Chapters, {0} chapters", chapters.Count - 1);
}
if (audioSource.MPLSHeader.play_item.Count > 0)
{
foreach (var video in audioSource.MPLSHeader.play_item[0].video)
foreach (var video in videos)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Error.Write(id++);
@@ -158,7 +159,7 @@ namespace CUETools.eac3to
Console.ForegroundColor = ConsoleColor.Gray;
Console.Error.WriteLine("{0}, {1}{2}", video.CodecString, video.FormatString, video.FrameRate * (video.Interlaced ? 2 : 1));
}
foreach (var audio in audioSource.MPLSHeader.play_item[0].audio)
foreach (var audio in audios)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Error.Write(id++);
@@ -167,18 +168,14 @@ namespace CUETools.eac3to
Console.Error.WriteLine("{0}, {1}, {2}, {3}", audio.CodecString, audio.LanguageString, audio.FormatString, audio.RateString);
}
}
}
if (destFile == null)
return 0;
if (stream > 0)
{
int id = 1;
ushort pid = 0;
if (chapters.Count > 1)
{
if (stream == id)
int chapterStreams = chapters.Count > 1 ? 1 : 0;
if (stream <= chapterStreams)
{
string extension = Path.GetExtension(destFile).ToLower();
if (!extension.StartsWith("."))
@@ -288,35 +285,20 @@ namespace CUETools.eac3to
Console.Error.WriteLine("Unsupported chapters file format \"{0}\"", encoderFormat);
return 0;
}
else
if (stream - chapterStreams <= videos.Count)
{
id++;
}
}
if (audioSource.MPLSHeader.play_item.Count > 0)
{
foreach (var video in audioSource.MPLSHeader.play_item[0].video)
{
if (stream == id)
{
pid = video.pid;
}
id++;
}
foreach (var audio in audioSource.MPLSHeader.play_item[0].audio)
{
if (stream == id)
{
pid = audio.pid;
}
id++;
}
}
if (pid == 0)
{
Console.Error.WriteLine("Stream {0} not found.", stream);
Console.Error.WriteLine("Video extraction not supported.");
return 0;
}
if (stream - chapterStreams - videos.Count > audios.Count)
{
Console.BackgroundColor = ConsoleColor.DarkRed;
Console.Error.Write("The source file doesn't contain a track with the number {0}.", stream);
Console.BackgroundColor = ConsoleColor.Black;
Console.Error.WriteLine();
return 0;
}
ushort pid = audios[stream - chapterStreams - videos.Count - 1].pid;
(audioSource.Settings as BDLPCMReaderSettings).Pid = pid;
}