Duet by Kenton and Duane

Kenton and Duane were nice enough to perform a duet for us!

I had some trouble rotating the video without cropping - I used a solution I found: Correct Smartphone Orientation. Though, I used avconv not ffmpeg.

Then, I found that with the original version, the audio didn't work on an iPhone 5. Why not? Well, it appears that iOS supports a very few options when it comes to audio/video codecs.

According to ios-video-encoding (see also how-to-play-mp4-on-ipad):

> - H.264 video codec up to 1080p, 30 frames per second FPS, High Profile level 4.1 with AAC-LC audio codec up to 160 Kbps, 48kHz, stereo audio with .m4v, .mp4, and .mov video container;
> - MPEG4 video codec up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio codec up to 160 Kbps per channel, 48kHz, stereo audio with .m4v, .mp4, and .mov video container;
> - Motion JPEG (M-JPEG) up to 35 Mbps, 1280 by 720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio with .avi as video container.

For the video I posted, VLC says I'm using "MPEG Audio layer 1/2/3 (mpga) 44100 Hz, 256 kb/s"

Oh, so no problem, right? I just re-encode the video with the appropriate codec. Well, not so fast. According to Encoding AAC on the libav site:

> Libav provides an experimental native encoder for aac and wraps higher quality third party libraries.
> ...
> The native encoder is experimental and known to have serious flaws, help on improving it is welcome. Do not use it in production.

According to the FFMPEG page about AAC, those 3d-party codecs aren't free:

> The licenses of libaacplus, libfaac, and libfdk_aac are not compatible with the GPL, so the GPL does not permit distribution of binaries containing code licensed under these licenses when GPL-licensed code is also included. Therefore these encoders have been designated as "non-free", and you cannot download a pre-built ffmpeg that supports them.

Back over to Libav, I can apparently use the AAC codec - it's just that the binary program containing the codec cannot be distributed:

> fdk-aac custom license is non-free, Libav compiled with it results being not redistributable.

Sigh...well...it looks like the Fraunhofer codec is the best choice:

> The VisualOn AAC encoder is rather spartan, supports up to 2 channels and the only setting supported is bitrate. It is suggested mainly because it is free-software compatible and redistributable. To achieve best results use the Fraunhofer one.

Hmm...well, I suppose I'll build ffmpeg myself and include the non-free stuff (installing the binary to my home directory). So, following FFMPEG Install Guide, I installed the necessary packages and codecs.

Then, to configure:

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libx264 \
  --enable-nonfree \

And the usual make, make install stuff...

Now, to give it a try:

njgraham@mercury /tmp/codec $ ~/bin/ffmpeg -i kenton_duane_duet.mp4 -c:a libfdk_aac -c:v h264 -preset medium -crf 25 kenton_duane_duet_for_apple_babies.mp4

That seems to have worked! VLC now says The video codec is H264 - MPEG-4 AVC and the audio codec is MPEG AAC!

Also, it's a _lot_ smaller.

njgraham@mercury /tmp/codec $ ls -lh
total 25M
-rw-r--r-- 1 njgraham njgraham 1.9M Dec 30 14:21 kenton_duane_duet_for_apple_babies.mp4
-rw-r--r-- 1 njgraham njgraham  23M Dec 28 15:15 kenton_duane_duet.mp4


Comments powered by Disqus