Posts tagged with ‘Video’ Category

Panda: Scalable, Open Source Video Transcoding

We recently had to transcode a large number of videos for the iPhone. Rather than try to scale out our in-house infrastructure, we thought it would be prudent to check out different projects people had been working on. One stellar example is Panda (whom our friend Ezra Zygmuntowicz at Engine Yard mentioned to us). Panda leverages Amazon’s S3, EC2, and Simple DB web services to offer a very flexible, cost effective, and scalable option for integrating video transcoding into any site. We’re likely going to do build something a bit more tailored for howcast.com, but will definitely try to see if there are things that we can contribute back to that project. We humbly tip our hats to the New Bamboo team for their fantastic work.

Podcast Transcoding Re-revisited

OK so we have admittedly just about worn out this topic, however, we do have some recipe improvements to share with you. We ran into some issues with our previous recipe for some videos on the iPhone. Here is our latest incantation which seems to work quite well:

ffmpeg -y -i [input file] -v 1 -threads auto -vcodec libx264 -b 300k -r 15 -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 480x320 -acodec libfaac -profile aac_low -ab 64k -ar 22050 -ac 2 -f mp4 [output file]

Note that you may need to adjust the resolution as appropriate. With respect to what changed, you will notice is that we lowered both the video and audio bit rate, are explicitly using the AAC low complexity audio profile (per Apple’s specs), and have also switched back to using stereo (vs. mono) for the audio output. You will need to ensure that you have a fairly recent version of FFmpeg installed with H.264 and AAC. We hope that you find this helpful and as always feel free to ping us with any questions.

Podcast Transcoding Re-visited

A post or so ago we talked about podcast transcoding. Since then we’ve updated things a bit to support 640×480 video. The first thing that we did was update the FFmpeg recipe we use for transcoding:

ffmpeg -y -i [input file] -v 1 -threads auto -vcodec libx264 -b 500k -bt 175k -refs 1 -loop 1 -deblockalpha 0 -deblockbeta 0 -parti4x4 1 -partp8x8 1 -me full -subq 6 -me_range 21 -chroma 1 -slice 2 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp 1 -s 640x480 -acodec libfaac -ab 96 -ar 48000 -ac 1 -f mp4 [output file]

This recipe was based on this Ubuntu community documentation. Note that we’re doing 1 pass versus 2 pass encoding and are using a single audio channel (still having interimittent audio issues if we use two).

The next challenge was setting the atom in the video such that the videos would sync properly from iTunes to video iPods and iPhones. As pointed out in Robert Swain’s post and also in an Apple forum thread, the development version of AtomicParsley has a feature to do this. We had to make some minor code tweaks to get things to compile properly (the changes were slightly different on OS X and Linux), but feel free to ping us if you get stuck. Once you have AtomicParsley compiled, here’s the command to run to set the atom:

AtomicParsley [output file] --DeepScan --iPod-uuid 1200 --overWrite

After that you should be set! Thanks to all of the contributors to these fantastic open source projects and let us know if you have any questions.

Podcast Transcoding with FFmpeg and AtomicParsley

There are a plethora of ways to transcode your videos into a podcast-compatible format. We wanted to give you a quick walkthrough of how we use FFmpeg and AtomicParsley to do it.

First things first — check out Apple’s technical specifications to understand more about the podcast feed format and iPod-compatible video specifications. This post is going to focus on creating 320×240 videos in M4V format (which is really MPEG-4 video format) with a single audio channel. Why not 640×480? There’s some additional work that you have to do to update the M4V metadata so that the video will sync properly to video iPods and we’re still experimenting with it. Why a single channel of audio? Technically we should be able to do things in stereo (two channels of audio), but we ran into issues in production with the audio cutting out midway through some of our videos, and using a single channel of audio seemed to resolve the problem. You may not run into this issue so we’ll point out where to tweak the transcoding recipe so that you can use one or two channels.

The rest of this post assumes that you have the following software installed:

  • FFmpeg - Open source video transcoding tool
  • AtomicParsley - Open source tool for manipulating metadata in MPEG-4 videos

If you have a Mac and use MacPorts, here’s the easy/lazy way to do it:

  • sudo port install ffmpeg +lame +libogg +vorbis +faac +faad +xvid +libx264 +a52
  • sudo port install AtomicParsley

If you prefer to download and compile the packages, there are a number of useful resources to help guide you based on the operating system you are using — so we’re going to skip diving into additional detail there.

Step 1 - Transcode the video

We basically follow the recipe in Robert Swain’s post:

ffmpeg -i [input file] -f mp4 -acodec libfaac -ab 128k -ac 1 -vcodec libx264 -b 768k -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me umh -subq 5 -trellis 1 -refs 5 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -maxrate 768k -bufsize 2M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 13 -s 320x240 -y [output file].m4v

A couple notes here:

  • If you use a Mac and are on Tiger vs. Leopard, you’ll need to use x264 versus libx264 for the -vcodec value
  • Change -ac 1 to -ac 2 if you want to try with 2 audio channels

Step 2 - Embed an image in the video’s metadata

Want a specific image to appear when your podcast videos display in coverflow?

Howcast podcasts in iTunes coverflow

Here’s where AtomicParsley works its magic.

AtomicParsley [output file].m4v --artwork [image] --overWrite

Note that per the Apple specs, you should use a 600×600 jpg or png image.

That’s all there is to it. Double-click on your M4V file and it should play in iTunes. Sync to your iPod and enjoy your video!

Tools for Adding Keyframe Metadata to Flash Video (FLVs)

If you’re working with video on the web, you’re most likely transcoding to Flash Video format. Whether you use FFmpeg, On2, or another transcoding package, if you are FLV streaming via lighttpd or nginx, you’ll need to add keyframe metadata to the FLV in order to allow your player to seek to different points in the video that have yet to be downloaded.

Being that our site is built with Ruby on Rails, it was natural for us to leverage flvtool2 (which is written in Ruby) to add this metadata. Lately, we’ve been having intermittent failures with flvtool2 that appear to be related to choppy audio.

Although the ideal way to deal with this issue is for us to fix the problem in flvtool2, given some of the other things that we’re working on we may not be able to look at this near term. One alternative that we’re starting to experiment with is using flvtool++.

We’re in the process of setting this up in a linux environment, but for people interested in trying it out on OS X (we’re using Leopard), here are some instructions on how to install for folks that use MacPorts:

1. Grab the latest http://mirror.facebook.com/facebook/flvtool++/ (thanks Facebook!)

2. sudo port install scons

3. sudo port install boost

4. tar xzvf flvtool++-1.1.tar.gz

5. cd [flvtool++ directory]

6. Add a build path to SConscript:

5. Manually create byteswap.h:

6. scons

7. And voila!

./flvtool++

flvtool++ 1.0
Copyright (c) 2007 Dan Weatherford and Facebook, inc.
http://developers.facebook.com/opensource.php
Published under the BSD license.

usage: flvtool++ [-nodump] [-nomerge] [-tag name value] [input filename] [output filename]
-nodump: do not dump the metadata when done (kinda quiet)
-nomerge: do not keep existing metadata from the input file
-strip: remove all metadata (do not write it to the output file)
-tag name value: Set a metadata tag named 'name' to the (string) value 'value'
Note that manually set tags will override automatically generated tags.

8. To add keyframe metadata to an FLV simply run a command like:

./flvtool++ in.flv out.flv

We hope this is helpful. We’ll keep you posted on how things go as we’re just beginning to experiment on linux.