Tuesday, August 25, 2009

Video processing

At my previous job I was working on integrated security system (ISS). One of major task was to capture and process video from video cameras. Usually, it was looked like PC-box with 3-4 very cheap tv-tuners based on bt878 and connected to some kind of "intellectual" signal splitter. It was possible to connect up to 32 cameras using single high-frequency cable of length up to several kilometers (I don't remember maximal extents, sorry). VGA-signal from camera was modulated by special small box, so all three dozens were connected to PC using one cable. If that looks like drastically cheap solution for you, I can ensure you: actually, it is even cheaper than in your dreams! ;)

Our PC boxes were powered by Red Hat Linux 9 and, later, Fedora 2 and 5. Software was written entirely in C++ plus a bunch of shell and perl scripts. For video capturing itself we used Video4Linux2. It was approximately 1.2 megabytes of source code, some parts of it with heavy usage of Boost library. I can say, it was PITA to do research job in project, because, nevertheless we had ability to do partial builds via autotools, project was building at least 2-3 minutes, even after one small change. I didn't know any other computer language at that time, except "must have" z80 and x86 assemblers, C/C++ and some shell/perl. Ok, assembler isn't "must" now, but is highly recommended and useful in video processing tasks, believe me :) Of course, as a normal mainstream programmer, I participated to flame wars at internet forums w.r.t "super high-level" languages, and heard, these new languages can speed up development several times. So, I had some thoughts how would it great to abandon C++ in our ISS at least in non-critical parts like GUI, setup tool, logic, etc.

Later I've started to read Common Lisp books and use SBCL for dumb helloworlds. I found Common Lisp is pretty lovely and, in the case of SBCL, is enough fast tool. I wanted to give it a try in video processing, but have changed my employer and country :) Heh.

2 years flew away, some weeks ago, being kinda more seasoned Lisp programmer, I started to dance around CFFI-bindings for Video4Linux2 - CL-V4L2 project, which, in future, should be a base for my small home brewedmade ISS. The project sources are at public GIT repository repo.or.cz. Currently, it's possible to capture video from both my web-cameras. I don't have tv-tuner yet, but I'm almost sure it will work.

Example in CL-V4L2 uses CL-GTK2 to draw a picture in GTK-window. I sent a patch to CL-GTK2's author, Dmitry Kalyanov, the patch adds ability to use GL-accelerated canvas in your application (via gtkglext library). Dmitry should prepare new sources for inclusion in CL-GTK2 shortly. I remember image scaling was one of the largest CPU consumer in ISS, and bulk GLDrawArea-prototype showed pretty good results: image scaling became as cheap, as a cost of cheapest modern graphic card you can buy in stores.

So, basically, bindings are ready for work, but they are capture oriented only, no video output, no VBI, not all ioctls and structure are implemented. However, it is quite easy to extend its feature set now. Use it, enjoy it, report bugs :)


Ewoud said...

Your English is much better readable than from google translate ;)

13-49 said...

... And still not perfect :)

Anonymous said...



Easy said...

Могу порекомендовать неплохую брошюру
The Elements of Style
, by Oliver Strunk. Умные люди ее часто рекомендовали. Жаль, что я им мало внимал.

13-49 said...

Thanks, the book looks very appealing.