Reputation: 1594
Does anyone have any sample asp.net C# code to extract the audio from a youtube video link and save it as a mp3 file. Someone recommended using wget and ffmpeg which I installed and am trying to shell a command, but get an exception below. Sample code is listed below.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "C:\\Program Files\\GnuWin32\\bin\\wget.exe http://www.youtube.com/get_video?video_id=... | ffmpeg -i - audio.mp3";
proc.Start();
Upvotes: 5
Views: 11697
Reputation: 5650
The Process.Start(string) method is meant to start a process with no arguments. Therfore as chibacity said, you get an exception because the whole string "C:\Program Files\GnuWin32\bin\wget.exe http://www.youtube.com/get_video?video_id=... | ffmpeg -i - audio.mp3" is treated as the file name to execute. To start a process with arguments use the Process.Start(string,string) method : http://msdn.microsoft.com/en-us/library/aa326952%28v=VS.71%29.aspx.
Upvotes: 0
Reputation: 38434
You are seeing "file not found" because you are not specifying a valid file name i.e.:
"C:\\Program Files\\GnuWin32\\bin\\wget.exe http://www.youtube.com/get_video?video_id=... | ffmpeg -i - audio.mp3"
The above is not a file name, it is a file name plus some arguments, that is then piped to another executable.
As you are trying to run two executables here (wget and ffmpeg) an approach here would be to write a script (e.g a batch file) that wraps up these two executable calls and then execute the script and pass the url argument to it.
Upvotes: 3
Reputation: 887225
You should use the WebClient
class to download the file, and use ffmpeg-sharp to transcode it.
Upvotes: 3