Saturday, February 27, 2010

Quicktime Error 2041 an invalid sample description was found in the movie

After converting an MPEG-TS file to mp4, I had trouble with some players. Particularly, the latest Quicktime (7.6.5) wouldn't play it, saying "Error -2041: an invalid sample description was found in the movie".

Searching Google on this error turned up thousands of results, but nothing I read was directly useful. The main "solution" proposed was "rename the .mp4 file to .3gp". That seems to work in some cases for .3gp phone files which the phone happens to name .mp4.

The only solution which worked for me was to use mp4creator with the " -aac-profile=4" option.

In case anybody wants to know all the details, they are below. If you happen to know the real source of the problem and/or a version of MP4Box or ffmpeg which fixes the problem, please leave a comment.

The source file was an MPEG-TS containing h264 video and aac audio. ffmpeg reported this:

$ ffmpeg -i INPUT_FILE.mpg
FFmpeg version 0.5-svn17737+3:0.svn20090303-1ubuntu6, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-gpl --enable-postproc --enable-swscale --enable-x11grab
 --extra-version=svn17737+3:0.svn20090303-1ubuntu6 --prefix=/usr --enable-avfilter
 --enable-avfilter-lavf --enable-libgsm --enable-libschroedinger --enable-libspeex
 --enable-libtheora --enable-libvorbis --enable-pthreads --disable-stripping --disable-vhook
 --enable-libdc1394 --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-armvfp
 --disable-neon --disable-altivec --disable-vis --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 0 / 52.20. 0
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Apr 10 2009 23:18:41, gcc: 4.3.3

Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 25.00 (25/1)
Input #0, mpegts, from 'INPUT_FILE.mpg':
  Duration: 00:00:36.05, start: 2.050022, bitrate: 9188 kb/s
  Program 1
    Stream #0.0[0x810]: Video: h264, yuv420p, 1280x688 [PAR 1:1 DAR 80:43], 25 tbr, 90k tbn, 50 tbc
    Stream #0.1[0x814](eng): Audio: aac, 48000 Hz, stereo, s16, 184 kb/s

The simple thing I did first and which gave a bad file was

$ ffmpeg -i INPUT_FILE.mpg -vcodec copy -acodec copy -f mp4 ffmpeg.mp4

 Looking at that file with various tools gives this:

$ mp4info ffmpeg.mp4
mp4info version 1.6
ffmpeg.mp4:
Track   Type    Info
1       video   H264 High@4.1, 36.000 secs, 7889 kbps, 1280x688 @ 25.000000 fps
2       audio   MPEG-4 Unknown Profile(0), 36.032 secs, 0 kbps, 48000 Hz
 Tool: Lavf52.31.0

$ MP4Box -info ffmpeg.mp4
* Movie Info *
        Timescale 1000 - Duration 00:00:36.032
        Fragmented File no - 2 track(s)
        File Brand isom - version 512
        Created: GMT Fri Jan  2 00:00:00 1970

File has no MPEG4 IOD/OD

iTunes Info:
        Encoder Software: Lavf52.31.0

Track # 1 Info - TrackID 1 - TimeScale 50 - Duration 00:00:36.000
Media Info: Language "Undetermined" - Type "vide:avc1" - 900 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 1280 x 688 - Profile High @ Level 4.1
NAL Unit length bits: 32
Pixel Aspect Ratio 1:1 - Indicated track size 1280 x 688
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 48000 - Duration 00:00:36.032
Media Info: Language "English" - Type "soun:mp4a" - 1689 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
Segmentation fault

Next, I tried to extract them separately:

ffmpeg -i INPUT_FILE.mpg -an -vcodec copy -f h264 video.h264
ffmpeg -i INPUT_FILE.mpg -vn -acodec copy -f aac audio.aac

and re-mux them using MP4Box (version 0.4.4):

$ MP4Box -add video.h264#video -add audio.aac#audio mp4box.mp4

That didn't work any better, even though mp4box didn't report a segmentation fault anymore:

$ MP4Box -info mp4box.mp4
* Movie Info *
 ?       Timescale 600 - Duration 00:00:36.031
        Fragmented File no - 2 track(s)
        File Brand isom - version 1
        Created: GMT Sat Feb 27 15:33:40 2010

File has root IOD
Scene PL 0xff - Graphics PL 0xff - OD PL 0xff
Visual PL: AVC/H264 Profile (0x15)
Audio PL: AAC Profile @ Level 2 (0x29)
No streams included in root OD

Track # 1 Info - TrackID 1 - TimeScale 25000 - Duration 00:00:36.000
Media Info: Language "Undetermined" - Type "vide:avc1" - 900 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 1280 x 688 - Profile High @ Level 4.1
NAL Unit length bits: 32
Pixel Aspect Ratio 1:1 - Indicated track size 1280 x 688
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 48000 - Duration 00:00:36.032
Media Info: Language "Undetermined" - Type "soun:mp4a" - 1689 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x67
MPEG-2 Audio AAC LC - 2 Channel(s) - SampleRate 48000
Synchronized on stream 1

and mp4info also seemed to like the file better:

$ mp4info mp4box.mp4
mp4info version 1.6
mp4box.mp4:
Track   Type    Info
1       video   H264 High@4.1, 36.000 secs, 7717 kbps, 1280x688 @ 25.000000 fps
2       audio   MPEG-2 AAC LC, 36.032 secs, 150 kbps, 48000 Hz

Note that re-wrapping this into a Quicktime .mov file ($ ffmpeg -i mp4box.mp4 -acodec copy -vcodec copy -f mov mp4box.mov) worked and gave a file Quicktime played without trouble.

But to get a working .mp4, I had to use yet another tool for the audio: mp4creator. With the -aac-profile=4 option:

$ mp4creator -aac-profile=4 audio.aac mp4creator-audio.mp4
Warning - you have changed the AAC profile level. ? This is not recommended
If you have problems with the resultant file, it is your own fault
Do not contact project creators

Despite the warning, this worked after re-muxing with mp4box:

$ MP4Box -add video.h264#video -add mp4creator-audio.mp4#audio mp4box.mp4
$ mp4info mp4box-2.mp4
mp4info version 1.6
mp4box-2.mp4:
Track ???  Type    Info
1       video   H264 High@4.1, 36.000 secs, 7717 kbps, 1280x688 @ 25.000000 fps
2       audio   MPEG-4 AAC LC, 36.032 secs, 150 kbps, 48000 Hz

Examining the difference, it seems that both ffmpeg and MP4Box were making an MPEG-2 AAC track, and Quicktime wanted an MPEG-4 track instead.

Wednesday, February 10, 2010

PDF to Word conversion notes

Had a complex PDF to convert to something editable like .doc, so I had another look at what was available.

This comparative test from 2008 was very helpful, as were some readers' comments. It concluded by recommending the koolwire.com service, which was indeed quite good, and also very convenient because it can be used through email. It produced an RTF with mostly actual tables. Visually, however, the tables in this particular case would have needed quite some re-formatting to look like the original ones.

Several readers suggested the PDF-to-Word service at pdftoword.com. For me, this gave me the best looking results. It converted the complex tables into columnized sections instead, but that was fine. (As an aside, it is not very clear which engine this service is using. It is related to Nitro PDF, a commercial Windows application which is promoted from the pdtftoword.com page. Also, the Nitro PDF pages link to the free pdftoword.com service as their free version. However, the produced Word document mentions Solid Converter PDF, another commercial Windows application, in it's properties. Weird...)

I also tried the convertpdftoword.net service which others suggested. It also gave a good looking Word document, but built it with tons of independent text boxes which was quite unconvenient in my case. A closer look, showed that this service was actually using VeryPDF's PDF2Word, which produced an RTF file (but with a .doc extension). PDF2Word turns out to actually be a re-packaging of xpdf, and is free (GPL) software. The source is available, but VeryPDF sells the Windows executable.

The funny thing from theses tests: the only completely useless conversions happened to be the one from Adobe itself.

Conclusion: I had the best results with pdftoword.com. But it all depends on your source document and what you want to do with it.

Labels: , , , , , ,

Friday, January 01, 2010

Open mbox file in Thunderbird

Unfortunately, there seems to be no straightforward way to ask Thunderbird to open or import an Mbox mail file directly.

Say you have an mbox file, and would like to view it in Thunderbird. For this example, we will view the file in a "temp-mbox" folder under Thunderbird's "Local Folders". The convoluted way which seems to work goes like this:

  • In Thunderbird, under Local Folders, create the new "temp-mbox" folder.
  • Exit Thunderbird.
  • Find your "Local Folders" directory in your profile. It may be something like "~/.thunderbird/random-string.default/Mail/Local Folders/". In there, you will find a temp-mbox and a temp-mbox.msf file.
  • Overwrite temp-mbox with your mbox file,
  • and delete the temp-mbox.msf index file.
  • Re-open Thunderbird
I needed to do this, because of another limitation of Thunderbird: it's poor search capabilities. Since the mails I wanted to group are on my own IMAP server, I did the search there, and put all the mails into a single file. What I wanted is all the last year's emails received from or sent to somedomain. The following got me a suitable mbox file:
mbox=somedomain-2009.mbox; search=@somedomain; \
find ~/Maildir/cur ~/Maildir/.Sent/cur -mtime -365 | \
while read f ; do \
if egrep "^(From|To|Cc):.*$search" "$f"; then \
  echo "From - " >>$mbox; \
  cat "$f" >>$mbox; \
fi; \
done
To achieve this using the TB search, I would have needed to:
  • Search Inbox without subfolders for "From contains @somedomain" or "To contains @somedomain" or "Cc contains @somedomain". This also searches previous years, and takes quite a while on my IMAP folder.
  • Save the search
  • Search Sent for "To contains @somedomain" or "Cc contains @somedomain".
  • Save the search
  • Create a folder for results
  • Open the first saved search folders, sort by date, and copy the 2009 mails to the new results folder
  • Repeat with the second saved search.

Labels: , , , , ,

Wednesday, December 30, 2009

OpenVPN client on Ubuntu 9.04 Jaunty

A few notes on setting up the openvpn client on Ubuntu, after my move from Windows. Configuration through the Network Manager VPN tab didn't work for me. As far as I could see, there was no way to directly import or copy my existing .ovpn files from Windows because NM doesn't use them. Instead, it uses it's own config files, which do not provide all the options of the standard openvpn client. The solution was to
  • install openvpn and resolvconf so that the name servers can be updated: sudo apt-get install openvpn resolvocnf
  • copy my .ovpn and key files to /etc/openvpn,
  • install gopenvpn to have a handy GUI launcher in the Gnome Panel. (the .deb package needs to be downloaded from the site)
  • Edit my .ovpn files to add up /etc/openvpn/update-resolv-conf and down /etc/openvpn/update-resolv-conf
It seems to work fine now. One example client .ovpn file looks like this:
client
dev tun
proto udp

remote hostname.example.com 1194

resolv-retry infinite
nobind
persist-key
persist-tun
mute-replay-warnings

ca example-cacert.pem
cert clientname.example.lan.pem
key clientname.example.lan.key

comp-lzo
verb 3

up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
2 little things are annoying: I need to enter my password, because changing the network requires root privileges. I'm sure there must be a solution, but the annoyance is probably not worth the time needed to find and apply it. And the other glitch is that window asking for my key's password sometimes opens behind the others.

Labels: , , , ,

Friday, September 18, 2009

Boot an iso file on your hard disk using grub

I needed to update the firmware on several of the infamous Seagate Barracuda 7002.11 drives with the buggy "SD15" firmware.

Seagate offers a Windows executable or an ISO file to create a bootable CD. However, I had only a Mac, a Linux notebook without a CD drive, and a Windows notebook with neither a CD nor any possibility to attach SATA drives.

After some googling, it looked like the Intel Mac could be booted from such a DOS CD, and that might have worked ... but I didn't even have a blank CD.

But wouldn't it be possible to boot from an .iso file on the hard disk?

As it turns out, it is. And this will probably prove quite handy to boot various Live CDs.

My notebook has Ubuntu, with the standard Grub boot loader. Grub cannot boot from an iso file, but another boot loader called grub4dos can. And Grub can boot that smart cousin of his... Yes, it's a sort of weird setup, but it worked for me.

There are also ways to do that on a Windows system. But here is the Linux version:

  1. Get grub4dos from sourceforge or gna.org
  2. Extract grub.exe from the zip file and copy it to your /boot directory.
  3. Also put the .iso you want to boot into your /boot directory.
  4. Edit your /boot/grub/menu.lst file and add these lines:
title == Load grub4dos below to be able to boot the following entries ==

title 1: reload this menu using grub4dos
kernel /boot/grub.exe

title 2: boot the Seagate firmware ISO file
map --mem /boot/MooseDT-SD1A-3D4D-16-32MB.ISO (hd32)
map --hook
chainloader (hd32)

(Adapt the "title 2: ..." line, and of course the "map --mem /boot/name-of-your.iso" line with the right file name. Note that it is case-sensitive)

When booting, you will first be in your standard grub, where you select the "1: ..." entry to load grub4dos. It will do just like grub, find the same menu.lst file, and display it again. Now you can select the .iso entry, which grub4dos will understand.

It is probably also possible to store the iso files on other partitions, but that is "left as an exercise to the reader" ...

See also: the wiki, this guide, a "success stories" thread or this other thread with a much hairier setup.

Labels: , , , ,

Monday, June 22, 2009

Pirater la musique, c'est mal

...

Il faut l'acheter pour que les multinationales du disque ne finissent pas comme les constructeurs de voitures américains artistes gagnent quelque chose. Alors j'essaye...

J'étais allé voir iTunes il y a des années, mais c'était réservé aux américains, et ne proposait que des fichiers cryptés que je ne pouvais pas écouter sur l'appareil de mon choix.

Puis sont venus les .mp3 de Amazon.com. Je m'y suis précipité, mais ils sont réservés aux américains.

Depuis, iTunes est disponible en Suisse, et il paraît qu'ils ont enfin renoncé au DRM dans leurs fichiers. Alors j'essaye itunes.ch. Pour découvrir que je ne peux télécharger de la musique que si j'installe le programme iTunes sur un ordinateur Mac ou Windows. Non merci.

Après de longues recherches par Google qui me propose des dizaines de sites et de manières de télécharger immédiatement la musique que je souhaite par divers moyens illégaux, je découvre Qobuz.com qui semble très intéressant. Hélas, c'était durant un week-end où leurs serveurs souffraient de pannes, et je n'arrive à rien.

Quelques semaines plus tard je retourne sur Qobuz.com, et j'y fais mon choix. Au moment de "passer à la caisse", je suis envoyé chez ClickandBuy qui semble être leur seul moyen de payement. ClickandBuy prend note de toutes mes données de carte de crédit, adresse, téléphone, etc. puis doit absolument m'envoyer un SMS avec un code de confirmation. Hélas, le code n'arrive jamais, malgré 2 tentatives, et mes vérifications minutieuses du numéro de téléphone portable que je leur donne.

Mais j'ai entendu dire que Amazon France offrait enfin aussi des .mp3. J'y trouve ce que je veux, mais au moment de mettre la musique à télécharger dans mon "panier", je reçois ce message: "Message important Nous sommes désolés. Nous n'avons pas pu traiter votre commande en raison de restrictions géographiques appliquées au produit que vous avez essayé d'acheter. Veuillez consulter les conditions d'utilisation de ce produit pour déterminer les restrictions géographiques applicables. Nous nous excusons pour la gêne occasionnée."

Heureusement, je peux écouter toutes ces musiques chez mon voisin, qui semble connaître de meilleurs moyens pour se procurer de la musique rapidement et sans complications...

Labels: , , , , ,

Saturday, May 23, 2009

Hard drive partitions and file system essentials

What most normal users need to know about hard disk partitions and filesystems to be able to move hard disks between various operating systems like Mac or Windows.

Hard disks contain 1 or more partitions. To the user, each partition appears as if it were a separate hard disk.

(In Windows, each partition receives a separate drive letter like C:, D:, etc.; on a Mac, you see a separate icon on the desktop for each partition; in Linux, each is a device like /dev/sdb1, /dev/sdb2, etc.)

Every partition needs to be formatted with a file system to let the operating system store and retrieve files. (On Mac, this formatting process is called "erasing")

There are many different types of file systems. Your system needs to understand these file systems to be able to use them. Unfortunately, various operating systems use different file systems. The problem is to find which one will be understood by all the systems you intend to connect your drive to. Also, some systems only support reading some file systems, not writing to them.

Summary

Below is a table trying to summarize the compatibility between the 3 main operating systems and the 4 main file system types. There are many others, but if you know about them, you probably don't need this page.

Windows Mac OS X Linux
FAT32 or DOS

Native support

Max. 4GB. file size

Read/Write

Max. 4GB. file size

Read/Write

Max. 4GB. file size

NTFS Native support

Read only.

Write support through external drivers. 1

Read/Write on recent distributions. 2
HFS+ or "Mac OS extended" Requires third party programs for reading and writing. 3 Native support

Read only.

Write if the journaling feature has been turned off in Mac OS X. 4

Ext2 or Ext3 Free drivers allow Read/Write access.5 Requires commercial driver. 6 Native support
FAT or FAT32 (named "MS-DOS" in Macs)

This the oldest of the file systems commonly used today. As such, it has the greatest compatibility and the least functionality. It is a sort of lowest common denominator.

All operating systems can read and write to it. It is the file system generally used on USB flash drives, memory cards for photo cameras, etc.

It cannot store files greater than 4 Gigabytes. It is also the least reliable of the current file systems, and has many other drawbacks (fragmentation, no support for permission, time stamps in local time and with only 2 seconds resolution, etc.)

The Windows disk manager refuses to format a FAT32 partition greater than 32 GB. But it can be formatted in Windows with the free fat32format.exe utility, or can be formatted to the wanted size on Mac or Linux.

NTFS

Is the native file system of Windows.

Macs can read it, but cannot write to it.

However, there is a Mac version of the open source NTFS-3G driver which can write to NTFS. 1

Recent Linux versions can both read it and write to it (thes usually have this NTFS-3G driver installed by default). 2

HFS aka. "Mac OS X" HFS+ aka. "Mac OS X Extended (journaled)"

Is the native file system on Macs.The Mac default is the HFS+ journaled variant.

Windows needs special programs installed to be able to read or write it. 3

Linux can read it when it has the hfsutils package installed. It can also write to it if journaling has been disabled. 4

Ext2 or Ext3

is the most common file system on Linux.

(If you wonder why you would need to know anything about Linux: while it is not very common as a desktop operating system, it is the system used in almost all your non-computer devices which contain a hard disk, like your NAS backup disk, your media player, etc. If that device breaks, you may be able to recover the files from it's hard disk by connecting it to your main computer and installing the driver for the ext2 file system)

Windows can read and write to it using free drivers. 5

There is a Mac driver, but it may be problematic. 6

Footnotes:

1. Mac -> NTFS : Get the free and open source driver from http://www.ntfs-3g.org/. You may also want to have a look at the user guide and the macntfs-3g blog.

2. Linux -> NTFS : In case you have an older distribution which doesn't have it pre-installed, you can normally install "ntfs-3g" using your distribution's package manager. Or have a look at their availability page.

3. Windows -> HFS : If you only need to copy files from a Mac disk to your Windows machine, you can use the free HFSExplorer, which will open your drive in a Windows Explorer-like window and let you copy files from there.

For full support, you may need commercial software like MacDrive or similar.

4. Linux -> HFS : If it isn't already on your system, you will need to install the "hfsutils" package.

If you need to write to the HFS disk, journaling must be disabled. You need to do this on a Mac. Afterward, you can re-enable journaling (again on a Mac). See here how to turn off journaling to enable writing: http://ubuntuforums.org/showthread.php?t=392287

5. Windows -> ext2/3 : There are 2 free drivers. The open source one is at http://www.ext2fsd.com/ and the closed source one is at http://www.fs-driver.org/.

6. Mac -> Ext2/3 : You can try the commercial ExtFS for Mac OS X. (There is also a free open source driver, but the project doesn't seem to be actively maintained. It may have worked well on older Mac OS versions, but when I tried a simple folder move with the current version 1.4d4 on a Mac OS X 10.5 system, it made the system crash hard, and left a badly corrupted drive, which I had to repair using e2fsck on Linux.)

Labels: , , , , ,

Friday, April 24, 2009

The Is Your New Bicycle Meme Revisited

Even though the '... Is Your New Bicycle' meme is already over a year old, I couldn't resist adding to it. So here is a new meta-meme-site for your amusement:

allyournewbicylces.com fetches new 'Is Your New Bicycle' quotes for you

It has a list of the best sites which are still alive, selects one, gets you a fresh quote from it, and displays it using the obligatory layout, with a helpful link to the original source site in the corner.

And in case you find it easier to remember, it even has an alternative name: thisisyournewbicycle.com.

If you had not heard about this American election year meme, this is the original site (which even became a book), and here is an article about it.

Labels: ,

Wednesday, March 18, 2009

Installing latest FFMPEG on Debian Etch

How to install the latest FFMPEG on a Debian 4 ("Etch") server? This post encouraged me to try it, despite the fact that it needs compiling from source, and that Etch isn't even the current "stable" Debian anymore. PhillC's post helped a lot, but it still didn't work for me exactly as described there. So here is how it eventually did work for me.

# echo "deb http://www.debian-multimedia.org etch main" >>/etc/apt/sources.list

or

# echo "deb http://www.debian-multimedia.org stable main" >>/etc/apt/sources.list

(I used both, and fiddled with enabling and disabling that repository, so I'm not sure anymore which one ended up being useful).

aptitude update gave me a GPG error, so I had to add the key it mentioned:

# gpg --keyserver hkp://wwwkeys.eu.pgp.net --recv-keys 07DC563D1F41B907
# gpg --armor --export 07DC563D1F41B907 | apt-key add -
# aptitude update

The following didn't work, or only worked partially:

# apt-get build-dep ffmpeg
Reading package lists... Done
Building dependency tree... Done
E: Unable to find a source package for ffmpegcvs
I continued anyway with the long install line of various libraries. I had to remove some of these libraries from the suggested install line. Particularly, since I had to recompile libx264 anyway, I should have removed libx264-dev at this point. It is removed in the line below:
# aptitude install liblame-dev libfaad-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev build-essential subversion

# cd /usr/src
# svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

And so I got the current version as of March 17:

Checked out external at revision 28979.
Checked out revision 18021.

And I tried configure:

# cd /usr/src/ffmpeg
# ./configure --enable-gpl --enable-pp --enable-libvorbis --enable-liba52 --enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libfaad --enable-libfaac --enable-pthreads --enable-libx264 -enable-libxvid

After various errors, and removing options, I ended up with this error:

ERROR: libx264 version must be >= 0.65.

And trying to install that from the debian-multimedia.org repository didn't work either:

# aptitude install libx264-65
The following packages have unmet dependencies:
libx264-65: Depends: libc6 (>= 2.7-1) but 2.3.6.ds1-13etch8 is installed and it is kept back.
So this thread came to rescue, and I embarked on getting x264 and compiling that from source too:
# aptitude install git git-core

Trying to use Git at this point gives an error, but suggests the solution:

# update-alternatives --config git
There are 2 alternatives which provide `git'.
Selection    Alternative
-----------------------------------------------
*+        1    /usr/bin/git.transition
        2    /usr/bin/git-scm

Press enter to keep the default[*], or type selection number: 2

Next steps:

# cd /usr/src/
# git clone git://git.videolan.org/x264.git
# cd x264
# ./configure --enable-shared

This gave an error about yasm, which was not the right version. I could have tried to compile that too, as shown on the Ubuntu forum, but impatiently decided to try the suggested disable option instead. So the x264 part which worked:

# ./configure --enable-shared --disable-asm
# make
# make install
# ldconfig

And finally, ffmpeg:

# cd /usr/src/ffmpeg/
# ./configure --enable-gpl --enable-postproc --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libx264 --enable-libxvid
# make
# make install
I also had to remove the old ffmpeg version (aptitude purge ffmpeg) which I had installed some time before this, and finally did this:
# echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
# ldconfig

Since I had a leftover libx264 installed with aptitude and which was too old, that caused a segmentation fault when I tried to encode with ffmpeg. After searching (aptitude search x264), I found i had to aptitude purge libx264-54 libx264-dev . Then, just to be sure, I re-did the ./configure, make clean, make, make install incantations for both x264 and ffmpeg.

In the end, ffmpeg is working. I suppose the --disable-asm option on x264 will make encoding slower, so it may be worth compiling yasm, and re-compiling x264 again.

Now that ffmpeg is working, the main problem is trying to understand it's myriad of incomprehensible and cryptically documented options.

Labels: , , , , , ,

Friday, January 23, 2009

Encoding video sizes

Video compression usually works on square blocks of pixels. These can have sizes of 8x8 or 16x16 or other powers of 2. H264 (AVC) for example, uses macroblocks of 16x16.

So when compressing video, it helps if the frame size is such that both width and height are evenly divisible by 16 or at least by 8. This is why videos encoded for the web or for portable video players are often not exactly in a 16/9 aspect ratio. The PSP's screen, for example, is 480 x 272 even though true 16/9 would require 480 x 270. But 270 is not divisible by 16 whereas 272 is. Youtube uses 640x360, which is true 16/9 and divisible by 8. If you use other sizes, FFmpeg will print a message like

width or height not divisible by 16 (480x270), compression will suffer.

So what are the sizes which are both the right aspect ratio and nicely divisible by 16 or by 8? This little Perl script will let us know:

#!/usr/bin/perl

my $aspect_width  = 16;
my $aspect_height = 9;
my $max_height = 1200;
my @dividers = (16, 8);

for my $divider (@dividers) {

print "$aspect_width/$aspect_height with both ",
     "width and height divisible by $divider :\n\n";

# try sizes up to Full HD
for my $i (1..$max_height/$aspect_height) {
   my $h = $aspect_height * $i;
   unless ($h % $divider) {
       my $w = $aspect_width * $i;
       printf "$aspect_width/$aspect_height divisible by %2d : %4d x %4d\n",
              $divider, $w, $h;
   }
}

print "\n";
}

For 16/9, this gives, among others, numbers like

16/9 divisible by 16 :  256 x  144
16/9 divisible by 16 :  512 x  288
16/9 divisible by 16 :  768 x  432
16/9 divisible by 16 : 1024 x  576
16/9 divisible by 16 : 1280 x  720

For sizes divisible by 8, you obviously have all of the above, plus (among others):

16/9 divisible by  8 :  384 x  216
16/9 divisible by  8 :  640 x  360
16/9 divisible by  8 :  896 x  504
16/9 divisible by  8 : 1920 x 1080
16/9 divisible by  8 : 2048 x 1152

Labels: , , , , ,