开发者

How to programmatically extract audio mp3 from a youtube video?

开发者 https://www.devze.com 2023-01-03 12:50 出处:网络
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

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 c开发者_Python百科ode 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();


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消