Added support for Raw/PCM audio

This commit is contained in:
N00MKRAD
2020-11-23 18:08:17 +01:00
parent 1d21ca4e97
commit 4d44461785
2 changed files with 14 additions and 6 deletions

View File

@@ -167,7 +167,8 @@ namespace Flowframes
{ {
case "vorbis": return "ogg"; case "vorbis": return "ogg";
case "mp2": return "mp2"; case "mp2": return "mp2";
default: return "m4a"; case "aac": return "m4a";
default: return "wav";
} }
} }
@@ -175,7 +176,12 @@ namespace Flowframes
{ {
Logger.Log($"[FFCmds] Merging audio from {audioPath} into {inputFile}", true); Logger.Log($"[FFCmds] Merging audio from {audioPath} into {inputFile}", true);
string tempPath = inputFile + "-temp.mp4"; string tempPath = inputFile + "-temp.mp4";
string args = $" -i {inputFile.Wrap()} -stream_loop {looptimes} -i {audioPath.Wrap()} -shortest -c copy {tempPath.Wrap()}"; if (Path.GetExtension(audioPath) == ".wav")
{
Logger.Log("Using MKV instead of MP4 to enable support for raw audio.");
tempPath = Path.ChangeExtension(tempPath, "mkv");
}
string args = $" -i {inputFile.Wrap()} -stream_loop {looptimes} -i {audioPath.Wrap()} -shortest -c copy {tempPath.Wrap()}";
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden); await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden);
if(AvProcess.lastOutputFfmpeg.Contains("Invalid data")) if(AvProcess.lastOutputFfmpeg.Contains("Invalid data"))
{ {
@@ -189,11 +195,11 @@ namespace Flowframes
public static float GetFramerate (string inputFile) public static float GetFramerate (string inputFile)
{ {
string args = $" -i {inputFile.Wrap()}"; string args = $" -i {inputFile.Wrap()}";
string streamInfo = GetFirstStreamInfo(AvProcess.GetFfmpegOutput(args)); string output = AvProcess.GetFfmpegOutput(args);
string[] entries = streamInfo.Split(','); string[] entries = output.Split(',');
foreach(string entry in entries) foreach(string entry in entries)
{ {
if (entry.Contains(" fps")) if (entry.Contains(" fps") && !entry.Contains("Input ")) // Avoid reading FPS from the filename, in case filename contains "fps"
{ {
Logger.Log("[FFCmds] FPS Entry: " + entry, true); Logger.Log("[FFCmds] FPS Entry: " + entry, true);
string num = entry.Replace(" fps", "").Trim().Replace(",", "."); string num = entry.Replace(" fps", "").Trim().Replace(",", ".");

View File

@@ -227,6 +227,8 @@ namespace Flowframes.IO
ShellFile shellFile = ShellFile.FromFilePath(path); ShellFile shellFile = ShellFile.FromFilePath(path);
fps = (float)shellFile.Properties.System.Video.FrameRate.Value / 1000f; fps = (float)shellFile.Properties.System.Video.FrameRate.Value / 1000f;
Logger.Log("Detected FPS of " + Path.GetFileName(path) + " as " + fps + " FPS", true); Logger.Log("Detected FPS of " + Path.GetFileName(path) + " as " + fps + " FPS", true);
if (fps <= 0)
throw new Exception("FPS is 0.");
} }
catch catch
{ {
@@ -359,7 +361,7 @@ namespace Flowframes.IO
public static string GetAudioFile (string basePath) public static string GetAudioFile (string basePath)
{ {
string[] exts = new string[] { "m4a", "ogg", "mp2", "mp3" }; string[] exts = new string[] { "m4a", "wav", "ogg", "mp2", "mp3" };
foreach(string ext in exts) foreach(string ext in exts)
{ {