Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello huy,

I want to convert aac format to mp3 using the ffmpeg.exe.
I found its easy and no problem.
But I was caught in a trap when I wanted to save the output to specific directory.

C#
private const string FffmpegArguments = "-acodec mp3 -ac 2 -ab 160k";


 foreach (InputFile inputFile in this.inputFiles)
            {
                string input = Path.Combine(inputFile.Location, inputFile.Name);

                string output = Path.Combine(
                    inputFile.Location,
                    Path.GetFileNameWithoutExtension(inputFile.Name) + "." + OutputExt);

                ProcessStartInfo startInfo = new ProcessStartInfo(
                        "ffmpeg.exe",
                        string.Format(@" -i ""{0}"" {1} ""{2}""", input, FffmpegArguments, output))
                {
                WindowStyle = ProcessWindowStyle.Hidden,
                UseShellExecute = false,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                CreateNoWindow = true
                };

                Process proc = new Process { StartInfo = startInfo };

                proc.Start();
            }


It saves the output but its damaged what seems to be the problem?

When I try to open the output mp3 I get this :
Output mp3 file
Posted
Updated 13-Jun-14 3:20am
v4
Comments
[no name] 13-Jun-14 9:01am    
The "output error" is a link to your incomplete question?
Zhivko Kabaivanov 13-Jun-14 9:07am    
Nope, I want to have successfull convertion
Sergey Alexandrovich Kryukov 13-Jun-14 9:18am    
What corruption? Why redirecting anything when you don't actually use redirected strings?

Attention: to reply, reply to the comment you want to reply, otherwise we won't get notifications.

—SA
Zhivko Kabaivanov 13-Jun-14 9:20am    
Now its ok
Sergey Alexandrovich Kryukov 13-Jun-14 9:32am    
I though it would work: I could not find essential mistakes.
The only somewhat incorrect piece is + '.' +...
It's the best to avoid using multiple string concatenation (strings are immutable! do I need to explain the consequence?) and hard-coded '.'. Use ChangeExtension method instead.
—SA

1 solution

As Sergey stated, I would rather use:
C#
UseShellExecute = true,
RedirectStandardInput = false,
RedirectStandardOutput = false,
RedirectStandardError = false,

and see if it does the trick.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900