mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 10:04:24 +00:00
eac3to improvements
This commit is contained in:
@@ -9,8 +9,12 @@ namespace CUETools.Codecs.BDLPCM
|
||||
{
|
||||
public BDLPCMReaderSettings()
|
||||
{
|
||||
IgnoreShortItems = true;
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public bool IgnoreShortItems { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int? Stream { get; set; }
|
||||
|
||||
|
||||
@@ -57,9 +57,10 @@ namespace CUETools.Codecs.BDLPCM
|
||||
foreach (var audio in item.audio)
|
||||
{
|
||||
if (audio.coding_type != 0x80 /* LPCM */) continue;
|
||||
if (settings.IgnoreShortItems && item.out_time - item.in_time < shortItemDuration) continue;
|
||||
if (audio.pid == chosenPid)
|
||||
{
|
||||
var parent = Directory.GetParent(System.IO.Path.GetDirectoryName(_path));
|
||||
var parent = Directory.GetParent(System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(_path)));
|
||||
var m2ts = System.IO.Path.Combine(
|
||||
System.IO.Path.Combine(parent.FullName, "STREAM"),
|
||||
item.clip_id + ".m2ts");
|
||||
@@ -299,7 +300,10 @@ namespace CUETools.Codecs.BDLPCM
|
||||
uint totalLength = 0;
|
||||
foreach (var item in hdr_m.play_item)
|
||||
{
|
||||
totalLength += item.out_time - item.in_time;
|
||||
if (item.num_audio == 0) continue;
|
||||
uint item_duration = item.out_time - item.in_time;
|
||||
if (settings.IgnoreShortItems && item_duration < shortItemDuration) continue;
|
||||
totalLength += item_duration;
|
||||
}
|
||||
|
||||
return TimeSpan.FromSeconds(totalLength / 45000.0);
|
||||
@@ -371,6 +375,48 @@ namespace CUETools.Codecs.BDLPCM
|
||||
}
|
||||
}
|
||||
|
||||
public List<uint> Chapters
|
||||
{
|
||||
get
|
||||
{
|
||||
//settings.IgnoreShortItems
|
||||
var res = new List<uint>();
|
||||
if (hdr_m.play_mark.Count < 1) return res;
|
||||
if (hdr_m.play_item.Count < 1) return res;
|
||||
res.Add(0);
|
||||
for (int i = 0; i < hdr_m.mark_count; i++)
|
||||
{
|
||||
ushort mark_item = hdr_m.play_mark[i].play_item_ref;
|
||||
uint item_in_time = hdr_m.play_item[mark_item].in_time;
|
||||
uint item_out_time = hdr_m.play_item[mark_item].out_time;
|
||||
if (settings.IgnoreShortItems && item_out_time - item_in_time < shortItemDuration) continue;
|
||||
uint item_offset = 0;
|
||||
for (int j = 0; j < mark_item; j++)
|
||||
{
|
||||
if (hdr_m.play_item[j].num_audio == 0) continue;
|
||||
uint item_duration = hdr_m.play_item[j].out_time - hdr_m.play_item[j].in_time;
|
||||
if (settings.IgnoreShortItems && item_duration < shortItemDuration) continue;
|
||||
item_offset += item_duration;
|
||||
}
|
||||
res.Add(hdr_m.play_mark[i].time - item_in_time + item_offset);
|
||||
}
|
||||
uint end_offset = 0;
|
||||
for (int j = 0; j < hdr_m.play_item.Count; j++)
|
||||
{
|
||||
if (hdr_m.play_item[j].num_audio == 0) continue;
|
||||
uint item_duration = hdr_m.play_item[j].out_time - hdr_m.play_item[j].in_time;
|
||||
if (settings.IgnoreShortItems && item_duration < shortItemDuration) continue;
|
||||
end_offset += hdr_m.play_item[j].out_time - hdr_m.play_item[j].in_time;
|
||||
}
|
||||
res.Add(end_offset);
|
||||
while (res.Count > 1 && res[1] - res[0] < 45000) res.RemoveAt(1);
|
||||
while (res.Count > 1 && res[res.Count - 1] - res[res.Count - 2] < 45000) res.RemoveAt(res.Count - 2);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
readonly static int shortItemDuration = 45000 * 30;
|
||||
|
||||
string _path;
|
||||
Stream _IO;
|
||||
byte[] contents;
|
||||
@@ -583,26 +629,5 @@ namespace CUETools.Codecs.BDLPCM
|
||||
|
||||
public List<MPLSPlaylistItem> play_item;
|
||||
public List<MPLSPlaylistMark> play_mark;
|
||||
|
||||
public List<uint> Chapters
|
||||
{
|
||||
get
|
||||
{
|
||||
var res = new List<uint>();
|
||||
if (play_mark.Count < 1) return res;
|
||||
if (play_item.Count < 1) return res;
|
||||
uint start = play_item[0].in_time;
|
||||
uint end = play_item[play_item.Count - 1].out_time;
|
||||
if (play_mark[0].time - start > 45000)
|
||||
res.Add(0);
|
||||
for (int i = 0; i < mark_count; i++)
|
||||
{
|
||||
if (end - play_mark[i].time > 45000)
|
||||
res.Add(play_mark[i].time - start);
|
||||
}
|
||||
res.Add(end - start);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Collections.Specialized;
|
||||
using CUETools.Codecs.BDLPCM;
|
||||
using CUETools.CDImage;
|
||||
using CUETools.CTDB;
|
||||
using System.Text;
|
||||
|
||||
namespace CUETools.eac3to
|
||||
{
|
||||
@@ -128,7 +129,7 @@ namespace CUETools.eac3to
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
int frameRate = 0;
|
||||
bool interlaced = false;
|
||||
var chapters = audioSource.MPLSHeader.Chapters;
|
||||
var chapters = audioSource.Chapters;
|
||||
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); }));
|
||||
@@ -176,34 +177,28 @@ namespace CUETools.eac3to
|
||||
{
|
||||
int chapterStreams = chapters.Count > 1 ? 1 : 0;
|
||||
if (stream <= chapterStreams)
|
||||
{
|
||||
if (destFile == "-" || destFile == "nul")
|
||||
{
|
||||
encoderFormat = "txt";
|
||||
}
|
||||
else
|
||||
{
|
||||
string extension = Path.GetExtension(destFile).ToLower();
|
||||
if (!extension.StartsWith("."))
|
||||
throw new Exception("Unknown encoder format: " + destFile);
|
||||
encoderFormat = destFile;
|
||||
else
|
||||
encoderFormat = extension.Substring(1);
|
||||
|
||||
if (encoderFormat == "txt")
|
||||
if (encoderFormat != "txt" && encoderFormat != "cue")
|
||||
{
|
||||
Console.Error.WriteLine("Creating file \"{0}\"...", destFile);
|
||||
using (StreamWriter sw = new StreamWriter(destFile))
|
||||
{
|
||||
for (int i = 0; i < chapters.Count - 1; i++)
|
||||
{
|
||||
sw.WriteLine("CHAPTER{0:00}={1}", i + 1,
|
||||
CDImageLayout.TimeToString(TimeSpan.FromSeconds(chapters[i] / 45000.0)));
|
||||
sw.WriteLine("CHAPTER{0:00}NAME=", i + 1);
|
||||
}
|
||||
}
|
||||
Console.BackgroundColor = ConsoleColor.DarkGreen;
|
||||
Console.Error.Write("Done.");
|
||||
Console.BackgroundColor = ConsoleColor.DarkRed;
|
||||
Console.Error.Write("Unsupported chapters file format \"{0}\"", encoderFormat);
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.Error.WriteLine();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (encoderFormat == "cue")
|
||||
{
|
||||
Console.Error.WriteLine("Creating file \"{0}\"...", destFile);
|
||||
string strtoc = "";
|
||||
for (int i = 0; i < chapters.Count; i++)
|
||||
strtoc += string.Format(" {0}", chapters[i] / 600);
|
||||
@@ -222,6 +217,32 @@ namespace CUETools.eac3to
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (encoderFormat == "txt")
|
||||
{
|
||||
Console.Error.WriteLine("Creating file \"{0}\"...", destFile);
|
||||
using (TextWriter sw = destFile == "nul" ? (TextWriter)new StringWriter() : destFile == "-" ? Console.Out : (TextWriter)new StreamWriter(destFile))
|
||||
{
|
||||
for (int i = 0; i < chapters.Count - 1; i++)
|
||||
{
|
||||
sw.WriteLine("CHAPTER{0:00}={1}", i + 1,
|
||||
CDImageLayout.TimeToString(TimeSpan.FromSeconds(chapters[i] / 45000.0)));
|
||||
if (meta != null && meta.track.Length >= toc[i+1].Number)
|
||||
sw.WriteLine("CHAPTER{0:00}NAME={1}", i + 1, meta.track[(int)toc[i+1].Number - 1].name);
|
||||
else
|
||||
sw.WriteLine("CHAPTER{0:00}NAME=", i + 1);
|
||||
}
|
||||
}
|
||||
Console.BackgroundColor = ConsoleColor.DarkGreen;
|
||||
Console.Error.Write("Done.");
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.Error.WriteLine();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (encoderFormat == "cue")
|
||||
{
|
||||
Console.Error.WriteLine("Creating file \"{0}\"...", destFile);
|
||||
//if (outputPath == null)
|
||||
//{
|
||||
// if (meta != null)
|
||||
@@ -229,7 +250,7 @@ namespace CUETools.eac3to
|
||||
// else
|
||||
// outputPath = "unknown.cue";
|
||||
//}
|
||||
using (StreamWriter cueWriter = new StreamWriter(destFile))
|
||||
using (StreamWriter cueWriter = new StreamWriter(destFile, false, Encoding.UTF8))
|
||||
{
|
||||
cueWriter.WriteLine("REM COMMENT \"{0}\"", "Created by CUETools.eac3to");
|
||||
if (meta != null && meta.year != null)
|
||||
@@ -282,8 +303,7 @@ namespace CUETools.eac3to
|
||||
return 0;
|
||||
}
|
||||
|
||||
Console.Error.WriteLine("Unsupported chapters file format \"{0}\"", encoderFormat);
|
||||
return 0;
|
||||
throw new Exception("Unknown encoder format: " + destFile);
|
||||
}
|
||||
if (stream - chapterStreams <= videos.Count)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user