Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically extract audio mp3 from a youtube video?

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();
like image 722
Bryan C Avatar asked Jun 13 '10 15:06

Bryan C


2 Answers

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

like image 163
SLaks Avatar answered Oct 05 '22 12:10

SLaks


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.

like image 34
Tim Lloyd Avatar answered Oct 05 '22 11:10

Tim Lloyd