Converting audio/video tracks to AAC format in C# app.

Alex1347

New member
Joined
Feb 4, 2025
Messages
2
Programming Experience
1-3
I try convert audio/video tracks to AAC format using qaac lib. In CMD it works and output information about progress of convertation. In my C# app it works too, but I can't get information about progress, i try use these events: OutputDataReceived, ErrorDataReceived. In handler of ErrorDataReceived I don't get needed information, in handler of OutputDataReceived I get received.Data like null value. How can I get conversion progress information during conversion in C# code?

(I use qaac lib because ffmpeg lib convert tracks to AAC incorrect - incorrect duration of result track, resolving not find for this problem, some analog apps have the same bug.)

Creating process for converting.:
string arguments = $"\"{engineParameters.InputFile.Filename}\" -no-delay -o \"{engineParameters.OutputFile.Filename}\"";

processStartInfo = new ProcessStartInfo
{
    FileName = QaacFilePath,
    Arguments = arguments,
    RedirectStandardOutput = true,
    UseShellExecute = false,
    CreateNoWindow = true,
    WindowStyle = ProcessWindowStyle.Hidden
};

Also i call these methods for process:
C#:
BeginOutputReadLine();
BeginErrorReadLine();
WaitForExit();

Handlers:
C#:
this.Process.OutputDataReceived += (sender, received) =>
{
    if (received.Data == null) return;
    //Some code...
}

C#:
this.Process.ErrorDataReceived += (sender, received) =>
{
    if (received.Data == null) return;
    //Some code...
}
 
Last edited:
If "qaac lib" is truly a library, why don't you just PInvoke the APIs of the library directly? I have a feeling based on a quick scan of the documentation links that "qaac" is actually a "prog" or "cli" and not a "lib".
 
Yup, looking at the source code, it definitely is a command line application, and not a library.

Anyway, part of the reason you are not getting any progress output is because the PeriodicDisplay class checks to see if the console window is visible. Since you are launching the app to be in a hidden window, then the progress is not displayed.

 
To effectively capture the conversion progress in your application, ensure that the qaac tool is configured to output progress information to the standard output stream. The issue you are encountering, where received.Data is null, may stem from the qaac tool not sending progress updates to the standard output as expected.

Here’s another approach to your implementation:
Check qaac Output Settings
: Ensure that qaac is set to provide verbose output. You might need to add a flag like -v to your arguments to enable detailed logging.
Modify Process Start Info: Ensure that the RedirectStandardError is also set to true, as some tools may output progress information to the error stream instead.
Example Code:

C#:
string arguments = $"\"{engineParameters.InputFile.Filename}\" -no-delay -o \"{engineParameters.OutputFile.Filename}\" -v";

processStartInfo = new ProcessStartInfo
{
    FileName = QaacFilePath,
    Arguments = arguments,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    UseShellExecute = false,
    CreateNoWindow = true,
    WindowStyle = ProcessWindowStyle.Hidden
};

this.Process.OutputDataReceived += (sender, received) =>
{
    if (!string.IsNullOrEmpty(received.Data))
    {
        Console.WriteLine($"Output: {received.Data}");
        // Process the output data for progress
    }
};

this.Process.ErrorDataReceived += (sender, received) =>
{
    if (!string.IsNullOrEmpty(received.Data))
    {
        Console.WriteLine($"Error: {received.Data}");
        // Handle error data if necessary
    }
};

this.Process.Start();
this.Process.BeginOutputReadLine();
this.Process.BeginErrorReadLine();
this.Process.WaitForExit();

By ensuring that both standard output and error streams are redirected, you should be able to capture the necessary progress information during the conversion process.
 
@Rythorian : It seems like you are using an AI to generate your responses. Please double check that it is not hallucinating
The -v flag for qaac is not to tell it to produce verbose output.

Also the OP showed in post #1 that they are correctly doing the appropriate output and error redirection and capture.

You also seemed to ignore post #3 where I showed that progress reports are deliberately disabled when the console window is not visible.
 
Double check yourself pal
I did double check before I commented in post #5:

1740367533736.png


and also:
C++:
#include <limits>
#include "options.h"
#include "win32util.h"
#include "wgetopt.h"
#include "metadata.h"

static getopt::option long_options[] = {
#ifdef QAAC
    { L"formats", no_argument, 0, 'fmts' },
    { L"abr", required_argument, 0, 'a' },
    { L"tvbr", required_argument, 0, 'V' },
    { L"cvbr", required_argument, 0, 'v' },
 
Back
Top Bottom