Transcoding H.264 files to Google's WebM format (VP8/Vorbis) in FFMPEG 0.6 or better using Linux for your own collection and HTML 5

Introduction


Note: I want to stress that I DO NOT CONDONE using this guide to encode movies that are infringing upon international and local copyright laws (which include the WIPO Treaty in Europe and the DMCA in the U.S). These examples ASSUME your encoding material in which you OWN The RIGHTS too! I will not be held responsible for individuals that are using it to encode copyrighted material in those respective countries! If there are disputes about this or any other questions please DO NOT hesitate to contact me right away! Thank you.


This week I am going to focus on showing you how to transcode videos to WebM, which is playable in both VLC and most HTML 5 compatible web browsers including Firefox, Chrome, Opera, and I.E 10! If you recall way back several months ago (if you had been following my old blog) I showed you some code snippets for how to encode directly to WebM using an older version of libvpx 0.6.1 code named "Bali", that came out last year, but has since been updated and improved, in an effort to make the WebM encoder much faster. Today, I am going to show you an alternate way to encode all of your videos using FFMPEG command-line using some code "snippets", that I put together myself, while experimenting with the command-line and encoding some family video files myself, using IMO the "best" quality optimizations when encoding with the WebM encoder from the command-line. There is one thing to take note of, that you should pay attention to, as I proceed forward and show you how to encode with the command-line. Now we can begin.

Note: This guide ALREADY assumes you have the new version of libvpx installed from your repositories or built from the source of, whatever Linux distro you are using i.e Ubuntu/Fedora or some other variant! If you do not have libvpx, you can download it from Google code repository on the WebM project site and then install or build it on your machine. This tutorial will not show you how to do that! the guide also assumes you know how to WORK your way around the command-line and how to tweak command-line arguments by hand. If you aren't comfortable with this or you want a GUI that can do it for you much faster with less work, but with less control over the video encoding process do a search for "Miro Video Converter" for Windows/Mac OS/X or if you are running Linux search for "Transmaggedon". There are countless other front-end GUI's on Linux, that you can also use to your advantage to speed up the encoding process using a quick web search.

Please also note as well that, the examples below assume your encoding with a dual-core processor or better, henceforth the need to let the encode choose the appropriate multi-threads. Even with a fair amount of CPU cycles with multi-core processors, the encoder can put a "strain" on your CPU and at BEST you might only be able to encode at about 10 fps for a one hour H.264 video file! Because all CPU's are different, this is the main reason I will NOT being using "best" quality preset in VP8. If you have more cores you can ultimately change this, but make sure you have at least eight cores, if you want the "best" of quality that the VP8 encoder has to offer! Do NOT say I didn't warn you though, if you decide to go this route, it will only "double" the encoding time!



Common Usage: Encoding a group of H.264 video files filmed in standard definition using an AVCHD camcorder



Example one: Transcoding a group of files in SD 480i with a 4:3 aspect ratio from H.264 using single pass "good" quality video encoding in WebM with a stereo audio track

$ffmpeg -y -i /home/USER/Videos/*.mp4 -threads 0 -f webm -s sd480 -aspect 4:3 -vcodec libvpx -deinterlace -vb 5000k -crf 50 -level 200 -acodec libvorbis -aq 5 /home/USER/Videos/*.webm

Common Usage: Encoding a group of H.264 video files filmed in high definition using an AVCHD camcorder



Example two: Transcoding a group of files filmed in HD 720p with a 16:9 aspect ratio from H.264 using single pass "good" quality video encoding in WebM with a 5.1 audio track

$ffmpeg -y -i /home/USER/Videos/*.m2ts -threads 0 -f webm -s hd720 -aspect 16:9 -vcodec libvpx -vb 10000k -crf 25 -level 200 -acodec libvorbis -aq 2 /home/USER/Videos/*.webm

Common Usage: Encoding a group of H.264 video files filmed in high definition using an AVCHD camcorder



Example three: Transcoding a group of files filmed in HD 1080p with a 16:9 aspect ratio from H.264 using single pass "good" quality video encoding in WebM with a 5.1 audio track

$ffmpeg -y -i /home/USER/Videos/*.mp4 -threads 0 -f webm -s hd1080 -aspect 16:9 -vcodec libvpx -vb 10000k -crf 25 -level 200 -acodec libvorbis -aq 2 /home/USER/Videos/*.webm

Common Usage: Encoding a group of H.264 video files filmed in high definition using a high definition webcam



Example four: Transcoding a group of files filmed in HD 720p with a 4:3 aspect ratio from H.264 using two pass "realtime" quality video encoding in WebM with a stereo audio track

$ffmpeg -y -i /home/USER/Videos/*.mp4 -threads 0 -f webm -s hd720 -aspect 4:3 -vcodec libvpx -pass 2 -vb 5000k -crf 50 -level 200 -acodec libvorbis -aq 5 /home/USER/Videos/*.webm


That's all there is to it! Feel free to take the examples and tweak them to your liking, encoding different types of video by tweaking the examples above, for different types of input! once you have the command-line flow and syntax down you can then start to get a feel for what works via command-line encoding and what doesn't. If you need to see what VP8 presets map to FFMPEG using the command-line use the reference below! I am only going to be posting two to three entries a week at this point. My next entry will be a couple of days again! If you have any questions or comments let me know. Thanks for reading and have a nice week!


Reference:



1. Google Docs. "ivfenc <> ffmpeg" https://docs.google.com/spreadsheet/ccc?key=0AvWxUS1XGCPAdGNtNW10a2p4c1VwdG1VZk1uMl9MUEE&hl=en#gid=0 accessed 25 Nov 2012. 2012

Comments

Popular posts from this blog

Encoding Opus files in Linux with opusenc for your own collection and HTML 5

Encoding Vorbis files in Linux using oggenc for your own music collection and HTML 5