Transcoding audio and video - audio

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.

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

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).

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.

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 :-).

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...

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.

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.

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

Related

Ffmpeg, avconv and sameq

Earlier I wrote so:
ffmpeg -i input.mp4 -sameq output.mp3
...and thus receive audio from video file. Ffmpeg just taken out or converted audio to mp3 with an appropriate quality. All thanks to key: -sameq [use same quantizer as source]
Now in Ubuntu instead of ffmpeg we have libav and there (in man for avcomv) I see no -sameq key. Well, here is a question: what I have to do now?..
What I have to do now to get converted audio file with the same quality as in original?
PS. -sameq : Use same quantizer as source (implies VBR).
$ man ffmpeg | col -b > ./man_ffmpeg
this man_ffmpeg is there: http://pastebin.com/qYxz1M1E
FFMPEG(1)
NAME
ffmpeg - ffmpeg video converter
SYNOPSIS
ffmpeg [[infile options][-i infile]]... {[outfile options] outfile}...
...
...
...
-sameq
Use same quantizer as source (implies VBR).
...
...
...
SEE ALSO
avplay(1), avprobe(1), avserver(1) and the Libav HTML documentation
AUTHORS
The Libav developers
2014-02-06
FFMPEG(1)
You are correct, -sameq option has been deprecated and then removed from avconv, there were many reasons for it. Not the least of it being that there are different quantizers and it makes little sense talking about same quantizer parameters when reencoding between different codecs.
Majority of people, when reencoding are looking for quality, not quantizers. So they should use -qscale n where n is between 1 and 31 representing quality from best to worst.
In a way if you have gotten used to -sameq option, you have fallen victim to a tool that should have been there at best for testing purposes. It doesn't produce anything reasonable, and can be kinned to trying to put "same metadata" into the container that doesn't support it, or doing "copy stream" into an archaic file format (leading to things like AVI with vorbis audio, that can't even be played). You can hack something together that does all these things, but it has no place in a video encoding tool.
I suggest that if you are going to be doing much stress testing of different containers and codecs, then you install ffmpeg which has more tools allowing the creation of frankensteins. If you are reencoding for the purposes of actually keeping the files that you produce or distributing them, than you can create another question explaining your situation, and what is your desired outcome.
In short "How can i create reencoding process with exactly the same quantizer?" Can only be answered with "No".

Include simple sound in iphone app

I searched many questions - but no one seems to be giving simplest, most uniform approach, hence please do not close as duplicate.
My requirement is simple: I have quiz app.
I want to include:
background music that plays continually - probably more than one
audio.
I need occassional sounds played at specific events - they
are very short in duration. Maybe 4-5 in number.
What sound format do I use? [aac etc]
How do I produce it? (optionally, get it from internet, if free)
What is the best approach to incorporate it? [audioplayback, openal etc)
Forgive me if this is quite stupid, but I am going very generic here and can't seem to find it.
Thanks for the help!
For sound format, use AAC or uncompressed 16-bit little endian in a CAF container (avoid mp3 since it's difficult to make it loop cleanly). You can convert using the command line tool 'afconvert':
Compressed:
afconvert -f caff -d aac sourcefile.wav destfile.caf
Uncompressed 16-bit:
afconvert -f caff -d LEI16 sourcefile.wav destfile.caf
For production, either record it yourself (using an audio program such as Audacity), get a professional to do it, or buy royalty free sounds/music.
To incorporate it, use AVAudioPlayer for music and OpenAL for sounds. OpenAL is difficult to use and doesn't decode compressed audio on its own, so you may want to use an audio library such as https://github.com/kstenerud/ObjectAL-for-iPhone

How do i sample an audio file say .wav , in an 8 bit 8khz parameter

i am not that big on programming and i need to sample an audio file that is recorded via a mobile, i understand that the mobile device records the voice, and there are sample rates and each sample has a 8bit or 16 bit sample size. i need 8 bit sample size in 8khz. the programming environment is lua but that doesnt matter really the basic deal is sampling. Any help would be appreciated.
You need to either set your recording parameters at the time that you record the sound sample to 8 bits # 8 kHz, or, if you can't, or don't have any control over the actual recording process, then you will need to resample the original recording to get it into the format that you need. You can do this off-line with a tool such as SoX, or you can write code that does this on-the-fly. If you give more detail in your question then I can add more specific detail in my answer.
I don't know about lua, but as suggested by Paul R, you can always post-process your audio files using SoX or ffmpeg. On linux, just install ffmpeg :
sudo apt-get install ffmpeg
Then :
ffmpeg -i trenet.wav -ar 8000 trenet-8k.wav
This resamples your audio at 8000 Hz. I did not find how to deal with the bits/sample parameter but you can always tune the bitrate. For documentation :
man ffmpeg

Mix Audio tracks with offset in SOX

From ASP.Net, I am using FFMPEG to convert flv files on a Flash Media Server to wavs that I need to mix into a single MP3 file. I originally attempted this entirely with FFMPEG but eventually gave up on the mixing step because I don't believe it it possible to combine audio only tracks into a single result file. I would love to be wrong.
I am now using FFMPEG to access the FLV files and extract the audio track to wav so that SOX can mix them. The problem is that I must offset one of the audio tracks by a few seconds so that they are synchronized. Each file is one half of a conversation between a student and a teacher. For example teacher.wav might need to begin 3.3 seconds after student.wav. I can only figure out how to mix the files with SOX where both tracks begin at the same time.
My best attempt at this point is:
ffmpeg -y -i rtmp://server/appName/instance/student.flv -ac 1 student.wav
ffmpeg -y -i rtmp://server/appName/instance/teacher.flv -ac 1 teacher.wav
sox -m student.wav teacher.wav combined.mp3 splice 3.3
These tools (FFMEG/SoX) were chosen based on my best research, but are not required. Any working solution would allow an ASP.Net service to input the two FMS flvs and create a combined MP3 using open-source or free tools.
EDIT:
I was able to offset the files using the delay switch in SOX.
sox -M student.wav teacher.wav combined.mp3 delay 2.8
I'm leaving the question open in case someone has a better approach than the combined FFMPEG/SOX solution.
For what it's worth, this should be possible with a combination of -itsoffset and the amix filter, but a bug with -itsoffset prevents it. If it worked, the command would look something like this:
ffmpeg -i student.flv -itsoffset 3.3 -i teacher.flv -vn -filter_complex amix out.mp3
mixing can be pretty simple: how to mix two audio channels?
well i suggest you should use flash.
it may sounds weird, correct me if im wrong but with Flash's new multimedia abilities you can mix a couple tracks.
im not sure, but i'm just trying to help you,
theese 2 link can help you for your aim (specially second link i guess);
http://3d2f.com/programs/25-187-swf-to-mp3-converter-download.shtml
http://blog.debit.nl/2009/02/mp3-to-swf-converter-in-actionscript-3/

How to develop an AAC converter for Linux?

I am a beginner developer want to develop a MP3 to AAC converter for Linux. But I don't know how to start as I havn't done any development in Linux before. I am using Ubuntu 10.04. Can anyone tell me how to start and from where? What libraries do I need?
Thanks
If you want to use an encoder, FAAC is open source, so you could write a program that uses it. Or check out the source code.
I.A.N.A.L. but, AAC is a patented technology, so you may have to pay fees to make a commercial project.
A good place to start learning how lots of Unix programs are written, is using the GNU toolchain, GCC, Make, Configure etc...
The ffmpeg libraries are a great swiss army knife for anything dealing with audio/video. In fact, you can use the ffmpeg command-line interface to easily convert between MP3 and AAC:
ffmpeg -i <path to MP3 file> <path to AAC file>
This requires that ffmpeg be compiled with FAAC and LAME support. I don't think Ubuntu's ffmpeg libraries include these by default for legal reasons, but there are ways to install MP3 and AAC enabled versions: http://gebaar.blogspot.com/2009/06/howto-easily-enable-mp3-mpeg4-aac-and.html
If you want to use ffmpeg's underlying libraries (libavcodec, libavformat, etc) to code it yourself: http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/api-example_8c-source.html

Resources