Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with duration for audio - ffprobe #495

Open
abutir opened this issue Jan 8, 2024 · 0 comments
Open

Issue with duration for audio - ffprobe #495

abutir opened this issue Jan 8, 2024 · 0 comments

Comments

@abutir
Copy link

abutir commented Jan 8, 2024

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;
    }
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant