Web is full of articles about encoding videos with FFmpeg, however most of them are obsolete and use old non-working FFmpeg parameters. So here’s my guide for encoding web videos using recent FFMpeg versions for Flash and HTML5.
Step 1: Get a new build of FFmpeg
Most distribution builds are very old, buggy and have numerous issues. Don’t use them.
Ubuntu users: UbuntuForums has a great guide for compiling newest FFMpeg build. I strongly suggest you use a stable FFmpeg build (that’s 0.9 at the moment) instead of git master. Don’t forget libx264 for H.264 and libvpx for VP8/WEBM if you want that support.
Windows users: Zeranoe has great static builds of FFmpeg for Windows with libx264 and libvpx included. Use those for encoding.
OS X users: MacPorts should be able to compile and install FFmpeg with libvpx and libx264. As I don’t use any machines with OS X you’ll have to check for yourself.
Step 2: Choose resolution, bitrate and profile
Now you’ll have to decide on two things – the resolution, bitrate and profile you want those videos in.
Resolution gives “sharpness” to the overall image. If you choose a low resolution, the video will be small and it will be blurry when users will put it full-screen. Typically people use 360p (that’s a shorthand naming made popular by HD televison, meaning picture has height of 360 with width corresponding to wanted aspect ratio), 480p, 720p and 1080p resolutions, as those correspond to common screen sizes, which avoids excessive blurriness.
Contrary to popular belief, resolution does not affect file size.
Bitrate tells the encoder about how many bits should each second of video have. It directly determines file size of the video along with the quality. Set too low, it will cause the video to look very blocky (especially in fast-moving scenes) and set too high will make your files excessively large.
When choosing bitrate you need to remember, it is directly connected to resolution – storing pictures of certain resolution requires more bits, so if you want higher resolution videos, you’ll have to choose higher bitrate for them to not look like garbage.
A rule of thumb to calculate file size from bitrate is:
filesize (in MB) = (bitrate in Mbit/s * 8) * (video length in seconds)
Some general resolution/bitrate guidelines that we’ve found to work well at Viidea:
|Resolution||Bitrate||Approximate size of 10min video|
|320p (mobile)||180 kbit/s||~13 MB|
|576p (PAL)||850 kbit/s||~63MB|
|720p||1000 kbit/s||~75 MB|
The values in the table were optimized for lecture-type content recorded with SD cameras, so if you want to encode something more dynamic (like Transformers 😉 ) I suggest you bump the bitrate up a little.
Profile constrains H.264 to a subset of features – higher profiles require more CPU power to decode and are able to generate better looking videos at same bitrate. You should always choose the best profile your target devices support.
Basic support matrix for devices:
|Device||Max supported profile|
|Desktop browsers, iPhone 4S+, iPad 2+, Android 4.x+ tablets, Xbox 360, Playstation 3||High profile|
|iPhone 3GS, iPhone 4, iPad, low-end Android phones||Main profile|
|iPhone, iPhone 3G, old low-end Android devices, other embedded players||Baseline profile|
Remember, most devices also have a maximum resolution and bitrate they can handle. That is usually expressed in as a H.264 level and can be set in FFmpeg with -level parameter (this will make FFmpeg abort encoding of videos which couldn’t be played on the device).
Step 3: Choose audio format and bitrate
For audio, the choice is a lot simpler – if you want to encode for mobile devices I strongly suggest you use AAC+, which has a very noticeable improvement of audio quality at the same bitrate.With that in mind, AAC+ is perfect for podcasts, lectures and other speech content, since it retains quality even at low bitrates (difference between “normal” LC-AAC at 96 kbit/s vs. AAC+ at 64kbit/s is practically not noticeable).
You will need
libfdk_aac compiled into your version of ffmpeg to encode into AAC+ profile and pass
-profile:a aac_he_v2 as a parameter.
Otherwise, rule of thumb is to take around 128 kbit/s for standard quality material and 192kbit/s for something more complex.
Step 4: Encode!
So, you made all the hard choices and now it’s time to encode your video. FFmpeg command line to encode a standard web video looks like this:
ffmpeg -i input_file.avi -codec:v libx264 -profile:v high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -codec:a libfdk_aac -b:a 128k output_file.mp4
You can also encode the video in two-passes, which gives the added benefit of quality increase and more accurate file size for given bitrate:
ffmpeg -i input_file.avi -codec:v libx264 -profile:v high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -pass 1 -an -f mp4 /dev/null
ffmpeg -i input_file.avi -codec:v libx264 -profile:v high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -pass 2 -codec:a libfdk_aac -b:a 128k -f mp4 output_file.mp4
Scary isn’t it?
Warning: ffmpeg command line arguments are position sensitive – make sure you don’t mix up the order. Good rule of thumb to prevent mistakes is to keep the order of
ffmpeg [input options] -i [input filename] -codec:v -codec:a http://options [output file options] [output filename]
Let’s break down all those parameters:
-i [input file] | this specifies the name of input file
-codec:v libx264 | tells FFmpeg to encode video to H.264 using libx264 library
-profile:v high | sets H.264 profile to “High” as per Step 2. Other valid options are baseline, main
-preset slow | sets encoding preset for x264 – slower presets give more quality at same bitrate, but need more time to encode. “slow” is a good balance between encoding time and quality. Other valid options are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo (never use this one)
-b:v | sets video bitrate in bits/s
-maxrate and -bufsize | forces libx264 to build video in a way, that it could be streamed over 500kbit/s line considering device buffer of 1000kbits. Very useful for web – setting this to bitrate and 2x bitrate gives good results.
-vf scale | applies “scale” filter, which resizes video to desired resolution. “720:480” would resize video to 720×480, “-1” means “resize so the aspect ratio is same.” Usually you set only height of the video, so for 380p you set “scale=-1:380”, for 720p “scale=-1:720” etc.
-threads 0 | tells libx264 to choose optimal number of threads to encode, which will make sure all your processor cores in the computer are used
-codec:a libfdk_aac | tells FFmpeg to encode audio to AAC using libfdk-aac library
-b:a | sets audio bitrate in bits/s
-pass [1 2] | tells FFmpeg to process video in multiple passes and sets the current pass
-an | disables audio, audio processing has no effect on first pass so it’s best to disable it to not waste CPU
That’s basically all there is to it.
Some sample command lines:
ffmpeg -i input_file.avi -codec:v libx264 -profile: high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -codec:a libfdk_aac -b:a 128k output_file.mp4
ffmpeg -i inputfile.avi -codec:v libx264 -profile:v baseline -preset slow -b:v 250k -maxrate 250k -bufsize 500k -vf scale=-1:360 -threads 0 -codec:a libfdk_aac -b:a 96k output.mp4
ffmpeg -i inputfile.avi -codec:v libx264 -profile:v main -preset slow -b:v 400k -maxrate 400k -bufsize 800k -vf scale=-1:480 -threads 0 -codec:a libfdk_aac -b:a 128k output.mp4
ffmpeg -i inputfile.avi -codec:v libx264 -profile:v high -preset slower -b:v 1000k -vf scale=-1:576 -threads 0 -codec:a libfdk_a
10. Monitor Your Computer for Running Tasks or Unauthorized Access
If you’re at work and want to keep an eye on your home machine—whether it’s keeping track of a download or making sure someone else isn’t trying to use it—you can do that with Dropbox. All you need is a screenshot tool (like one of our favorites) and some way to automate it (like this AutoHotkey script). Then, just periodically check your Dropbox folder, and you’ll have a chronological timeline of everything happening on your screen at home. You can also use Dropbox to check your home computer’s IP from afar, and even locate your laptop if its been stolen.
9. Securely Share Files, from Saucy Pics to Paperwork
We all know Dropbox is great for sharing files, but it’s particularly good for sensitive information, like tax returns, passwords, or saucy photos (note: saucy photos not recommended). Dropbox encrypts everything you upload, and downloads it over a secure HTTPS connection, meaning that file is secure from start to finish. Of course, you can also encrypt it in a ZIP file first for extra protection, too. Just don’t be reckless!
8. Manage Your BitTorrent Downloads
Most BitTorrent clients have handy web interfaces that let you add, monitor, and remove torrents from afar, but a simple alternative is to just use Dropbox. Just tell your BitTorrent client to watch a specific folder in your Dropbox for new torrents. Then, when you’re away and find a cool torrent you want, just copy that torrent to your designated Dropbox folder. It’ll sync back to your house, get recognized by your client, and start downloading for you.
7. Quickly Install Android Apps and ROMs
The Google Play store is great, but sometimes you find an app that you need to install yourself using an APK file. Or, maybe you’re flashing a new ROM to your phone and trying something completely different. Either way, you don’t need to plug your phone in via USB—you can just drag that APK or ZIP file to your Dropbox, then download it using the Dropbox app on your phone (or install it right then and there). In the case of smaller files, it’s much faster than finding your USB cable.
6. Print Documents to Your Home Printer from Any Computer
If you have a document you want printed back at home, Dropbox can make it happen. All you need is a script running at home that monitors a Dropbox folder for incoming documents and prints them. Then, you can add a document to that folder from any remote computer or smartphone, and a hard copy will be waiting for you when you get back. You can check out the cross-platform script here, though we’ve also written a simpler Mac-specific tutorial here as well.
5. Host a Web Site or Start Page for Your Browser
So you’ve built your first web site, and now you’re looking for somewhere to host it. You can actually host it for free right in your Dropbox—either manually or with a service like DropPages. This trick is also handy for syncing your custom start page across your systems, so you have it everywhere you go—whether it’s one you created yourself or one of the many we’ve featured here before.
4. Create Your Own Cloud-Based Music Library
Not satisfied with the other cloud music services out there? You can use Dropbox to sync your entire music library between computers and up to the cloud, so it’s the same everywhere. Then you can play that music when you’re away from home using a web player like DropTunes or a smartphone app like BoxyTunes. Note that this one requires a significant amount of space, so if you only have a few gigs, make sure you check out our cheapskate’s guide to free Dropbox storage.
3. Launch Applications and Run Commands on Your Home Computer
Similar to the remote printing method, you can also run applications and commands on your home computer with a clever setup in Dropbox. We’ve shown you how to do it with Windows and AutoHotkey, but Dropbox also has a tutorial for Linux users, which is pretty handy. It’s perfect for starting up your favorite remote desktop program so you can get full control of your computer from afar.
2. Convert, Share, and Automate Your Files
One of the coolest ways to take advantage of Dropbox is to use a tool like Dropbox Automator or Wappwolf to automate the files inside. With those apps, you can convert an image just by dropping it in a Dropbox folder, or send a PDF to your Kindle. Heck, you can even tell it to upload all your synced photos to Facebook or Flickr. Check out our full tutorial on Wappwolf for more information.
1. Keep the Same Apps, Settings, and Passwords on All Your PCs
If you have multiple computers, Dropbox is a great way to keep important files available at all times. But, it’s also great for keeping all your favorite apps readily available, and with the same settings across each PC. Portable Apps are the best way to do this, since they keep all their settings in one neat little folder, and you can sync them between all your computers. But, you can also sync your settings separately, whether it’s a custom Microsoft Word dictionary, Your Firefox and Pidgin profiles, multiple Rainlendar calendars, or anything else. You can even use Dropbox as the ultimate password syncer, keeping your passwords safe, secure, and available wherever you are.
The First Version of Microsoft Windows, Windows 1.0, with simple applications and the concept of multitasking on PC
1987 Windows 2.0
The Second Version of Windows, Windows 2.0 with some fixes and the Control Panel.
1988 Windows 2.1
The Second Version of Windows with some additions, and some fixes, Windows 2.1, the Paint software is seen in this one!
1990 Windows 3.0
The Third Version of Windows, Windows 3.0, featuring the File Manager and Program Manager, replacing the old MS DOS based File and Program Managers.
1992 Windows 3.1
The later released upgraded version of Windows 3.0, which had support for 32-bit Disk Access, Personalization options and had the Minesweeper game for the first time.
1995 Windows 95
Windows 95, the changed look, the new interface and the beginning of the form of Windows which we see now. Enhanced Graphics and better Communication Programs.
1998 Windows 98
Windows 98, one of the most successful versions of Windows till now, this version of Windows can still be seen in some PCs even today. With Extended Softwares, better Performance, this Version was the first milestone in the path of the development of Windows.
2000 Windows ME
Windows ME or Windows Millenium Edition, though not a very popular version of Windows, but still it had some better tools and performance than the previous ones in some cases.
2001 Windows XP
Windows XP, the Daddy of all versions of Windows, the most popular version of windows even today. Windows XP is still used today because of its unmatched performance, tools and interface. This has been the best version of Windows till the arrival of Windows 7.
2006 Windows Vista
Windows Vista, though it didnâ€™t go so well in the public, but still its a good version of Windows specially for the interface the Windows Aeroâ„¢ Effect, making the Window Transparency work like magic.
2009 Windows 7
Windows 7, the best version of Windows till date. With the new and advanced features such as the Superbar, this version of Windows created another milestone for Microsoft after Windows 98 and Windows XP. Windows 7 features an unbeatable user interface, and powerful tools that makes it the best among the rest.
2012 Windows 8
Windows 8, to be released in the late 2012. The interface of Windows 8 as seen at the D9 Conference. A better version of Windows as proposed by Microsoft, with the changed User Interface.