New Project configuration PROD in debug
Added support for Zerbra PRN fiels to be converted to image and imported in PIN4ProdCtrl DB
Video Compression (TDB)
//string progVersion = "Version 2.0.1 - (12/08/2024)";
// Added copy of non image files with same name
string progVersion = "Version 2.0.2 - (27/08/2024)";
// Added support for ZEBRA PRN files, generate image and base64 for prn and image.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BinaryKits.Zpl.Viewer" Version="1.2.1" />
|
||||
<PackageReference Include="GroupDocs.Parser" Version="23.8.0" />
|
||||
<PackageReference Include="Imazen.WebP" Version="10.0.1" />
|
||||
<PackageReference Include="itext7" Version="8.0.1" />
|
||||
@@ -21,6 +22,8 @@
|
||||
<PackageReference Include="Pdfbox" Version="1.1.1" />
|
||||
<PackageReference Include="sharpcompress" Version="0.37.2" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
|
||||
<PackageReference Include="Xabe.FFmpeg" Version="5.2.6" />
|
||||
<PackageReference Include="Xabe.FFmpeg.Downloader" Version="5.2.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>ComicCompress</ActiveDebugProfile>
|
||||
<ActiveDebugProfile>PROD</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
|
||||
+124
-7
@@ -17,6 +17,8 @@ using iText.Kernel.Pdf;
|
||||
|
||||
using Imazen.WebP;
|
||||
|
||||
using Xabe.FFmpeg;
|
||||
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Zip;
|
||||
using SharpCompress.Common;
|
||||
@@ -29,11 +31,24 @@ using javax.xml.transform;
|
||||
using System.Collections.Concurrent;
|
||||
using iText.Barcodes.Dmcode;
|
||||
using ZstdSharp;
|
||||
using Xabe.FFmpeg.Downloader;
|
||||
using System.Reflection;
|
||||
using Microsoft.VisualBasic;
|
||||
using BinaryKits.Zpl.Viewer;
|
||||
|
||||
namespace ComicCompressor
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
|
||||
// string progVersion = "Version 2.0.0 - (04/07/2024)";
|
||||
|
||||
// Added copy of non image files with same name
|
||||
//string progVersion = "Version 2.0.1 - (12/08/2024)";
|
||||
|
||||
// Added support for ZEBRA PRN files, generate image and base64 for prn and image.
|
||||
string progVersion = "Version 2.0.2 - (27/08/2024)";
|
||||
|
||||
public static int Main(string[] args) => CommandLineApplication.Execute<Program>(args);
|
||||
|
||||
#region INPUT_FLAGS
|
||||
@@ -69,6 +84,8 @@ namespace ComicCompressor
|
||||
[Option("-j|--image", Description = "process images only")]
|
||||
public bool DoImage { get; } = false;
|
||||
|
||||
[Option("-n|--prn", Description = "process images only")]
|
||||
public bool DoPrn { get; } = false;
|
||||
[Option("-a|--copyall", Description = "copy all unprocessed files")]
|
||||
public bool DoCopyAll { get; } = false;
|
||||
|
||||
@@ -124,6 +141,17 @@ namespace ComicCompressor
|
||||
Logger.Debug = true;
|
||||
Logger.LoggingLevel = LogLevel.Verbose;
|
||||
|
||||
Logger.Log(progVersion, LogLevel.Verbose, true);
|
||||
|
||||
var progress = new Progress<ProgressInfo>( p => Logger.Log(p.ToString(), LogLevel.Verbose, true) );
|
||||
FFmpeg.SetExecutablesPath(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
|
||||
FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official,progress);
|
||||
|
||||
|
||||
//FFmpeg.SetExecutablesPath (Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FFmpeg"));
|
||||
Logger.Log(FFmpeg.ExecutablesPath, LogLevel.Verbose, true);
|
||||
|
||||
|
||||
IList<string> files = new FileParser().ListAllFiles(Input, Recursive);
|
||||
|
||||
Process(files);
|
||||
@@ -135,7 +163,7 @@ namespace ComicCompressor
|
||||
|
||||
}
|
||||
|
||||
private void Process(IList<string> files)
|
||||
private async void Process(IList<string> files)
|
||||
{
|
||||
Compressor compressor = new Compressor(Logger);
|
||||
compressor.Quality = Quality;
|
||||
@@ -156,7 +184,7 @@ namespace ComicCompressor
|
||||
foreach (var file in files)
|
||||
{
|
||||
Logger.Log($"{n,3}/{files.Count,3} - ", LogLevel.Verbose, false);
|
||||
CompressTask(compressor, file, filename_len);
|
||||
await CompressTask(compressor, file, filename_len);
|
||||
n++;
|
||||
}
|
||||
|
||||
@@ -205,14 +233,22 @@ namespace ComicCompressor
|
||||
|
||||
}
|
||||
|
||||
private void CompressTask(Compressor compressor, string filename, int max_name_len = -1, Boolean isPar = false, ParallelLoopState state = null, long index = 0, long total = 0)
|
||||
private async Task CompressTask(Compressor compressor, string filename, int max_name_len = -1, Boolean isPar = false, ParallelLoopState state = null, long index = 0, long total = 0)
|
||||
{
|
||||
var relativePath = Path.GetRelativePath(Input, filename);
|
||||
var outputPath = Path.Join(OutputFolder, Path.ChangeExtension(relativePath, "cbz"));
|
||||
var outputPath_webp = Path.Join(OutputFolder, Path.ChangeExtension(relativePath, "webp"));
|
||||
var outputPath_webm = Path.Join(OutputFolder, Path.ChangeExtension(relativePath, "webm"));
|
||||
var outputPath_same = Path.Join(OutputFolder, relativePath);
|
||||
int digits = 1+(int)Math.Floor(Math.Log((Double)total) / Math.Log(10.0));
|
||||
|
||||
|
||||
bool isImage = filename.ToLower().EndsWith("jpg") ||
|
||||
filename.ToLower().EndsWith("jpeg") ||
|
||||
filename.ToLower().EndsWith("tif") ||
|
||||
filename.ToLower().EndsWith("bmp") ||
|
||||
filename.ToLower().EndsWith("png");
|
||||
|
||||
string print_line_header = "";
|
||||
switch (digits)
|
||||
{
|
||||
@@ -250,10 +286,10 @@ namespace ComicCompressor
|
||||
Logger.Log(outputPath, LogLevel.Verbose, true, Color.Yellow);
|
||||
return;
|
||||
}
|
||||
if (DoImage && Skip && File.Exists(outputPath_webp))
|
||||
if (DoImage && Skip && isImage && File.Exists(outputPath_webp))
|
||||
{
|
||||
long lengthin = new System.IO.FileInfo(filename).Length;
|
||||
long lengthout = new System.IO.FileInfo(outputPath).Length;
|
||||
long lengthout = new System.IO.FileInfo(outputPath_webp).Length;
|
||||
Program.file_stat fs = null;
|
||||
Program.File_statistics.TryGetValue(filename, out fs);
|
||||
if (fs != null)
|
||||
@@ -286,8 +322,66 @@ namespace ComicCompressor
|
||||
return;
|
||||
}
|
||||
|
||||
//if (DoPdf)
|
||||
// return;
|
||||
// COMPRESS video to webm
|
||||
if(filename.ToLower().EndsWith("mp4"))
|
||||
{
|
||||
Logger.Log(outputPath_webm, LogLevel.Verbose, true, Color.LightBlue);
|
||||
|
||||
IMediaInfo mediaInfo = await FFmpeg.GetMediaInfo(filename);
|
||||
IStream videoStream = mediaInfo.VideoStreams.FirstOrDefault()
|
||||
?.SetCodec(VideoCodec.vp8);
|
||||
IStream audioStream = mediaInfo.AudioStreams.FirstOrDefault();
|
||||
|
||||
var conversion = FFmpeg.Conversions.New()
|
||||
.AddStream(audioStream, videoStream)
|
||||
.SetOutput(outputPath_webm);
|
||||
conversion.UseHardwareAcceleration(HardwareAccelerator.cuvid,VideoCodec.h264,VideoCodec.hevc);
|
||||
|
||||
// var snippet = await FFmpeg.Conversions.FromSnippet.ToWebM(filename, outputPath_webm);
|
||||
conversion.OnProgress += (sender, args) =>
|
||||
{
|
||||
var percent = (int)(Math.Round(args.Duration.TotalSeconds / args.TotalLength.TotalSeconds, 2) * 100);
|
||||
Logger.Log($"[{args.Duration} / {args.TotalLength}] {percent}%", LogLevel.Verbose, true, Color.LightBlue);
|
||||
};
|
||||
conversion.OnDataReceived += (sender, args) =>
|
||||
{
|
||||
Logger.Log($"{args.Data}{Environment.NewLine}", LogLevel.Verbose, true, Color.LightBlue);
|
||||
};
|
||||
IConversionResult result = await conversion.Start();
|
||||
return;
|
||||
}
|
||||
|
||||
if(DoImage && DoPrn && filename.ToLower().EndsWith("prn"))
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] lines = System.IO.File.ReadAllLines(filename);
|
||||
lines = lines.Skip(2).ToArray();
|
||||
string template_prn = string.Join("\r\n",lines);
|
||||
template_prn = template_prn.Replace(">;", "");
|
||||
// BinaryKits
|
||||
IPrinterStorage printerStorage = new PrinterStorage();
|
||||
var drawer = new ZplElementDrawer(printerStorage);
|
||||
|
||||
var analyzer = new ZplAnalyzer(printerStorage);
|
||||
var analyzeInfo = analyzer.Analyze(template_prn);
|
||||
|
||||
foreach (var labelInfo in analyzeInfo.LabelInfos)
|
||||
{
|
||||
byte[] img = drawer.Draw(labelInfo.ZplElements);
|
||||
outputPath = Path.Join(OutputFolder, Path.ChangeExtension(relativePath, ".prn.png"));
|
||||
File.WriteAllBytes(outputPath, img);
|
||||
//imageData is bytes of png image
|
||||
string base64String = Convert.ToBase64String(img);
|
||||
|
||||
File.WriteAllText(outputPath + ".base64", base64String);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (DoImage &&
|
||||
filename.ToLower().EndsWith("jpg") ||
|
||||
@@ -668,6 +762,29 @@ namespace ComicCompressor
|
||||
|
||||
outStream.Flush();
|
||||
outStream.Close();
|
||||
|
||||
if (DoPrn)
|
||||
{
|
||||
using (MemoryStream m = new MemoryStream())
|
||||
{
|
||||
encoder.Encode(mBitmap, m, 70);
|
||||
byte[] imageBytes = m.ToArray();
|
||||
string base64String = Convert.ToBase64String(imageBytes);
|
||||
|
||||
File.WriteAllText(outputFolder + ".base64", base64String);
|
||||
|
||||
byte[] imageBytes_o = Convert.FromBase64String(base64String);
|
||||
using (MemoryStream ms = new MemoryStream(imageBytes_o))
|
||||
{
|
||||
// Create image from memory stream
|
||||
using (FileStream file = new FileStream(outputFolder + ".base64.webp", FileMode.Create, System.IO.FileAccess.Write))
|
||||
{
|
||||
|
||||
ms.WriteTo(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//encoder.Encode(mBitmap, 70, out result, out length);
|
||||
//UnmanagedMemoryStream ustream = new UnmanagedMemoryStream((byte*)result, length);
|
||||
//ustream.CopyTo(outStream);
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
"ComicCompress": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "-i _IMG_ -o _IMG_WEBP_ -r -s -d -a"
|
||||
},
|
||||
"PROD": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "-i \"K:\\_RPG_\\__THE_AMBER_ROOM_UPDATE\\__ASSETS__\\_IMG_\" -o \"K:\\_RPG_\\__THE_AMBER_ROOM_UPDATE\\__ASSETS__\\_IMG_WEBP_\" -r -s -j -a"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user