mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-02-06 16:59:43 -06:00
FF-1589: Added timeouts to ffmpeg/ffprobe to Audio File read info
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
|
||||
namespace FileFlows.AudioNodes;
|
||||
|
||||
@@ -19,17 +21,18 @@ public class FFprobeAudioInfo
|
||||
/// </summary>
|
||||
/// <param name="json">the json output from FFprobe</param>
|
||||
/// <returns>the AudioFormatInfo parsed</returns>
|
||||
[RequiresUnreferencedCode("")]
|
||||
public static Result<AudioFormatInfo> Parse(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
#pragma warning disable IL2026
|
||||
var ffAudioFormatInfo = JsonSerializer.Deserialize<FFprobeAudioInfo>(json,
|
||||
new JsonSerializerOptions()
|
||||
{
|
||||
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
|
||||
IgnoreNullValues = true,
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
#pragma warning restore IL2026
|
||||
return ffAudioFormatInfo.Format;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -211,7 +211,7 @@ public class AudioInfoHelper
|
||||
audioInfo.Disc = disc;
|
||||
audioInfo.Duration = (long)result.Value.Duration.TotalSeconds;
|
||||
audioInfo.Genres = result.Value.Tags?.Genre
|
||||
.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries)?.Select(x => x.Trim())
|
||||
?.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries)?.Select(x => x.Trim())
|
||||
?.ToArray();
|
||||
audioInfo.Title = result.Value.Tags.Title;
|
||||
if (int.TryParse(result.Value.Tags.Track, out int track))
|
||||
@@ -264,13 +264,11 @@ public class AudioInfoHelper
|
||||
return Result<string>.Fail("Process timed out." + Environment.NewLine + pkOutput);
|
||||
}
|
||||
|
||||
// we use error here, since we're not specify an output file, FFmpeg will report it as an error, but we don't care
|
||||
string output = process.StandardOutput.ReadToEnd();
|
||||
string error = process.StandardError.ReadToEnd();
|
||||
|
||||
if (string.IsNullOrEmpty(error) == false)
|
||||
return Result<string>.Fail($"Failed reading ffmpeg info: {error}");
|
||||
|
||||
return output;
|
||||
return output?.EmptyAsNull() ?? error;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -4,10 +4,11 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using AudioNodes.Tests;
|
||||
|
||||
namespace FileFlows.AudioNodes.Tests;
|
||||
[TestClass]
|
||||
public class AudioInfoTests
|
||||
public class AudioInfoTests: AudioTestBase
|
||||
{
|
||||
const string file = @"/home/john/Music/test/test.wav";
|
||||
readonly string ffmpegExe = (OperatingSystem.IsLinux() ? "/usr/local/bin/ffmpeg" : @"C:\utils\ffmpeg\ffmpeg.exe");
|
||||
@@ -16,17 +17,16 @@ public class AudioInfoTests
|
||||
[TestMethod]
|
||||
public void AudioInfo_SplitTrack()
|
||||
{
|
||||
var logger = new TestLogger();
|
||||
var args = new FileFlows.Plugin.NodeParameters(file, logger, false, string.Empty, null);;
|
||||
args.GetToolPathActual = (string tool) => ffmpegExe;
|
||||
args.TempPath = @"/home/john/Music/temp";
|
||||
var args = GetNodeParameters(TestFile_Mp3);
|
||||
var af = new AudioFile();
|
||||
af.PreExecute(args);
|
||||
var result = af.Execute(args); // need to read the Audio info and set it
|
||||
|
||||
var result = new AudioInfoHelper(ffmpegExe, ffprobe, args.Logger).Read(args.WorkingFile);
|
||||
Assert.IsFalse(result.IsFailed);
|
||||
Assert.AreEqual(1, result);
|
||||
|
||||
var AudioInfo = result.Value;
|
||||
var AudioInfo = args.Parameters["AudioInfo"] as AudioInfo;
|
||||
|
||||
Assert.AreEqual(9, AudioInfo.Track);
|
||||
Assert.AreEqual(4, AudioInfo.Track);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
Reference in New Issue
Block a user