0

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?

abdullah cinar
  • 543
  • 1
  • 6
  • 20
  • try using utf8 strings - also try something like https://stackoverflow.com/questions/38533903/set-c-sharp-console-application-to-unicode-output – BugFinder Apr 24 '18 at 07:57
  • And why do you need to run cmd.exe at all, and write to its input? Just run ffmpeg directly. – Evk Apr 24 '18 at 08:18
  • @BugFinder Actually I couldn't run it with converting the strings in those topics either. Regarding your second answer, I was converting them with cmd.exe in windows, so I just wanted to do it in the ways in examples since I'm new to C#. Do you think it can be related to this? – abdullah cinar Apr 24 '18 at 08:28

1 Answers1

1

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.

abdullah cinar
  • 543
  • 1
  • 6
  • 20