Encoding Video For Mobile Devices?
MadGeek007 writes "I am developing an app for Android that will use many short (averaging 10-20 minutes) instructional videos. Unfortunately, I know next to nothing about encoding video. I'd like to use a codec that is supported by Android and iOS out-of-the-box. I need the videos to look decent on large mobile displays (IPhone 4, HTC EVO, etc.), and still be able to stream well on a good 3G connection. The sound quality is also important. With so many different display resolutions on mobile devices, do I need to encode multiple copies of the same video? Or can I get away with a one-size-fits-all video? Can anyone recommend encoding software, codecs, resolutions, and bitrates that would work best for this application?"
Handbrake is what I use:
http://handbrake.fr/
While it does mean you'll use up a little extra storage it is probably best to encode one version for each resolution, h.264 tends to be the standard in video these days (especially for mobile devices since they tend to have h.264 decoding hardware).
By using one resolution per device (or at least for the more common devices and then a couple of fallback resolutions) you ensure the best possible quality for the largest number of users while also avoiding wasting a lot of bandwidth streaming high-res iPhone 4-res video to some other phone just because you didn't want your video to look like crap on the iPhone.
Greylisting is to SMTP as NAT is to IPv4
For iOS pretty much the only choice is MPEG-4, H.264.
I believe Android supports it as well.
Apple actually has a decent section in their web developer section on developer.apple.com about what is supported for iOS.
The android developers site has an excellent list of supported media formats. http://developer.android.com/guide/appendix/media-formats.html The iphone 4 specifications http://www.apple.com/iphone/specs.html claims that the iPhone 4 supports AAC-LC and h.264 which android supports as well. So looks like you have an easy match for high quality as well.
Well, for Android you could always use WebM, and for iOS H.264.
Michael
http://s1.sfgame.us/index.php?rec=58163
As others mentioned, make it an h264 video with aac audio. I suggest using mediacoder, a free encoder with a billion options, including preconfigured iphone profiles I believe. Others suggest handbrake but I've found in the past that mediacoder looks like it has a lot more options to fiddle with. YMMV though, I've read handbrake has come a long way since ditching the "only encode DVDs" thing It used to do exclusively.
If you wish to hit iOS H.264 is your only option. Apple has very strict requirements on applications that stream over 3g, including a 60k/s variant. (If you don't mean actual streaming but just progressive download thats different). You can look those up on the Apple developer forums.
The sound quality is also important.
You say you are making instructional videos, which implies to me the audio will contain mostly speech. If that is indeed the case, then a low bitrate like 64 kbps in mono will probably suffice. Encoders like MP3 or AAC are very good at keeping speech intelligible at lower bitrates.
Pretty good is actually pretty bad.
It will use less power to play h264 in hardware then MPEG2 in software. And all of the phones will have hardware h264 decoders.
I'm assuming you're talking about web video; if not, this info won't be applicable. The 'Video for Everybody' project at Camen Design has put a lot of work into cross-platform HTML5 video, and the test page has an extensive compatibility matrix for both desktop and mobile platforms.
Be aware that if you're targeting Android, its implementation of HTML5 video is lackluster (for now; I'd expect this to get better soon). Details of the problems, and a few solutions, can be found here: http://www.broken-links.com/2010/07/08/making-html5-video-work-on-android-phones/.
Isn't this a better question for StackOverflow.com?
I am under Ubuntu and uses QT-AVIdemux and uses MENU: Auto-> Apple-> Apple Ipod
Works everytime.
DO NOT USE THE GTK VERSION as the auto facilities are not included.
Tomorrow is another day...
Assuming the video is already in a non encrypted format (read- not on a DVD) I recommend mediacoder (http://www.mediacoderhq.com/index.htm). It's free, runs pretty much everything, and has a bounty of features.
The mobile version is OK (assuming you know what device). If you get the full version you can control just about everything (video size, native resolution, bitrate, encoder, effects, etc...).
I would recommend playing with the settings, seeing what works and what doesn't work, then saving the final set-up as preset.
The one issue I've run into with mediacoder is subtitles. It burns subtitles into the video, even if you choose the "do not render" option. If you start with an .mkv remove the subtitles using mkv merge (http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge-gui.html), then process away. Both video and audio are straight forward, and should allow for whatever you're doing.
The forum for mediacoder should answer any other questions you might have. Best of luck to you, and remember that commercial users of mediacoder should seriously consider donating to keep the project running.
And MPEG2 in hardware less still. And for mobile devices without H.264 hardware assist, you don't have H.264 hardware assist, so you're back to software decoding which is much cheaper with MPEG2 than with H.264.
As others have suggested, handbrake + h.264
But my thought is, 10-20 minute instructional videos? Especially on a mobile device?
Break it up into 2-4 minute segments. No one is going to watch a 20 minute video, and retain what was in minute 0-6. zzzzzzzzzz
Upload to youtube and forget about it.
vlc.exe -vvv -I dummy myvideo.avi --sout="#transcode{ab=96,samplerate=44100,channels=2,acodec=mp4a,vcodec=h264,width=480,height=320,vfilter="canvas{width=480,height=320,aspect=16:9}",fps=25,vb=900,venc=x264{profile=baseline,level=3.0,no-cabac,keyint=75,ref=3,bframes=0}}
--sout="#transcode{threads=2,high-priority,audio-sync,acodec=mp4a,ab=64,samplerate=22050,channels=2,vcodec=mp4v,fps=23.976,vb=900,width=480,height=320,vfilter="canvas{width=480,height=320,aspect=16:9}",venc=ffmpeg{qmax=20}}
File>Export>Movie to Iphone
"The problem with socialism is eventually you run out of other people's money" - Thatcher.
Well, for Android you could always use WebM, and for iOS H.264.
Oh really? Oh what currently shipping device would that work?
If you can name a shipping device on which that would work, then mull over the battery implications of playing back hardware decoded video vs. using the mobile CPU to do all the decoding.
WebM is a great idea and it will be interesting to see if Google can push hardware makers to support it, but to suggest using it for anything that plans to ship in under a year is awful advice.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
I'm not sure if Android supports this yet, but the best way to do what you want is to encode at a few different bitrates, and build an M3U8 wrapper which basically describes what video to use at the current bandwidth available to the device. You point the player at that file, then the player makes the choice at runtime which of the feeds to use.
I'm not sure if you need anything specific on the server side beyond encoding all the video in h.264.
Even if you can't do this for Android it's still well worth supporting on the iPhone, since someone on WiFi can have a much better quality video viewing experience than someone on 3G.
You also might consider bundling lower quality versions with the app for times when there is no network to be had - though with so many videos, it might only be practical to cache from the server or not cache at all.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
H.264 with aac for both. Http live streaming on ios, progressive downloads on everything else... Seriously, why waste your time doing this solo? plenty of companies already do this stuff almost for free a lot better than you can do it by yourself. Ooyala or brightcove are good for web. Synctv does web and custom apps across every major platform (ios , android, pre, yahoo widgets, bluray, roku, etc...) You can waste months developing something not even close to as good.
That requirement pretty much restricts the choice to H.264. I think Android and iOS both have 3GPP support (not sure), and maybe H.263, but they're both rather terrible quality.
The shame is that, and don't rip me a new one for saying this, Theora is otherwise a perfect solution. Most smartphones in the last few years will manage QVGA (320x240) software-only decode perfectly fine. That means it's a baseline that will work on nearly all Android handsets and any iOS platform from 3G onwards. QVGA is a perfectly acceptable resolution, bearing in mind you want this to fit reliably on a 3G link. I'm sure many will be telling you to cram a 800x480 1mbps video down to handsets, but that's extreme overkill.
As for audio, oddly enough a baseline may be MP3. You only need 48kbit for a high quality mono stream. Any more is overkill. You can go for AAC if you really must. Again, the shame here is that Vorbis would otherwise be a perfect solution.
Summary: H.264/AAC/MP3. In an ideal world Theora/Vorbis, but sadly there's too much political shenanigans and misinformation to make that a reality. (And because of that, it's not available out-of-the-box on these handsets)
What's wrong with 320x240 (QVGA)? This is supposed to go over a 3G link, and quite frankly if it's just some instructional videos, you don't need crisp, crystal clear video. Going for low resolution also means you can turn down the 'profile' settings for the encoder, ensuring it works on a wider variety of handsets.
I think you'll be surprised just how good low resolution video works. Most of the quality difference is from codec choice, not resolution. I think most people are imagining crappy 3GPP and/or H.263 videos (old flash). iPhone 4 may have a high resolution display, but it's still only a few inches. Even the larger form factor handsets aren't big enough to warrant high resolution videos, quite frankly. We're not talking entertainment here - this is instructional.
You should check out http://www.tapiocamobile.com. Their service is what you need.
It is one of qualcomm's products.
Just because h264 fits your technical needs you still have to be aware of the licensing.
Not all uses of h264 are free !
There is no need to push hardware developers, they already make DSP chips for mobile devices that will be able to do HW acceleration for WebM. We're just waiting for software to make this happen.
Ogg Frog is designed to rip CDs into OGG format and then support MP3 and other formats. It will be based on Zoolib which Mike Crawford is working on porting to different platforms with Andy Green.
Eventually Mike will take Ogg Frog out of alpha testing and move it to beta and then a golden 1.0 release in 2020, 2023 tops. By then standards will have changed to something else but the OGG audio and video formats will be used as they are open sourced and almost everything else is someone else's or company's IP and will start suing people who use them in their applications and sell music and videos in that format. Compuserve for example came up with GIF standards as I recall and started suing so people moved to TIF, JPG, PNG, etc. PNG I believe is safe from lawsuits but it is only an image format and not an audio or video format.
Remember, Slashdot does not have a -1 disagree moderation, and no, troll, flamebait, and overrated are not substitutes.
I'm just sayin......
Just remember the wise words of Vader, "You are part of a rebel alliance and a traitor. Take her away!"
I only had a buck every time I read, "No one is going to do [x] on a mobile device," over the past few years...
I have entire seasons of TV shows (Last Airbender) queued up on my phone for when I get trapped waiting somewhere and/or my son is bored on car trips, etc. It's not 2004 any more - the whole "mobisodes" trend came and went as it was discovered people don't *like* 2 minute custom-created content for the phones. They want normal length videos, and with today's large screens and relatively massive storage there's no problem with that.
-Russ
Me
If you're targeting windows mobile, you're screwed. WMA is your only choice. Theora...nope forget it. Been there, done that.
Which would be mpeg4 for high res vids and 3gp for low res.
Indeed -- or any of the dozens (hundreds?) of Android community websites where this question has been answered 100 times already. I'm sorry, but Ask Slashdot has gone down the tubes (or series thereof). This is a question one could Google and find the answer to in less than a minute. This is supposed to be "news for nerds", not "common questions for laymen & kdawson."
meep
That and output as H.264 which is really the only choice.
Agree. H.264 is supported, in hardware, by most of the smartphones you care about (iPhone, Nokia/Symbian and most android phones).
I've found the output from mencoder (part of mplayer) has worked across all three platforms flawlessly.
Helix Mobile producer is purpose built for this task.
http://www.any-dvd-converter.com/
/usr/bin/HandBrakeCLI -I -O -i %DIR%/%FILE% -t 1 -c 1-21 -o /mythtv/videos/Compressed/"%TITLE%"-"%SUBTITLE%".mp4 -f mp4 -w 480 -l 272 –crop 0:0:0:0 -e x264 -b 384 -2 -T -r 29 -a 1 -E faac -B 160 -R 44.1 -6 stereo -D 1 -x ref=2:me=umh:cabac=0:bframes=0 -C 8 -v
I use this for encoding my MythTV recordings for my iPhone 3GS and my wife's Droid. Works very well.
Enjoy. You're welcome. I assume you will figure out on your own how to best use this and get what you want out of it.
You'll have to read the manual, but you'll be able to write a script to encode several different versions for different devices with relative ease.
upload it to youtube, which is pretty format tolerant. iOS and Android both have youtube applications out of the box.
check http://h264.code-shop.com/trac for encodings to fix vids for Android specificly, use the provided qtfaststart >qt-faststart "$tmpfile" "$outfile"
On most devices, H.264 is not HW decoded.
For many current high-end, it is, but not most devices.
And very few devices CAN decode H264 in HW And bandwidth is more easily constrained by encoding smaller than using a more expensive computatinally algorithm.
"I agree that MPEG2 have it's uses as a less CPU intensive codec, but not in this case."
Yes, in this case too. The FA mentioned high end ones "too", not "only".
"For the bandwidths available for mobile phones (1-2Mbit range tops for most users)"
And 800Mbit at 512x384 is fine. You're using up space for the MP3 audio, too.
If you don't know something and cannot be bothered to find out, just ask a question and let someone else do the work.
I recommend Arista .
Encode your video in H.264 Baseline Profile and it will play on everything. Baseline Profile is DVD-quality, 640x480. Players with smaller screens will scale it down. The bigger HD H.264 profiles will not play on everything, because not all devices can play HD yet. Devices with smaller screens will scale the video down.
You don't get to express your individuality with a choice of codec, because video consumers only have one: H.264. If your video is not H.264, the consumer cannot see it. That is the reason H.264 exists, that is why it has that ISO/IEC name starting with an H instead of its previous name, which was Advanced Video Coding. Making a universal meeting place for video content is why we have ISO standardization of video codecs, so there is a common playback and capture codec for consumers. In the same way that you had to use MPEG-2 video on a DVD Player, you have to use MPEG-4 H.264 video on the video players has succeeded it: iPhone, iPad, Blackberry, Android, Palm, Blu-Ray, iTunes, iPod, Zune, YouTube (although they will transcode nonstandard codecs to H.264 automatically), QuickTime Player, FlashPlayer, Safari, Chrome, IE9, Mac OS, Ubuntu, various set-tops and other devices.
To stream well on 3G it will have to be very low-bandwidth. Typically, a version is encoded for Wi-Fi and a separate version for 3G.
Apple has a lot of information about video authoring and encoding for mobile devices on their developer site. Apple has forgotten more about this topic than most companies will ever know: QuickTime is the backbone of audio video authoring, MPEG-4 is a standardization of the QuickTime file format, Final Cut Pro is the most popular pro video editor, iMovie is the most popular consumer video editor, WebKit the most video-savvy browser core, and of course they run iTunes Store are the maker of the iPod. So you can follow their advice and get the job done right. Their advice will also apply to Android and other smartphones because when it comes to video they are all iPods.
http://developer.apple.com/
I find arista very good, and easy to use (for linux). Winff works great for me too, with more options. Transmageddon seems good too, as a sort of bleeding edge arista with more options. Winff runs on Windows too.
http://www.transcoder.org/
http://winff.org/
http://www.linuxrising.org/transmageddon/
There is some software written for maemo called Knots2 (cf. http://wiki.maemo.org/Knots2) that does a pretty decent job of encoding a stream starting from any type of format to something that can be watched natively on the device or with a browser.
It's what I use to access MythTV from my N900.
No idea on how hard this would be to port to Android, though.
Just make a damn video (you pick the flavor) and link people to DoubleTwist.
I agree - it does seem to be odd to have a rather specific development question for one particular platform as an Ask Slashdot. I have plenty of questions I ask, for things like Symbian/Qt and Windows/DirectX development that I do in my spare time, and I'm sure plenty of other Slashdot readers do on various areas, but I post to an appropriate development forum (e.g., Nokia forums, GameDev). If every development question about a random platform they were development got asked, the front page would quickly get bogged down with endless questions...
I'm no expert on this, but http://wurfl.sourceforge.net/ has a very extensive database on mobile device capabilities, so you might find what you need there.
ffmpeg -i myfile.mpg -target vcd /tmp/vcd.mpg
Check out the "target" options for the best solution to your needs.
If you don't find one that fits, check out mencoder.
#!/bin/sh
# This is for really simple XVID conversion, use
SCALE=",scale=400:-3"
VIDEO_BITRATE=500
XVIDENCOPTS="turbo:bitrate=$VIDEO_BITRATE:max_key_interval=250:trellis:max_bframes=1:vhq=3"
FRAMES="-ofps 15000/1001"
for filename in "$@"; do
IN=$filename
NICE_LEVEL="+15"
nice /usr/bin/mencoder "$IN" $FRAMES -oac mp3lame -lameopts preset=128 -ovc xvid \
-vf lavcdeint${SCALE} -noodml -forceidx -ffourcc XVID \
-xvidencopts ${XVIDENCOPTS} -of avi -o "${IN}-n800.avi"
done
Simple.
I simply use ffmpeg to encode videos for iPhone playback. You can certainly adjust anything as desired:
From a Windows batch file (note the file arguments), which can have a file dropped onto it:
ffmpeg -y -threads 2 -i "%CD%\%~nx1" -vcodec libx264 -r 29.97 -s 480x272 -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -crf 24 -bt 256k -refs 1 -coder 0 -me umh -me_range 16 -subq 5 -partitions +parti4x4+parti8x8+partp8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec libfaac -ab 192k -ar 48000 -ac 2 "%CD%\%~n1_iPhone.mp4"
I hope I die a horrible lingerie death too... :P