-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5017d88
commit 58dd6be
Showing
12 changed files
with
526 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace THP_Converter_CS_CLI.Classes | ||
{ | ||
static class Extensions | ||
{ | ||
internal static string ReplaceSpacesWithUnderscore(this string str) => str.Replace(' ', '_'); | ||
|
||
internal static List<T> ToList<T>(this T[] arr) | ||
{ | ||
var l = new List<T>(); | ||
foreach (var a in arr) | ||
l.Add(a); | ||
return l; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using static THP_Converter_CS_CLI.Properties.Resources; | ||
|
||
namespace THP_Converter_CS_CLI.Classes | ||
{ | ||
class MP4Video | ||
{ | ||
public MP4Video(ushort width, ushort height, FileInfo inFile, FileInfo outFile, double rate = 29.97, bool useAudio = false) | ||
{ | ||
Width = width; | ||
Height = height; | ||
Rate = rate > 1.0 ? (rate < 59.94 ? rate : 59.94) : 1.0; | ||
UseAudio = useAudio; | ||
InFile = inFile.Extension is ".mp4" ? inFile : throw new Exception("The inFile paramater must be a mp4 file."); | ||
OutFile = outFile.Extension is ".thp" ? outFile : new($"{outFile.FullName[0..outFile.FullName.LastIndexOf(".")]}.thp"); | ||
} | ||
|
||
protected MP4Video() | ||
{ | ||
|
||
} | ||
|
||
protected ushort Width { get; set; } | ||
|
||
protected ushort Height { get; set; } | ||
|
||
protected double Rate { get; set; } = 29.97; | ||
|
||
protected bool UseAudio { get; set; } | ||
|
||
protected FileInfo InFile { get; set; } | ||
|
||
protected FileInfo OutFile { get; set; } | ||
|
||
public void Convert() | ||
{ | ||
Directory.SetCurrentDirectory(ProgramData.ProgramDir.FullName); | ||
File.WriteAllBytes("ffmpeg.exe", ffmpeg); | ||
File.Move(InFile.FullName, "video.mp4"); | ||
Directory.CreateDirectory("temp"); | ||
Process.Start(startInfo: new() | ||
{ | ||
CreateNoWindow = true, | ||
UseShellExecute = false, | ||
WindowStyle = ProcessWindowStyle.Hidden, | ||
FileName = "cmd.exe", | ||
Arguments = $"/c ffmpeg.exe -i video.mp4 -r {Rate} -vf scale={Width}:{Height} temp\\frame%03d.jpg" | ||
}).WaitForExit(); | ||
File.Delete("ffmpeg.exe"); | ||
if (UseAudio) | ||
{ | ||
File.WriteAllBytes("mplayer.exe", mplayer); | ||
Process.Start(startInfo: new() | ||
{ | ||
FileName = "cmd.exe", | ||
Arguments = "/c mplayer.exe -ao pcm:file=temp.wav video.mp4" | ||
}).WaitForExit(); | ||
File.Delete("mplayer.exe"); | ||
} | ||
File.WriteAllBytes("THPConv.exe", THPConv); | ||
File.WriteAllBytes("dsptool.dll", dsptool); | ||
Process.Start(startInfo: new() | ||
{ | ||
CreateNoWindow = true, | ||
UseShellExecute = false, | ||
WindowStyle = ProcessWindowStyle.Hidden, | ||
FileName = "cmd.exe", | ||
Arguments = UseAudio ? $"/c thpconv.exe -j temp/*.jpg -r {Rate} -s temp.wav -d output.thp" : $"/c thpconv.exe -j temp/*.jpg -r {Rate} -d output.thp" | ||
}).WaitForExit(); | ||
File.Move("output.thp", OutFile.FullName); | ||
Console.WriteLine($"Converted {InFile.Name} to {OutFile.Name}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace THP_Converter_CS_CLI.Classes | ||
{ | ||
static class ProgramData | ||
{ | ||
internal static DirectoryInfo ProgramDir => new(AppDomain.CurrentDomain.BaseDirectory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using FFmpeg.NET; | ||
using static THP_Converter_CS_CLI.Properties.Resources; | ||
|
||
namespace THP_Converter_CS_CLI.Classes | ||
{ | ||
class THP | ||
{ | ||
protected FileInfo InFile { get; set; } | ||
|
||
protected FileInfo OutFile { get; set; } | ||
|
||
public THP(FileInfo infile, FileInfo outfile) | ||
{ | ||
InFile = infile.Extension is ".thp"? infile : throw new Exception("The infile paramater requires a thp video."); | ||
OutFile = outfile.Extension is ".mp4" ? outfile : throw new Exception("The outfile paramater requires a mp4 video."); | ||
} | ||
|
||
public async Task<MediaFile> Convert() | ||
{ | ||
Directory.SetCurrentDirectory(ProgramData.ProgramDir.FullName); | ||
await File.WriteAllBytesAsync("ffmpeg.exe", ffmpeg); | ||
var engine = new Engine("ffmpeg.exe"); | ||
var infile = new InputFile(InFile); | ||
var outfile = new OutputFile(OutFile); | ||
var r = await engine.ConvertAsync(infile, outfile); | ||
File.Delete("ffmpeg.exe"); | ||
return r; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using THP_Converter_CS_CLI.Classes; | ||
|
||
namespace THP_Converter_CS_CLI | ||
{ | ||
static class Program | ||
{ | ||
static double Rate { get; set; } = 29.97; | ||
|
||
static ushort Width { get; set; } = 0; | ||
|
||
static ushort Height { get; set; } = 0; | ||
|
||
static bool UseAudio { get; set; } = false; | ||
|
||
static FileInfo OutFile { get; set; } | ||
|
||
static FileInfo InFile { get; set; } | ||
|
||
static void Main(string[] args) | ||
{ | ||
for (int i = 0; i < args.Length; i++) | ||
switch (args[i]) | ||
{ | ||
case "-i": | ||
case "--in": | ||
if (i + 1 > args.Length) throw new Exception("The paramerters were malformed."); | ||
if (!File.Exists(args[i + 1])) throw new FileNotFoundException("Input file must exist."); | ||
InFile = new(args[i + 1]); | ||
i++; | ||
break; | ||
case "-r": | ||
case "--rate": | ||
if (i + 1 > args.Length) throw new Exception("The parameters were malformed."); | ||
Rate = double.Parse(args[i + 1]); | ||
i++; | ||
break; | ||
case "-wi": | ||
case "--width": | ||
if (i + 1 > args.Length) throw new Exception("The parameters were malformed."); | ||
Width = ushort.Parse(args[i + 1]); | ||
i++; | ||
break; | ||
case "-he": | ||
case "--height": | ||
if (i + 1 > args.Length) throw new Exception("The parameters were malformed."); | ||
Height = ushort.Parse(args[i + 1]); | ||
i++; | ||
break; | ||
case "-a": | ||
case "--audio": | ||
if (i + 1 > args.Length) | ||
throw new Exception("The parameters were malformed."); | ||
UseAudio = true; | ||
i++; | ||
break; | ||
case "-h": | ||
case "--help": | ||
ShowHelp(); | ||
break; | ||
case "-o": | ||
case "--out": | ||
if (i + 1 > args.Length) | ||
throw new Exception("The parameters were malformed."); | ||
OutFile = new(args[i + 1]); | ||
i++; | ||
break; | ||
} | ||
if (InFile.Extension is ".thp") | ||
{ | ||
if (OutFile.Extension is not ".mp4") throw new Exception("Outfile needs to be a mp4 if the Inputfile is a thp."); | ||
new THP(InFile, OutFile).Convert().GetAwaiter().GetResult(); | ||
Console.WriteLine($"Converted {InFile.Name} to {OutFile.Name}."); | ||
} else if (InFile.Extension is ".mp4") | ||
{ | ||
if (OutFile.Extension is not ".thp") throw new Exception("Outfile needs to be a thp if the Inputfile is a mp4."); | ||
new MP4Video(Width is 0 ? (ushort)640 : Width, Height is 0 ? (ushort)368 : Height, InFile, OutFile, Rate is 0 ? 29.97 : Rate, UseAudio).Convert(); | ||
} | ||
} | ||
|
||
static void ShowHelp() | ||
{ | ||
string[] lines = | ||
{ | ||
"THP-Converter-CS-CLI", | ||
"Created by Lord-Giganticus", | ||
"Command Usage:", | ||
"-i/--in (The input file to use)", | ||
"-r/--rate (The frame rate of a new THP Video. Defaults to 29.97)", | ||
"-wi/--width (The width of a new THP Video. Defauts to 640)", | ||
"-he/--height (The height of a new THP Video. Defaults to 368)", | ||
"-a/--audio (Use audio when making a new THP Video. Defaults to False)", | ||
"-h/--help (Shows this)", | ||
"-o/--out (The file to write to)" | ||
}; | ||
Console.WriteLine(string.Join("\n", lines)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.