Late last week, I took the plunge and upgraded my work desktop–which, to the Irony Gods’ great delight, is also a production server–from Ubuntu 11.10 to the Precise 12.04 known as Pangolin.
Cue every IT professional ever:
With two tiny exceptions, though, it’s been a remarkably smooth transition. The first (and most trivial) of the two exceptions was that MySQL was, without explanation or warning, uninstalled entirely from my system, leaving me to reinstall it manually. Once that happened, all my databases reappeared as if it was all some big Hide and Seek game.
The second is proving less of a tiny exception and more of a “WHY WON’T THIS WORK”: getting OpenCV to behave once more.
I’ve been using OpenCV’s Python bindings in order to do some small on-the-fly video manipulation with the data we’ve been gathering for my research. We still largely use Matlab for operations like optical flow (since we’re not terribly confident in what, exactly, is happening in OpenCV for those calculations), but for things like extracting a single frame from the video, converting it to a PNG image, and throwing it up on a website, it works extremely well.
I’d been using the old version of OpenCV, the one that comes in the Ubuntu package manager; I believe it’s 2.1, when the newest version is 2.4 and features some radical changes to the API. It was easiest to use (nothing beats a simple
apt-get install) and worked just fine.
Problem! When I upgraded from 11.10 to 12.04, it suddenly stopped working. The frames we extracted using the same exact code suddenly looked either like this or were completely black.
Over the past weekend (in addition to the Pittsburgh Marathon, which I’ll write about later), I posted this question on StackOverflow to try and diagnose the problem. It’s since spun almost out of control into a step-by-step-by-step ordeal where each subsequent action solved the previous problem while simultaneously introducing a new one.
- I started here, uninstalling all the packages from Ubuntu for the critical components (OpenCV, ffmpeg, libvpx, x264), and then downloading the source code for each one and following the compilation and installation instructions listed.
- On the last step–recompiling OpenCV–it kept crashing with a very cryptic error message:
relocation R_X86_64_32S against `av_destruct_packet' can not be used when making a shared object; recompile with -fPIC. Wish I knew what that meant!
- My Googling around led me here–someone with the same problem! I tried adding the apparently-magical
--enable-sharedflag to the ffmpeg configuration, and…nothing. Actually, worse than nothing: now ffmpeg started throwing the same cryptic error!
- AGJWOIEJQJ*WJOWEIDQAWAKJDFSRAAAAAAGE QUIT
- I went back a step, and rebuilt and reinstalled libvpx with the same magical flags (
--enable-shared), then tried it again on ffmpeg…and holy crap it worked!
- Tried recompiling OpenCV once more…AND IT WORKED! Successfully built and installed with no problems. Would this finally perform the simple action of pulling one frame from a video and saving it as a PNG?
- NO! It couldn’t even find the ffmpeg executable! Something about missing shared libraries! OH GOD MAKE IT STOP.
- More Googling around turned up this gem, which ended up being exactly what I needed. NOW let’s test OpenCV and see if it works?
- …no. Of course not.
You can follow this progression on the SO question itself, but needless to say I am once again stuck. There’s not a whole lot I can do until this is fixed, and the problem is likely some menial little codec somewhere that got removed in the Ubuntu upgrade but which OpenCV won’t admit that it needs.
I suppose I still have plenty of other things to keep me busy.
EDIT: Yep, I finally figured it out. Yes, all the steps beforehand were required to even attempt the final solution, but [as usual] I blocked myself from reaching the ultimate destination by leaving out one. crucial. line of code. from the script that went something like this:
grab() method is more than just a check (mentally I made it analogous to Java’s Stack’s
isEmpty(), for example) and actually bootstraps the whole process. Without it my program couldn’t do anything. Mystery solved.