mirror of
https://github.com/n00mkrad/flowframes.git
synced 2026-07-10 12:37:56 +02:00
Fixed Audio support for non-MP4 formats
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Flowframes.Data;
|
||||
using Flowframes.AudioVideo;
|
||||
using Flowframes.Data;
|
||||
using Flowframes.IO;
|
||||
using Flowframes.Main;
|
||||
using System;
|
||||
@@ -204,9 +205,9 @@ namespace Flowframes
|
||||
public static async Task ExtractAudio(string inputFile, string outFile) // https://stackoverflow.com/a/27413824/14274419
|
||||
{
|
||||
Logger.Log($"[FFCmds] Extracting audio from {inputFile} to {outFile}", true);
|
||||
string ext = GetAudioExt(inputFile);
|
||||
outFile = Path.ChangeExtension(outFile, ext);
|
||||
string args = $" -loglevel panic -i {inputFile.Wrap()} -vn -acodec copy {outFile.Wrap()}";
|
||||
//string ext = GetAudioExt(inputFile);
|
||||
outFile = Path.ChangeExtension(outFile, ".ogg");
|
||||
string args = $" -loglevel panic -i {inputFile.Wrap()} -vn -acodec libopus -b:a 320k {outFile.Wrap()}";
|
||||
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden);
|
||||
if (AvProcess.lastOutputFfmpeg.ToLower().Contains("error") && File.Exists(outFile)) // If broken file was written
|
||||
File.Delete(outFile);
|
||||
@@ -227,13 +228,15 @@ namespace Flowframes
|
||||
public static async Task MergeAudio(string inputFile, string audioPath, int looptimes = -1) // https://superuser.com/a/277667
|
||||
{
|
||||
Logger.Log($"[FFCmds] Merging audio from {audioPath} into {inputFile}", true);
|
||||
string tempPath = inputFile + "-temp.mp4";
|
||||
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()}";
|
||||
string tempPath = inputFile + "-temp" + Path.GetExtension(inputFile);
|
||||
// if (Path.GetExtension(audioPath) == ".wav")
|
||||
// {
|
||||
// Logger.Log("Using MKV instead of MP4 to enable support for raw audio.");
|
||||
// tempPath = Path.ChangeExtension(tempPath, "mkv");
|
||||
// }
|
||||
string aCodec = Utils.GetAudioEnc(Utils.GetCodec(Interpolate.current.outMode));
|
||||
int aKbits = Utils.GetAudioBitrate(aCodec);
|
||||
string args = $" -i {inputFile.Wrap()} -stream_loop {looptimes} -i {audioPath.Wrap()} -shortest -c:v copy -c:a {aCodec} -b:a {aKbits}k {tempPath.Wrap()}";
|
||||
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden);
|
||||
if (AvProcess.lastOutputFfmpeg.Contains("Invalid data"))
|
||||
{
|
||||
|
||||
@@ -60,6 +60,25 @@ namespace Flowframes.AudioVideo
|
||||
return args;
|
||||
}
|
||||
|
||||
public static string GetAudioEnc(Codec codec)
|
||||
{
|
||||
switch (codec)
|
||||
{
|
||||
case Codec.VP9: return "libopus";
|
||||
}
|
||||
return "aac";
|
||||
}
|
||||
|
||||
public static int GetAudioBitrate (string codec)
|
||||
{
|
||||
if (codec.Trim().ToLower() == "aac")
|
||||
return 128;
|
||||
if (codec.Trim().ToLower().Contains("opus"))
|
||||
return 112;
|
||||
|
||||
return 160;
|
||||
}
|
||||
|
||||
public static string GetExt(Interpolate.OutMode outMode, bool dot = true)
|
||||
{
|
||||
string ext = dot ? "." : "";
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Flowframes
|
||||
|
||||
if (extractAudio)
|
||||
{
|
||||
string audioFile = Path.Combine(current.tempFolder, "audio.m4a");
|
||||
string audioFile = Path.Combine(current.tempFolder, "audio");
|
||||
if (audioFile != null && !File.Exists(audioFile))
|
||||
await FFmpegCommands.ExtractAudio(inPath, audioFile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user