views:

123

answers:

3

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();
+3  A: 

You should use the WebClient class to download the file, and use ffmpeg-sharp to transcode it.

SLaks
do you have any sample code that you can share?
Zap
+3  A: 

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.

chibacity
I'm still unable to get a batch file to run properly. Can someone help troubleshoot? I bring up cmd.exe and go to directory where ffmpeg is in and try running this command: "C:\Program Files\GnuWin32\\bin\wget.exe youtube.com/get_video?video_id=2O0kuoiAm2A | ffmpeg.exe -i - c:/temp/mp3/audio.mp3" I get a system cannot find the file specified error
Zap
Your accept rate is very low.
chibacity
I recently read downloading a video from youtube is no longer possible. Can anyone confirm?
Zap
A: 

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.

apoorv020
I recently read downloading a video from youtube is no longer possible. Can anyone confirm?
Zap