views:

929

answers:

8

What is the best way to transcode audio and video to show on the web?

I need to do it programmatically. I'd like to do something like YouTube or Google Video where users can upload whatever format they want, and I encode it to flv, mp3, and/or mp4. I could do it on our server, but I would rather use an EC2 instance or even a web service. We have a Windows 2008 server.

+2  A: 

ffmpeg can do it, its a command-line tool that uses the libavcodec. Can handle conversion of most video formats. Its license is LPGL, if that suits your needs. You can utilize it as a separate process programmatically, or if you're feeling hardcore, you can use the libavcodec library yourself to encode directly.

JimDaniel
+1  A: 

Do be aware that certain parts of ffmpeg are under GPL. I believe the libpostproc module is and if I recall correctly this is used in transcoding. Make sure this license is compatible with what you're doing.

dpp
Actually GPL parts of ffmpeg are optional and included only if you run ./configure with --enable-gpl option.
mouviciel
@mouviciel, you're right: most of FFMPEG is under LGPL but there are some components under GPL. The question references one of those areas that I believe would require GPL.
dpp
GPL is perfectly acceptable if it's running in your own server. It's only Affero GPL stuff that could be problematic.
TRiG
+2  A: 

When you want to transcode to Flv (which is probably the best for the web) then I use this line:

ffmpeg -hq -y -i $directory/$file -r 20 -s 300x200 -deinterlace -ar 22050 $directory/$file.flv 1>/dev/null 2>/dev/null

It works very well, under linux of course :-).

masc
+1  A: 

I would take a look at Main Concept's Reference SDK:

http://www.mainconcept.com/site/developer-products-6/pc-based-sdks-20974/reference-sdk-21221/information-21243.html

It is built for transcoding and, since it is a licensed SDK it doesn't have any of the legal issues surrounding ffmpeg/libavcodec.

Nick Haddad
+3  A: 

kind of depends on how much you want to spend. if this is a brand new (and mostly unfunded) idea, then go the ffmpeg route, but as you scale and look to iprove the quality, consider one of the more professional encoding tools that can be automated (Rhozet, Inlet, Digital Rapids are 3 options).

+1  A: 

If you are looking for GPL'ed stuff:

For audio mucking about, try sox. Very powerful! It does a lot! It's included in most linux distributions.

There is also the famous LAME for mp3 [audio] encoding.

For video, mencoder is impressive! It's part of the mplayer package. It will handle conversions from most video formats. Far more than I ever dreamed existed. (For documentation, see Chapter 9. Basic usage of MEncoder and Chapter 10. Encoding with MEncoder.)

It's somewhat more limited about what it can create. But it does support mpeg4, mpeg2, dvd-mpeg, flv, and many others. (While I haven't tried flv myself, google shows other folks are using it.)

I have done things like jpeg + sound -> mpeg4 movie:

nice +20 $MENCODER mf://${JPEGFILE}  -mf w=720:h=480:fps=1/${SOUNDLENGTH}:type=jpeg -audiofile ${SOUNDFILE} -ovc lavc -oac lavc -lavcopts vcodec=mpeg4 -ofps 30000/1001 -o ${MENU_MPG}

Or transcode arbitrarily formated video to dvd-compatible mpeg:

nice +20 $MENCODER -edl ${EDL} -ovc lavc -oac lavc -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=${VBITRATE}:keyint=18:acodec=ac3:abitrate=192:aspect=4/3:trell:mbd=2:dia=4:cmp=3:precmp=3:ildctcmp=3:subcmp=3:mbcmp=3:cbp:mv0:dc=10 -of mpeg -mpegopts format=dvd -vf scale=720:480,harddup -srate 48000 -af lavcresample=48000 -ofps 30000/1001 -o ./${INFILE}.reformatted  ${FILEPATH}

-edl/-edlout [Edit Decision Lists] are used to snip out just the video sections I want.

${VBITRATE} is normally 5000 for DVD-mpeg-video. But if you flub it a bit you can squeeze more video onto a dvd. Assuming you can tolerate the artifacts.

scale=720:480,harddup -- Little issue with the scale being wrong for my dvdplayer, and harddup to resolve a sound-video desync issue on my "el cheapo" player.

(To playback on a widescreen player that wouldn't handle 4x3 video, I've used atrocities like "aspect=16/9", "-vf scale=560:480,expand=720:480,harddup". But in general you don't want to waste bits encoding black-bars.)

This is not the most efficient set of options to mencoder by far! It can be time consuming to run. But I had other goals in mind...

Mr.Ree
A: 

Rhozet Carbon Coder can handle a wide range of formats plus you can use plugins to alter the video (eg add a watermark)

hamishmcn
+1  A: 

I strongly recommend ffmpeg. On Windows, I have found this site to host good binaries.

geekpreacher