Issue with duration for audio - ffprobe
Opened this issue · 0 comments
abutir commented
when using ffprobe analyse in aws lambda it returns the object half with default values . even though the same code works perfectly locally . could be something to do with different enviroments.
i needed the duration out of the FFProbeAnalysis but it always comes out zero .
for anyone in the future here is a helper class to get the ffprobe analysis . please note that the values are not parsed . so you have to parse them to your liking ( you can find the parse class in the library )
`public class FFProbeHelper
{
public static async Task<FFProbeAnalysis> AnalyzeRawAsync(Stream memoryStream, string ffprobePath, string tmpFilePath = "")
{
if (string.IsNullOrWhiteSpace(tmpFilePath))
tmpFilePath = $"tmp/{Guid.NewGuid()}.mp3"; // the tmp file path should be passed in case of lambda functions with prefix /tmp/..
await using (var fileStream = File.Create(tmpFilePath)) {
memoryStream.Seek(0, SeekOrigin.Begin);
await memoryStream.CopyToAsync(fileStream);
}
using var process = new Process();
process.StartInfo = new ProcessStartInfo {
FileName = ffprobePath,
Arguments = $"-loglevel error -print_format json -show_format -sexagesimal -show_streams -show_chapters -i {tmpFilePath}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
try {
process.Start();
var output = await process.StandardOutput.ReadToEndAsync();
await process.WaitForExitAsync();
File.Delete(tmpFilePath);
var analysis = JsonSerializer.Deserialize<FFProbeAnalysis>(string.Join(string.Empty, output), new JsonSerializerOptions() {PropertyNameCaseInsensitive = true});
return analysis;
}
catch (Exception e) {
Console.WriteLine("exception : " + e.Message);
throw;
}
}
}`