views:

116

answers:

1

Hey,

I'm trying to create a C# application which allows me to extract just the audio from YouTube videos. I've come across sites that already do that, but I'm not sure how they actually work. What would be the best way to do this programmatically?

Thanks for any advice

+3  A: 

Writing an application for this might be overkill. Existing tools already do a pretty good job, and it's hard to beat their simplicity:

wget http://www.youtube.com/get_video.php?video_id=... |
  ffmpeg -i - audio.mp3

All done!

If your application needs to do something special with the audio afterwards, it would make sense to write an app for that part. But for just getting the audio out, shelling out to ffmpeg will be a lot easier.

John Feminella
Thanks for the reply. I'm considering porting this to mobile devices, so I'm not sure how valid the ffmpeg/wget library is. (Not to say it isn't, I just need to do a bit more research).
Skoder
These libraries are written in C and can often compile on other platforms with the right flags. I assume you're looking at Android if you're thinking about C# on a mobile platform, in which case `wget` and `ffmpeg` have both successfully been built. Note that, generally speaking, doing media processing is a very expensive, CPU-intensive, battery-draining operation. It might be smarter to do this on a server and pipe the audio file back to the mobile client.
John Feminella
Thanks! You also answered another question I was going to ask further down the line regarding cost of audio processing. I think I'll create a webservice that invokes the extraction code and returns the audio stream.
Skoder
Can anyone post the exact sample code to do this from C# asp.net page? Also, what namespace is wget part of?
Zap
Zap: `wget` and `ffmpeg` are executables, not C# objects.
John Feminella
Thanks. I've installed both wget and ffmpeg and tried shelling a command by: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/watch?v=... | ffmpeg -i - audio.mp3"; proc.Start();I get an exception stating it can find binary.
Zap
@Zap: Well, first off, you have to use `get_video` (which retrieves the actual video resource), not `watch` (which is the whole page). Second, `ffmpeg` probably isn't on your path. You'll probably want to start a new question for this -- comments aren't the best way to have a full discussion.
John Feminella
I've posted new question.
Zap