Update on FFmpeg 3.0 and Firefox

Posted on .

Well, that was a short-lived package. FFmpeg 3.0 support was included in Firefox 45, released just a few days ago. A specific FFmpeg 2.8 package is no longer needed.

Nice surprise in the Fedora freetype package

Posted on .

I was pleasantly surprised a couple of days ago with the way the freetype library is packaged in Fedora, when I removed every trace of RPMFusion from my system and attempted to rebuild freetype with subpixel rendering support.

As I mentioned sometimes in the past, I prefer to package the missing bits in a Fedora installation myself, but I had RPMFusion installed, and normally disabled, to have easy access to Steam and freetype-freeworld, an alternative freetype package with subpixel rendering enabled.

Subpixel rendering is a technology that’s patented in some parts of the world (not my home country) and is disabled by Fedora in the freetype package for mere legal reasons. The freetype project includes an implementation in its source code.

A few days ago I decided to uninstall Steam from my Linux system and, with it, every other i686 package. The only thing left from RPMFusion was freetype-freeworld.

When I investigated how to build freetype myself to create my own freetype package with subpixel rendering enabled, I found a nice surprise. The freetype package maintainer has included some code in the package SPEC file that makes it trivial to rebuild with subpixel rendering in a few commands. Here’s how.

One-time setup

There are some things to set up only once for the first time, as taken from the Fedora guide on how to create RPMs. You should install some packages and package groups in your system, you should add a new user to build packages as and, finally, you should prepare an RPM-building environment for that user.

# As root:
dnf install @development-tools
dnf install fedora-packager
dnf install rpmdevtools

/usr/sbin/useradd makerpm
usermod -a -G mock makerpm
passwd makerpm

# As the new user.

I called my user “build” instead of makerpm, but the username is irrelevant. You also need to install every package that’s required to build the freetype package and is, as such, listed as “BuildRequires” in the SPEC file. As of the time I’m writing this, these are libX11-devel, libpng-devel, zlib-devel and bzip2-devel.

# As root.
dnf install libX11-devel libpng-devel zlib-devel bzip2-devel

Every time you want to rebuild the freetype package

The first time, or when Fedora updates the freetype package (it doesn’t happen very frequently), you’ll find out your font rendering is bad again. Only three commands are needed to rebuild the package.

First, download the source RPM for the package and rebuild it.

# As the RPM-building user.
cd ~/rpmbuild/SRPMS
dnf download --source freetype
rpmbuild --rebuild --with subpixel_rendering freetype-WHATEVER.src.rpm

The key here is the patch the freetype package maintainer provides to activate subpixel rendering, and everything that’s set up so calling rpmbuild with the --with subpixel_rendering option applies the patch and builds a package with the technology activated. Great job on their part.

Finally, proceed to reinstall your custom version of the packages.

# As root.
cd /home/makerpm/rpmbuild/RPMS/x86_64
dnf reinstall ./freetype-WHATEVER.rpm

Then, restart your X applications, or restart the whole X11 GUI or simply reboot and your font rendering will be good again.

FFmpeg 3.0 and Firefox

Posted on . Updated on .

Not long ago I blogged about Firefox being able to use FFmpeg directly. Since then, FFmpeg 3.0 has been released, with incompatible changes API and ABI-wise. I wasn’t sure about upgrading, but now the dust has settled and the strategy forward is clear.

I have several packages in my system that use FFmpeg, most notably mpv and MOC. mpv builds and runs with FFmpeg 3.0 just fine, and MOC needs a small code change that has already been committed to “trunk” in its Subversion repository.

However, Firefox dynamically loads FFmpeg when running and is currently bound to the API and ABI of FFmpeg 2.8. I’m not sure if it’s easy for Mozilla to support two FFmpeg ABIs simultaneously and a search on their bug trackers didn’t turn up any relevant results I could see about future FFmpeg 3.x support.

If you simply replace FFmpeg 2.8.6 with FFmpeg 3.0 in a given system, you will see Firefox refuses to load its libraries and the YouTube HTML5 video test page won’t show H.264 as available if you were relying on FFmpeg to provide that support.

I monitored what Arch Linux did in this regard because their Firefox package depended on FFmpeg. So far, they have chosen to make Firefox depend on a newly created “ffmpeg2.8” package which can be installed in parallel with “ffmpeg”, and using a simple ld.so.conf file to tell Firefox where to look for FFmpeg libraries. Note the FFmpeg project still supports branch 2.8 and it’s expected to receive security fixes for the time being.

I replicated that work in my SPEC files repository. FFmpeg 3.0 is built normally and FFmpeg 2.8.x creates a special “ffmpeg2.8” package. As you can see, this one is built with --disable-programs, --disable-doc, --disable-static, --disable-debug and --disable-filters. These flags make sure only the dynamic libraries and header files are installed as part of the package. In addition, libdir, shlibdir and incdir are configured so the files end up in a specific subdirectory instead of colliding with FFmpeg 3.0.

Finally, the package ships a file in /etc/ld.so.conf.d adding the directories /usr/lib64 and /usr/lib64/ffmpeg2.8. The second one is obvious and needed for the dynamic linker to find the FFmpeg 2.8.x libraries when Firefox requests them. The first one just makes sure /usr/lib64 is chosen first as the source of the libraries without any version suffix, should any program need them.

This scheme will need to be supported until Mozilla ships FFmpeg 3.0 support directly in Firefox. Monitoring what Arch Linux does with their Firefox package is a good idea and will give you a rough estimate on when to deprecate and remove the specific “ffmpeg2.8” package.

Update: Support for FFmpeg 3.0 will land in Firefox 46, according to bug 1232268 and its related bugs. Firefox does ship support for several FFmpeg/LibAV binary versions at the same time, as you can easily observe in the FFmpegLibWrapper.cpp file.

Game Review: Severance: Blade Of Darkness

Posted on . Updated on .

Severance: Blade Of Darkness or Blade: The Edge Of Darkness (its original title) is a third-person RPG from Spanish studio Rebel Act released in 2001. I’ve played and enjoyed the game many times over the years and I wanted to write a small homage review before its 15th anniversary at the end of this month.

Severance was recently featured in the “Have You Played?” section of Rock, Paper, Shotgun. This prompted me to download my copy from GOG.com and play it one more time. Or, more precisely, four more times, once for each main character you can select. Nowadays, if you want to play it and you don’t already have a copy, your options are severely limited. As of the time I’m writing this, Severance is no longer present in the GOG catalog (probably due to their license expiring). It can be downloaded if you’ve already purchased it but it’s not available for new sales. This situation may change in the future.

History and piracy

While I own a legal copy nowadays, I must admit I pirated the game back when it was released. I’m far from proud of pirating games in my youth but when I was a student I simply didn’t have the money to buy every game I wanted to play. I owned quite a few games legally, but not every one of them. If I had been unable to pirate those games, I simply wouldn’t have played them. Other games released in 2001 include Serious Sam, Max Payne or Return to Castle Wolfenstein.

I’m sidetracking a bit here, but I think one of the problems in the video game industry, and also one of the reasons DRM is used so aggressively and sometimes obnoxiously, is that video games, today, are very expensive to produce, and they’re sold to people who don’t have much money themselves: students, teenagers and kids. Moreover, parents from previous generations have always seen video games as a not-very-desirable hobby. I’m sure many would prefer their kids to play sports outdoors instead of games for hours in the basement, so they don’t tend to buy their children every game they want to play even if, in contrast, they take them to the movies to watch most films they wish. When gamers like myself grow up and get a job, they can finally buy plenty of games but what they start lacking is the time to play them. I see a lot of people and friends pursuing other hobbies and dropping gaming when they grow up, get a job and start earning real money.

Rebel Act Studios closed not long after the game was published and I’m pretty sure more sales would’ve helped keep the studio alive. Part of the team later founded MercurySteam and they’ve recently been developing a few Castlevania-universe games for Konami. Rebel Act have also admitted that they ran out of money developing the game and they had to publish it in a somewhat unfinished state, wrapping up what they had to create a gameplay experience as cohesive as possible. This can be perceived in some gameplay aspects, but the game is fine as it is. The essentials are there. I sincerely apologize and regret not having bought the game for its full prize when it was released.


Obviously, a game from 2001 is in a totally different league from what you see nowadays. If you play it from the mind of a 2001 gamer, you’ll see some impressive features, like the water reflection effects and dynamic lights and shadows. I remember being impressed at the time by its graphics and animations, and how the shadows were also integrated in the gameplay beyond a mere technical feature, many times being projected on walls to give you hints and clues of enemies nearby, or to scare you making them look bigger than they are.

The sounds were unique and good too, and the game sound track was also skillfully integrated in-game to set the mood of every area and moment. Surprisingly, it was comprised of several pieces of freely available music.

Remarkably, game assets were not packed in large custom binary files and could be found in the game data directories as plain files. This also revealed much of the game logic actually resides in Python scripts (version 1.5 at the time!). Even savegames themselves are stored as Python scripts.

On a side note, if you want to run the game nowadays I recommend the following setup. Configure the game for a 640x480 screen resolution using the Voodoo 1 and 2 renderer, which is based on Glide, the 3dfx API. In GOG, the game is shipped with the latest version of nGlide, a library that provides a Glide API implementation using modern Direct3D as the backend. Dive into the game directory and find the nGlide setup tool. Configure nGlide with it to use a 4:3 resolution that maximizes the vertical space of your screen (I chose 1440x1080 as I have a 1080p monitor) and force 4:3 to be the screen aspect ratio. If you use an NVIDIA card like I do, from the NVIDIA control panel choose not to scale the screen and use the GPU for scaling. This will make sure the game is rendered in the center of your monitor with proper aspect ratio and black bands on the left and right.

Using the previous setup, the game menus, HUD and help screens will be big as they were intended to be in the original game, while the game world itself is transparently rendered in 1440x1080 at 32 bits per pixel. The only drawback of using nGlide is a glitch when rendering the help screens, in which the red and blue RGB channels are swapped. I contacted the nGlide author and he told me it’s a problem in the game code and its usage of the Glide API. In any case, they’re still perfectly usable and you won’t have to use a mod manager or mess with the OpenGL renderer and its major flaws rendering the game fog, which affect whole levels like the Gorge of Orlok. The original Direct3D renderer is too buggy in modern systems and fails to display many things properly. I ran the game in Windows 10 without any compatibility setting and only got a few crashes here and there. I think most of them were present in the original release, except for a game saving bug I hit a couple of times that made me replay some level sections.


Gameplay is very entertaining even if some people think the game’s too hard. However, it’s much simpler and easier than, say, Dark Souls, a game it’s often compared with despite both being quite different.

At the start of the game you can choose between four characters: an amazon, a knight, a barbarian or a dwarf. Each of them prefers a specific subset of the available weapons and features a unique introduction level before playing a common set of levels. While some weapons are generic and could, in theory, be used by any character, your best bet is to use your character’s favorite weapons, which can be seen on the help screen. That’s a range of pole weapons for the amazon, two-handed swords and axes for the barbarian, single-handed swords and maces for the knight, and single-handed axes and hammers for the dwarf.

Your character’s level sets the amount of health and stamina. You hit the enemy by using the attack button combined with a direction key or a dodge movement. Every character has a set of basic combos available that can be used with any weapon provided you have the required level. Higher levels give access to more powerful combos. The character’s favorite weapons also have a unique combo each that can be performed if your level is high enough. In general, unique combos are the most powerful ones and can be used when enemies attack and miss, and are left exposed to your attacks. You can start using most weapons before you reach the required level for its combo, and you can continue to use them after surpassing the required level if you don’t like the combos of (in theory) better weapons you may have available.

The game has no difficulty levels and is played as it is. In general, I’d say the game is easiest with the amazon. You can perceive they didn’t finish polishing that character because of the low amount of general combos she has and because the game’s a bit unbalanced with her. The unique combo with her best weapon is powerful enough to tear bosses and minibosses apart in two, three or four attacks. From there, the standard and most polished character is the knight, having many combos, armor and being generally balanced. The barbarian and dwarf make the game harder for those inclined to face a small challenge. The barbarian is simply too slow and his combos are easily interrupted by enemies. This happens throughout the whole game. The dwarf suffers from a very short attack range, but I think playing with him gets progressively easier as the game advances. Some of his weapons and combos are fast, cover a wide angle and allows the character to move two or three steps forward, reaching unsuspecting enemies. I kept using the third best weapon with the dwarf in the final levels just because of its special combo, combining it with the Sword of Ianna.

After playing the game with all four characters in a row, I think its low points are the enemy and combat variety. The number of different enemies is alright for a 2001 game, but more or less the vast majority of the game is spent fighting about five different types of enemies: goblins, orcs, knights, skeletons and zombies. Combat-wise, each of them has a very specific set of movements that are very easy to memorize, anticipate and provoke (with knights being the least predictable and more cerebral ones). I found combat to be based usually on waiting for the enemy to start a combo, dodging it, and attacking the exposed enemy with your own combo. In other words, while your available combat movements are many and varied, in practice you only use a small part of them.


I don’t think there’s much point in giving scores to a 2001 game, but I’ll try.

From the perspective of 2001, the technical score is easily a 9. From today, there’s no point in giving it any score. The gameplay aspect could easily be an 8 or 9 in 2001, and nowadays the level variety, geometry, puzzles and the use of sound and music can keep it as high as a 7, for example.

So you think you can program an elevator

Posted on .

So You Think You Can Program An Elevator is a very interesting programming exercise that reached the front page of Hacker News a couple of weeks ago.

It’s about programming the logic controlling an elevator and responding to elevator passengers and people outside the elevator pressing buttons by deciding if you must stop when you reach a given floor, or start going up or down.

The exercise itself requires some basic Python knowledge, but the interesting part is how it may be able to surprise you and be much harder to solve than you expect (or maybe you nail it on the first try, who knows?). There’s also some difficulty in distilling the logic requirements from the long description and the unit tests themselves, which contain cases that the main description lacks. In this sense, it’s a wonderful insight into capturing software requirements from a client, for example.

So if you have some spare minutes or hours, I recommend you fork the repository and try to follow the instructions and code snippets carefully. You’ll probably have some frustrating fun!