Realtime Linux Security Module

del.icio.us TRACK TOP
Posted on December 28th, 2006 by joey. Filed in linux, kernel.
No comments yet. Be the first to comment!

Audio and video applications require low latency times in order to deliver high data rate content. On Linux, if you want to run audio applications such as Ardour or Rosegarden, which use JACK, then you either have to be willing to run them as root, or you have to set up the Realtime Linux Security Module. Realtime LSM allows non-root users to run applications with realtime priority, meaning that your audio apps can take priority over other processes.

There are a lot of HOWTOs out there that provide a good description of how to build a Linux kernel. I don’t want to write another one here, so if you’ve never compiled a Linux kernel before, you can hit Google up for the terms “Linux kernel build HOWTO” and bask in the wonders of the information age. I’ll summarize my own experience here in brief.

I’m running Fedora Core 6 on an older IBM ThinkPad. The sources that live under /usr/src/kernels/2.6.18-1.2798.fc6-i586/ were useless because they didn’t compile. What you want to do is go fetch the official Kernel sources. I unpacked the kernel sources under /usr/src/, creating the directory /usr/src/linux-2.6.18/. I then copied /usr/src/kernels/2.6.18-1.2798.fc6-i586/.conf to /usr/src/linux-2.6.18/.conf.

I couldn’t get the patch for Realtime LSM to apply cleanly, but it’s a simple patch, so I was able to manually fix it up. patch was ignoring or misreading directory information in the patch, so it dumped new files into the root of the kernel sources and tried to patch the wrong make file (I’d love to know how to fix that, but no -p option seemed to work). I had to move realtime.c into the security directory, and manually update security/Makefile to add the line from the patch. Then I edited .config to make sure that the following directives had the correct values:

CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_SECURITY=y
CONFIG_SECURITY_CAPABILITIES=m

I manually added the following line to .config, which would have gotten added automatically if I’d run $ make config.

CONFIG_SECURITY_REALTIME=m

Once all that was in place, the build process was simple, if time consuming:

$ sudo make bzImage
$ sudo make modules
$ sudo make modules_install
$ sudo make install

The install procedure will automatically update /etc/grub.conf so that you can select the new kernel from a list the next time you boot up. I updated /etc/grub.conf manually to make sure my custom kernel had a unique label since by default it was labeled as a Fedora Core kernel. Once you’ve rebooted and verified that the new kernel works, it’s time to load the realtime module. Since my GID is 500, I used the following command:

$ sudo /sbin/modprobe realtime gid=500

Note the capitalization on “gid”. You’ll pull out a lot less hair if you remember that it’s case sensitive. You can tell that the realtime module is working by running $ jackd -R -d alsa. If realtime isn’t working, then you’ll get a permissions error.

High Resolution Timer

del.icio.us TRACK TOP
Posted on January 2nd, 2007 by joey. Filed in linux, kernel.
No comments yet. Be the first to comment!

If you’re planning on using rosegarden, when you recompile your kernel you’ll want to make sure the following options are set like this in your .config:

# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000

Doing this got rid of a start-up warning from rosegarden that told me I didn’t have a high enough resolution system timer to really work with MIDI. The Fedora Core 6 stock kernel seems to keep time at 250Hz, which is not fast enough for rosegarden.

IEEE 1394/FireWire Video Capture

del.icio.us TRACK TOP
Posted on January 4th, 2007 by joey. Filed in capture.
No comments yet. Be the first to comment!

Most digital camcorders these days support IEEE 1394, AKA FireWire, for transferring video to the hard drive of your computer. Linux has good support for a variety of IEEE 1394 devices, and compatibility listings can be found at linux1394.org. We purchased the Pyro PCI 64 (API311) card from ADS Technologies, Inc. We chose that card mostly because it was available at the campus computer store and is supported under Linux.

There are capture facilities built into cinelerra and kino. At first blush, when configured for IEEE 1394 capture, cinelerra locks and spews errors when I hit record. More digging will be required to unravel the mysteries of cinelerra’s capture capabilities. Kino works great without any configuration and allows you to monitor and control your DV deck via the FireWire.
However, the dvgrab utility (available on the kino website) is perfect for my own purposes. Mostly, I’m working with capturing whole tapes. Final Cut’s logging and capturing facilities allow you to annotate time codes on each tape and later grab only the media that you need. With the speaker series, the subjects are giving an academic lecture and are covered by a single camera, so little editing is possible or required. As a result, we just capture one big file. To capture an hour of Mini-DV tape with dvgrab, the command is simple:

$ dvgrab –duration 1:00:00 /path/to/file

dvgrab automatically puts the DV deck into play mode, then stops it after one hour has elapsed. If you know your media is shorter, you can shorten the time. The appropriate filename extension will be automatically appended to the output filename you specify. You can change the output file type with the –format option (see the man page). dvgrab splits all its output so that the file size never exceeds 1GB, a limit that can be changed via the –size option. This splitting behavior causes dvgrab to number its output files so the above command would result in a new file named “file001.avi”.

Kino is quite happy to work with the video that dvgrab produces by default. When I imported the same file into cinelerra, it would not initially play back in real time. After some poking, I found that this was a reaction to degraded performance, not a functional problem with the video format. My current test machine is relatively slow, with only a half gigabyte of RAM and a small display. The default cinelerra preferences use a processor intensive scaling algorithm, and when I changed to the cheapest scaling algorithm I could get frame rates around 24 FPS; still lower than the 29.97 FPS frame rate of the video. To make this change, select ‘Preferences…’ from the Settings menu in the timeline window. Select Playback from the drop-down list in the upper left of the preferences window. Under the Video Out section, set the ‘Scaling equation’ option to ‘Nearest neighbor enlarge and reduce’.

Video Editing Software

del.icio.us TRACK TOP
Posted on January 9th, 2007 by joey. Filed in editing.
1 comment filed

A little time spent with Google quickly shows that there’s a good number of video editors available for Linux, but where does one start? Wikipedia has a list of non-commercial, open source video editors for Linux and other operating systems, but it’s unfortunately presented with little context and no evaluation of the individual packages. In 2005, Dan Sawyer wrote an excellent article for the Linux Journal in which he compared a number of the video editors available for Linux. It’s a testament to the rapidly shifting sands of FLOSS that two of the five projects he examined are now defunct: while Cinelerra, Kino, and Blender are still going strong, Diva (formerly of diva-project.org) and Cuisine are apparently no longer developed. What else has changed?

After quite a lot of searching and evaluating, it appears that Cinelerra, Kino, and Blender are still at the top of the heap. I’m working on descriptions of each of these packages which I’ll post here in the coming days (it’s too much to post all at once).

Recently Jahshaka has entered as a promising new project, but as yet I haven’t put forth the effort to make it work. LiVES is another promising tool, but also currently lacks clean packaging, making installation non-trivial. I hope to be able to talk about these experimental/alpha systems as time allows.

Blender as Video Editor

del.icio.us TRACK TOP
Posted on January 10th, 2007 by joey. Filed in editing.
No comments yet. Be the first to comment!

Blender is primarily a 3D modeling and animation suite, so it may seem odd to include it in this discussion. Blender was developed as an application capable of all the tasks in a CGI production pipeline, so it provides a non-linear editing mode (the “sequence editor”) capable of most video editing tasks. On Fedora Core, installation of Blender is as easy as issuing the command “sudo yum install blender”.

Blender sports some extremely compelling features. Video sequences can be cut, trimmed, overlayed, and repositioned quickly and easily with single-frame accuracy. Blender’s node based compositing system allows for extremely sophisticated effects, color correction, and transitions. The latest release includes chromakey nodes, allowing for green-screen effects.

However, there is a long list of reasons Blender may not be ideal in certain situations.

  • has no video capture facilities, so Kino, dvgrab or some other utility is required to get video onto your workstation.
  • has no built-in facilities for managing your video clips, so you will need to carefully organize them yourself.
  • keeps track of time in terms of frame counts, quite natural for animators, but alien to video editors who primarily use SMPTE.
  • does not output a true 29.97 NTSC frame rate, which may make working with sound difficult. This is not an issue if you work in 24p video.
  • has only rudimentary support for sound in the sequence editor; again, quite satisfactory for animation, where sound is mastered separately, but it is not ideal for video editing.
  • the user interface presents a relatively steep learning curve, though there are clear benefits to productivity.

Because of Blender’s origins in animation and its impressive image manipulation facilities, it is ideal for highly stylized video. It’s probably not the best choice for the impatient beginner or simpler, more straight forward video.

Kino Video Editor

del.icio.us TRACK TOP
Posted on January 11th, 2007 by joey. Filed in editing, kino.
No comments yet. Be the first to comment!

Kino, unlike Blender, is expressly built as a video editor. The developers’ goal in building Kino is to offer “easy and reliable DV editing for the Linux desktop with export to many usable formats” (citation). I think they’ve hit that mark dead on.

Kino’s installation is trivial via yum on Fedore Core (sudo yum install kino). DV capture via IEEE 1394, AKA FireWire, works right out of the box. Kino offers a simplified interface where clips (called “Scenes”) are arranged in a vertical time-line (the “Storyboard”) along the left edge of the screen. Clips are re-ordered via drag and drop. Any clip can be trimmed non-destructively. Effects may be applied to clips and transitions can be made between clips, but these effects are rendered to new files and inserted as new clips rather than being applied in real time. The recent addition of the Superimpose and Titler video filters provide support for titiling and the ability to composite PNG based image sequences over your video. When the timeline is polished to your satisfaction, the export function allows you to write your video back to DV tape over your IEEE 1394 connection, or to create a variety of formats appropriate for VCD, DVD, or web distribution.

However, the simplified approach that makes Kino so responsive and stable also makes some things a little more difficult. Kino has no multitrack video support (aside from the Superimpose video filter). This makes certain editing styles more difficult to accomplish, for instance, in a recent project I needed to cross cut between two cameras that had been running simultaneously while using a sound track that had been recorded via DV tape. Cutting between the cameras using Kino would be an exercise in counting frames. Kino can’t work with a secondary sound track, so in this example the audio output would be cut between the two cameras, same as the video, constantly ping-ponging the audio levels. Finally, Kino presents a relatively sparse set of filters, which in turn limits its ability to create sophisticated visual effects.

In the final analysis, Kino is best suited to simple, straightforward video work. This is entirely consistent with its intended purpose as a consumer grade video editing package.

The Open Source Media Manifesto

del.icio.us TRACK TOP
Posted on January 11th, 2007 by joey. Filed in culture.
No comments yet. Be the first to comment!

Sometime before 2004, I’m not sure exactly when, J.D. Lasica, working with the Internet Archive, published an Open Source Media Manifesto. It’s still an interesting read, especially with regards to some of the ways it’s gotten out-of-date.

We hold free expression and public commentary to be fundamental to living in a democracy. If we are going to have public education and free elections, then everyone must be able to express themselves and publicly critique each other’s views.

The manifesto unites the spirit of open source with that of grass-roots journalism. Lasica discusses it in some detail here. Unfortunately, I don’t think the project they envisioned really prospered, not in the way that Creative Commons has. But it’s not like the idea went away. For instance, Open Source is a PRI distributed radio show that works in the spirit of the Open Source Manifesto:

We designed the show to invert the traditional relationship between broadcast and the web: we aren’t a public radio show with a web community, we’re a web community that produces a daily hour of radio.

The manifesto appeared prior to the explosion that was YouTube—founded in February of 2005. Suddenly “Broadcast Yourself” has become a slogan attached to a business model rather than the original and radical notion proposed by the manifesto. Among the goals that Lasica set out in the manifesto was to create tools for annotation and quotation via deep-linking to media. Tools for annotation are no longer needed because YouTube style videos can be embedded directly in your commentary. Tools for deep linking aren’t needed because quotation can be performed by digital copy at no greater expense (to the YouTube poster) than quotation by reference.

To a certain extent the idea of “open source media” is materializing as a lived reality. At the same time, we’re seeing the rise of “consumer generated content,” which is probably closer to the terminology used in boardrooms. The distinction, I think, is largely economic. Open source media is economically agnostic—money making certainly isn’t verboten. On the other hand, consumer generated media implies a capitalistic framework that maintains the traditional roles of sellers and purchasers, only now individuals can wear more than one hat. Lawrence Lessig recently gave a talk that articulates what is at stake.

Cinelerra Video Editor

del.icio.us TRACK TOP
Posted on January 12th, 2007 by joey. Filed in editing, cinelerra.
5 comments filed

Cinelerra is the most sophisticated of the open source Linux video editing packages I’ve looked at. The developer describes Cinelerra as capable of turning an appropriately powerful Linux box into a “50,000 watt flamethrower of multimedia editing.” Although this is certainly hyperbolic (and the author has a penchant for the hyperbolic), Cinelerra is quite competent and is a serious tool.

On Fedora Core, Cinelerra can be installed in binary form using the rpm utility, but not via yum. Cinelerra loads a sufficiently broad variety of common video formats. While it advertises the ability to capture DV from IEEE 1394 sources, the configuration to make this work is non-trivial (I haven’t gone down that rabbit hole yet).

Cinelerra allows for three-point editing (defining in/out and insertion points) as well as cut-and-paste editing. Clips on the time-line can be extended, trimmed, and shifted by dragging their endpoints. Multitrack video is supported, allowing titles to be composited over video, or switching between views in a multiple camera shoot. Multitrack audio is also supported, allowing for the addition of a sound track or voice-over. Cinelerra also allows you to zoom and pan video tracks using a camera/projector system which provides support for more advanced compositing effects. A variety of video and audio filters are available, some of which, such as the pixel tracker and stabilization plugins, aren’t available in common commercial packages. Cinelerra can render to output formats appropriate for use in DVD and on the web.

However, Cinelerra is not as stable as Kino and has a reputation for crashes. The documentation is serviceable, but a bit thin. The interface supports common editing activities, but it’s a little weird in the way it does some things, e.g. making a section of a video track invisible, in order to reveal the track below, is done by “muting” it. Perhaps this is only a pet peeve of mine, but once clips are loaded to the time-line, they cannot be repositioned by dragging the clip itself, rather you must use the endpoint handles to push it around. Finally, the stated hardware requirements for Cinelerra are pretty heavy, although in my experience it will run acceptably well on much lighter systems.

To sum up, Cinelerra is the most functionally complete open source video editing solution for Linux that I’ve seen.

MP4 for web distribution via ffmpeg

del.icio.us TRACK TOP
Posted on January 16th, 2007 by joey. Filed in distribution, ffmpeg.
3 comments filed

If you intend to distribute your video content via the web then you will want to minimize the size of your video file in order to incur the least cost in terms of bandwidth. There are three strategies that will lead to lower video file sizes: using more efficient or aggresive compression, reducing the resolution of the file, and reducing the frame rate of the video.

For web distribution we use the MP4 file format with MPEG-4 part 2 encoded video and MP3 encoded audio. The MP4 file format is specified as part of the MPEG-4 suite of standards and is playable by a broad range of media players, including iTunes and the iPod in case you’re podcasting your video. In order to transcode your video into the MP4 format you simply specify the .mp4 file extension for the output file and ffmpeg will understand what you want.

$ ffmpeg -i input.avi output.mp4

If for some reason you want to use a non-standard filename extension, then you must make the file format explicit:

$ ffmpeg -i input.avi -f mp4 output.ext

While the H.264 codec would be ideal, ffmpeg does not yet support encoding in H.264, so instead we use the MPEG-4 part 2 Advanced Simple Profile. The best compression ratio for audio in the MP4 format is still achieved via MP3 compression. The audio codec and video codec can be specified via the -acodec and -vcodec options.

$ ffmpeg -i input.avi -acodec mp3 -vcodec mpeg4 output.mp4

The -b option sets the video bitrate, and the -ab option sets the audio bitrate. By default ffmpeg uses 200 kb/s video bitrate for the mpeg4 codec and 64 kb/s audio bitrate for the mp3 codec.

The most common resolution for web distribution is 320×240; a 4:3 aspect ratio with square pixels. Almost all the video on archive.org is in that resolution, as are MP4 (iPod) video downloads from google video. To force this resolution, use the -s option:

$ ffmpeg -i input.avi -acodec mp3 -vcodec mpeg4 -s 320×240 output.mp4

Note that the same video encoded at standard resolution and at 320×240 will have roughly similar file sizes. This is because the codec’s bitrate is constant: bitrate times time equals file size. Reducing the video resolution allows you to use a lower bitrate with fewer compression artifacts.

If your source material is interlaced, add the -deinterlace option. I don’t know how ffmpeg deinterlaces video, and it’s likely not a great method, e.g. choosing one of the fields and scaling it up to a 4:3 aspect ratio; however, if you’re going from standard definition to 320×240, even the most brutal deinterlacing methods will be hidden by the scaling.

Finally, to squeeze every last spare bit out of the video file, you can reduce the frame rate. Most video can be dropped to 24 FPS with no perceptible change. For relatively static material, such as slide presentations, very low frame rates in the 2-4 FPS range may be appropriate. Again, you also have to reduce your bitrate or 24 FPS will produce an image with fewer compression artifacts rather than a smaller file size. Set the frame rate with the -r option:

$ ffmpeg -i input.avi -acodec mp3 -vcodec mpeg4 -s 320×240 -r 24 output.mp4

A great way to experiment with acceptable bitrates is to use the -ss and -t options. The -ss option seeks to a position in the input file, and the -t option sets the duration of the output file. Thus:

$ ffmpeg -i input.avi -ss 30 -t 5 output.mp4

Will encode a five second clip of the input file thirty seconds from its beginning. This lets you see what the resulting compression level will look like without encoding the whole video.

New Multimedia Distribution - Ubuntu Studio

del.icio.us TRACK TOP
Posted on January 22nd, 2007 by joey. Filed in linux, news.
No comments yet. Be the first to comment!

On boingboing yesterday it was noted that there will shortly be a new flavor of Linux distribution focused on providing support for multimedia creators. Ubuntu Studio, scheduled to be available in April 2007, will include Cinelerra-CV (the community version). This means that Cinelerra-CV will soon be available as packaged software for Ubuntu, making it accessible to a much broader set of users.