0

I am trying to pipe youtube-dl output to ffmpeg as input, but cannot seem to get the piping part to work. In normal cmd, I can do something like

 C:\YT\youtube-dl.exe -o - https://www.youtube.com/watch?v=L4aLQ0ki9Tk | ffmpeg -i pipe:0 -f asf pipe:1 

but in c# this doesn't work. Currently, I have c# create 2 processes:

one for youtube-dl

C:\YT\youtube-dl.exe -o - https://www.youtube.com/watch?v=L4aLQ0ki9Tk

and another for ffmpeg

ffmpeg  -i {yt.StandardOutput} -f s16le -ar 48000 -ac 2 pipe:1

The problem is with the {yt.StandardOutput} (where yt is the process name of the youtube-dl process and -i specifies the input file/stream). Using pipe:0 doesn't work either and I am not sure how to link the piped output of the first to the input of the second.

Masoud Andalibi
  • 3,168
  • 5
  • 18
  • 44
  • See [this SO](http://stackoverflow.com/questions/13806153/example-of-named-pipes.aspx). However named pipes have a lot of overhead; you should read this [msdn article](https://msdn.microsoft.com/en-us/library/bb546102(v=vs.110).aspx) about anonymous pipes with C# demo code. – RamblinRose Jan 01 '17 at 17:49

2 Answers2

0

When doing your processing instead of starting youtube-dl.exe and ffmpeg as separate processes start the command shell itself from your code using cmd.exe /C this will allow you to use the pipe to flow the context from one program to another.

var proc = Process.Start("cmd.exe", 
                         "/C C:\YT\youtube-dl.exe -o - https://www.youtube.com/watch?v=L4aLQ0ki9Tk | ffmpeg -i pipe:0 -f asf pipe:1");
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
0

pipe:0 is stdin, so when you start ffmpeg.exe you could set RedirectStandardInput = true, then use the Process StandardInput property to get the stream to write to, you can then hook this up to the StandardOutput property of the other process with StreamReader + StreamWriter + byte array buffer.

In fact, just found an example on Github: https://github.com/theogeer/aaxtomp3/blob/b05514036dff85d9c395bfa5d9bf272f6361e729/AaxToMp3GUI/AaxToMp3GUI/Converter.cs

Stuart
  • 5,358
  • 19
  • 28