Created

Jul 21, 2012

CQ5 DAM H.264 video output on Mac OS X Lion

Posted by Rob In der Maur

In a follow-up on Sneh Arora's article on integrating ffmpeg with CQ DAM for RedHat, this article describes how to configure an out of the box CQ5.5 installation with Digital Asset Management (DAM) to transcode source video to H.264 high quality video on Mac OS X, that can be displayed in Safari browsers and on iPhone/iPad/Apple TV devices.

For video transcoding, the CQ5.5 Digital Asset Manager (further referred to as DAM) relies on ffmpeg. In theory it means that you can upload any video format into the DAM, and ffmpeg, under the covers, will transcode the video in the formats you have specified in your DAM configuration. ffmpeg is almost like a Swiss army knife for video transcoding, it can do almost any transcoding you can think of but you need to tell it how to do this and, unfortunately, that is not that straightforward. Furthermore, ffmpeg is not by default available on all platforms you will run CQ5.5 DAM on (which is true for a Mac OS X Lion environment). So our first step will be to get hold of a ffmpeg for Mac OS X Lion. After we got hold of an ffmpeg version for Mac OS X we need to tweak the High Quality H.264 video profile for DAM.

The remainder of this article describes both a simple way and a complex way that will get you to our ultimate goal as described in the intro: transcoding videos to high quality H.264 output on Mac OS X that can be played in Safari browser as well as on iPad/iPhone/Apple TV devices.

The simple way

The easiest way to get hold of ffmpeg for Mac OS X Lion is to download the Snow Leopard & Lion & Mountain Lion 64-bit version from http://ffmpegmac.net. This version of ffmpeg is set up to handle most out of the box confgurations and you don't need to go through the hassles to configure and build a version on the platform yourself. Once you've downloaded and extracted the zip file, move the ffmpeg binary to a location on your Mac OS X Lion environment that is in your path (e.g. /usr/local/bin). If you've done this, then you should be able to type ffmpeg in Terminal from any location and see output similar to this:

ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Jun  9 2012 15:43:10 with llvm_gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
  configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --arch=x86_64 --enable-runtime-cpudetect
  libavutil      51. 54.100 / 51. 54.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.100 / 54.  6.100
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

A default CQ5.5 installation does have three video profiles installed. These video profiles can be accessed from the main window by selecting Tools, and then in the Tools window, selecting DAM > Video Profiles (or directy through http://localhost:4502/miscadmin#/etc/dam/video). Each of the video profiles do have their configuraton of how to invoke ffmpeg and this can be inspected as well as modified by opening any of the profiles and clicking the Edit button. For the sake of argument here, we will first see how our default CQ5.5 environment will transcode video to high quality H.264 format out of the box. Open the High Quality H.264 video profile and click the Upload Test Video button at the top of the window and select an MP4 video available on your local disk. Do not select a big file as transcoding takes it time, and a small file is sufficient to do the testing.

After you have selected the video, CQ5.5 will try to transcode but most likely it will fail, which you can see at the bottom of the window, where Test Result will display false for Success. You can see what went wrong when clicking the arrow at the FFMpeg Output control at the bottom of the screen. Most likely, your output will end with something like:

Please use -b:a or -b:v, -b is ambiguous
Unrecognized option 'directpred'
Failed to set value '3' for option 'directpred'

To fix this, we need to edit the ffmpeg configuration for high quality H.264, so click on the Edit button at the top of the window and this will open the Video Profile Settings dialog.

Based on my experiences, the following modifications to the configuration will get things working.

  • On the Audio tab, replace libfaac with copy as the name of the Codec. libfaac is no longer included with FFMpeg for licensing reasons, so even if you fix the original -directpred 3 error (see later) you will get a warning on libfaac not being available.
  • In the Advanced tab, remove -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip and -directpred 3 from the Custom ffmpeg arguments text field. Ensure you don't leave additional spaces in the Custom ffpmeg arguments when removing these arguments, because otherwise ffmpeg might throw an error like [NULL @ 0x7fcd2902ec00] Unable to find a suitable output format for '' followed by Invalid argument.

Test your video once more; based on the size of it, transcoding can take a while but eventually you will see true behind Success underneath Test Result at the bottom of the window (as well as your movie with an m4v extension).

The complex alternative

The simple installation of ffmpeg, as outlined above, doesn't cater for more exotic transcoding; it works for common conversions from mp4 format to mv4 format for example, but fails when trying to convert from Windows Media format to high quality H.264 (from wmv to m4v).

In order for ffmpeg to handle more versatile transcodings, one has to buid the tool from scratch on a platform, and there is no exception for Mac OS X Lion. In order to build ffmpeg on Mac OS X Lion, follow these steps:

1. Download and install the latest version of XCode

You can download the latest version of XCode from the Mac App Store; it is a big download and install, so take your time. To verify proper development environment for the remainin steps (and after you have downloaded and installed XCode), open a Terminal window and type:

gcc -version

which should give output like

i686-apple-darwin11-llvm-gcc-4.2: no input files

2. Install LAME

Download latest LAME (Lame Aint an MP3 Encoder), a high quality MPEG Audio Layer III (MP3) encoder) sources from http://sourceforge.net/projects/lame/files/ and unpack, configure, build and install using the following steps:

tar zxvf lame-3-99-5.tar.gz
cd lame-3-99-5
./configure
make
sudo make install

3. Install FAAC

Download latest FAAC (Freeware Advanced Audio Coder, an implementation of the AAC audio compression format) from http://sourceforge.net/projects/faac/files/ and unpack, configure, build and install using the following steps:

tar zxvf faac-1.28.tar.gz
cd faac-1.28
./configure
make
sudo make install

3. Install SDL

Download latest SDL (Simple DirectMedia Layer) sources from http://www.libsdl.org/download-1.2.php and configure, build and install using the following steps:

cd SDL-1.2.15
./autogen.sh
./configure
make
sudo make install

4. Install x264

Download latest x264 snapshot from http://download.videolan.org/pub/videolan/x264/snapshots/ and configure, build and install using the following steps:

cd x264
./configure --enable-static --disable-assembler
make
sudo make install

If you don't specify --disable-assembler, you need to download, unpack, configure, build and install both NASM (http://www.nasm.us/pub/nasm/releasebuilds/) and YASM (http://www.tortall.net/projects/yasm/releases/) assemblers before configuring, building and installing x264.

5. Build ffmpeg

Now you got all the required libraries in place (check /usr/local/lib) you can finally build ffmpeg. Get the latest source snapshot from the FFmpeg project, and then unpack, configure, build and install ffmpeg using the following steps:

tar zxvf ffmpeg-snapshot-tar.bz2
cd ffmpeg
./configure --enable-libmp3lame --enable-libfaac --enable-gpl --enable-libx264 --enable-static --enable-nonfree --enable-shared --disable-mmx --arch=x86_64 --cpu=core2
make
sudo make install

This will install ffmpeg in /usr/local/bin and all the libraries it requires in /usr/local/lib. 

You still need to tweak your High Quality H.264 video profile Custom ffmpeg arguments value as outlined in the first section of this article, but you should not redefine the audio codec from libfaac to copy, as we have included faac (libfaac) in our own build of ffmpeg.

If you require even more transcodings then follow similar steps as shown in step 1, 2, 3 or 4, rebuild ffmpeg by running the configure command with the additional parameter to include your codec, and then rebuild your version of ffmpeg.