Reputation: 543
I am trying to run ffmpeg
executable using the Process
to convert an input audio file to mp3 format. Below is the example call that works very well when I do it from the cmd.exe
in Windows:
"ffmpeg.dll -i "inputPath\input.wav" -vn -ar 44100 -ac 2 -ab 320k -f mp3 -y "outputPath\output.mp3"
The input or output file paths can contain Turkish characters like ş ö ç ğ
. So I have to take care of the encodings of StreamWriter
.
My snippet for the StreamWriter
is:
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.CreateNoWindow = false;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
Encoding tr_encoding = Encoding.GetEncoding("iso-8859-9");
using (StreamWriter sw = new StreamWriter(cmd.StandardInput.BaseStream, tr_encoding))
{
sw.WriteLine(ffmpeg_cmd + " & exit");
}
cmd.WaitForExit();
But I always get No such file or directory
error from the ffmpeg
because the filepath contains a folder named as şşşş
but my StreamWriter
sends that folder name as ■■■
.
How to send command-line arguments in different arguments?
Upvotes: 0
Views: 910
Reputation: 543
I finally solved the problem.
iso-8859-9
was not the exact encoding type for the ş
character. I needed to use the ibm857
encoding for this.
Below is the fixed code snippet:
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
Encoding tr_encoding = Encoding.GetEncoding(857);
StreamWriter streamWriter = new StreamWriter(cmd.StandardInput.BaseStream, tr_encoding);
streamWriter.WriteLine(ffmpeg_cmd + " & exit");
streamWriter.Close();
After this, I have been able to use Turkish characters in file paths.
Upvotes: 1