Skip to content

Commit

Permalink
reposition ffmpeg cmds #206
Browse files Browse the repository at this point in the history
  • Loading branch information
Anime4000 committed Jun 7, 2021
1 parent 2ff5b79 commit 1b3e245
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 561 deletions.
40 changes: 40 additions & 0 deletions IFME/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,44 @@ internal static string GetLanguageCodeFromFileName(this string value)
var file = Path.GetFileNameWithoutExtension(value);
return file.Substring(file.Length - 3);
}

/// <summary>
/// Copy a directory to new location
/// </summary>
/// <param name="sourceDirName">Source Directory</param>
/// <param name="destDirName">Destination Directory</param>
/// <param name="copySubDirs">Recursive</param>
internal static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);

if (!dir.Exists)
{
throw new DirectoryNotFoundException($"Source directory does not exist or could not be found: {sourceDirName}");
}

DirectoryInfo[] dirs = dir.GetDirectories();

// If the destination directory doesn't exist, create it.
Directory.CreateDirectory(destDirName);

// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string tempPath = Path.Combine(destDirName, file.Name);
file.CopyTo(tempPath, true);
}

// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string tempPath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, tempPath, copySubDirs);
}
}
}
}
37 changes: 20 additions & 17 deletions IFME/MediaEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ internal static void Audio(MediaQueue queue, string tempDir)

frmMain.PrintStatus($"Encoding Audio Id: {i}");

frmMain.PrintLog("[INFO] Extract audio file...");
if (item.Copy && queue.OutputFormat == MediaContainer.MKV)
{
frmMain.PrintLog("[INFO] Extract audio file...");

ProcessManager.Start(tempDir, $"\"{FFmpeg}\" -hide_banner -v error -i \"{item.File}\" -map 0:{item.Id} -c:a copy -y \"audio{i:D4}_{item.Lang}.mka\"");
continue;
}

frmMain.PrintLog("[INFO] Encoding audio file...");
if (Plugins.Items.Audio.TryGetValue(item.Encoder.Id, out PluginsAudio codec))
{
frmMain.PrintLog("[INFO] Encoding audio file...");

var ac = codec.Audio;
var md = item.Encoder.Mode;
var en = ac.Encoder;
Expand Down Expand Up @@ -289,7 +291,7 @@ internal static void Video(MediaQueue queue, string tempDir)
{
if (File.Exists(Path.Combine(tempDir, outrawfile)))
{
ProcessManager.Start(tempDir, $"\"{MP4Box}\" -add \"{outrawfile}\" -set-meta 0 -new \"{outfmtfile}\" ");
ProcessManager.Start(tempDir, $"\"{MP4Box}\" -add \"{outrawfile}#video:name=\" -itags tool=\"IFME MP4\" \"{outfmtfile}\" ");
File.Delete(Path.Combine(tempDir, outrawfile));
}
}
Expand All @@ -304,41 +306,41 @@ internal static void Video(MediaQueue queue, string tempDir)
}
}

internal static void Muxing(MediaQueue queue, string tempDir, string saveDir)
internal static int Muxing(MediaQueue queue, string tempDir, string saveDir, string saveFile)
{
var x = 0;
var metadata = string.Empty;
var metafile = string.Empty;
var map = "-map_metadata -1 -map_chapters -1 -dn ";
var map = string.Empty;

var argVideo = string.Empty;
var argAudio = string.Empty;
var argSubtitle = string.Empty;
var argEmbed = string.Empty;

var outFile = Path.Combine(saveDir, $"{Path.GetFileNameWithoutExtension(queue.FilePath)}_encoded.{queue.OutputFormat.ToString().ToLowerInvariant()}");
var outFile = Path.Combine(saveDir, saveFile);

frmMain.PrintStatus("Repacking...");
frmMain.PrintLog($"[INFO] Multiplexing encoded files into single file...");

if (File.Exists(Path.Combine(tempDir, "metadata.ini")))
{
metafile = "-i metadata.ini ";
metafile = "-f ffmetadata -i metadata.ini ";
}

foreach (var video in Directory.GetFiles(tempDir, "video*"))
{
argVideo += $"-i \"{Path.GetFileName(video)}\" ";
metadata += $"-metadata:s:{x} language={video.GetLanguageCodeFromFileName()} ";
map += $"-map {x} ";
metadata += $"-metadata:s:{x} title=\"{video.GetLanguageCodeFromFileName()}\" -metadata:s:{x} language={video.GetLanguageCodeFromFileName()} ";
map += $" -map {x}:0";
x++;
}

foreach (var audio in Directory.GetFiles(tempDir, "audio*"))
{
argAudio += $"-i \"{Path.GetFileName(audio)}\" ";
metadata += $"-metadata:s:{x} language={audio.GetLanguageCodeFromFileName()} ";
map += $"-map {x} ";
metadata += $"-metadata:s:{x} title=\"{audio.GetLanguageCodeFromFileName()}\" -metadata:s:{x} language={audio.GetLanguageCodeFromFileName()} ";
map += $" -map {x}:0";
x++;
}

Expand All @@ -348,8 +350,8 @@ internal static void Muxing(MediaQueue queue, string tempDir, string saveDir)
foreach (var subtitle in Directory.GetFiles(tempDir, "subtitle*"))
{
argSubtitle += $"-i \"{Path.GetFileName(subtitle)}\" ";
metadata += $"-metadata:s:{x} language={subtitle.GetLanguageCodeFromFileName()} {(d == 0 ? $"-disposition:s:{d} default " : "")}";
map += $"-map {x} ";
metadata += $"-metadata:s:{x} title=\"{subtitle.GetLanguageCodeFromFileName()}\" -metadata:s:{x} language={subtitle.GetLanguageCodeFromFileName()} {(d == 0 ? $"-disposition:s:{d} default " : "")}";
map += $" -map {x}:0";
x++;
d++;
}
Expand All @@ -360,15 +362,16 @@ internal static void Muxing(MediaQueue queue, string tempDir, string saveDir)
var files = Directory.GetFiles(tempDirFont, "*");
for (int i = 0; i < files.Length; i++)
{
argEmbed += $"-attach \"{Path.GetFileName(files[i])}\" ";
metadata += $"-metadata:s:{x++} \"mimetype={queue.Attachment[i].Mime}\" ";
argEmbed += $"-attach \"{Path.Combine("attachment", Path.GetFileName(files[i]))}\" ";
metadata += $"-metadata:s:{x} filename=\"{Path.GetFileName(files[i])}\" -metadata:s:{x} \"mimetype={queue.Attachment[i].Mime}\" ";
x++;
}
}
}

var author = $"{Version.Name} v{Version.Release} {Version.OSPlatform} {Version.OSArch} {Version.March} @ {Version.CodeName}";
var command = $"\"{FFmpeg}\" -hide_banner -v error -stats {argVideo}{argAudio}{argSubtitle}{argEmbed}{metafile}{map}{metadata}-metadata \"encoded_by={author}\" -c copy -y \"{outFile}\"";
ProcessManager.Start(tempDir, command);
var command = $"\"{FFmpeg}\" -hide_banner -v error -stats {argVideo}{argAudio}{argSubtitle}{metafile}{map} -c copy -metadata \"encoded_by={author}\" {argEmbed}{metadata} -y \"{outFile}\"";
return ProcessManager.Start(tempDir, command);
}
}
}
6 changes: 3 additions & 3 deletions IFME/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyDescription("Allow user to compress raw media")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Anime4000")]
[assembly: AssemblyProduct("One More Time")]
[assembly: AssemblyProduct("The galaxy is at a crossroads")]
[assembly: AssemblyCopyright("© 2017 Anime4000")]
[assembly: AssemblyTrademark("Anime4000, MulticoreWare, VideoLAN, FFmpeg, Xiph.Org Foundation, Google Inc., Nero AG, GPAC, AMD, Intel, Nvidia et al.")]
[assembly: AssemblyCulture("")]
Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("21.05.25")]
[assembly: AssemblyFileVersion("21.05.25")]
[assembly: AssemblyVersion("21.06.7")]
[assembly: AssemblyFileVersion("21.06.7")]
Loading

0 comments on commit 1b3e245

Please sign in to comment.