Before we begin our professional applications, we need to verify that the system has been set up for optimal performance. Performance is essential when working on the system, because video and audio streams can lose frames if the system is not fast enough to keep up with them. The higher the quality of audio or video, the more likely it is that frames will be lost, a situation that is referred to (at least in audio) as an “xrun.”
There is a tool, called the “Realtime Config Quickscan,” which is a simple script to look over the computer to verify that all settings have been optimized for real-time operation. Assuming nothing was successfully set up, though, we’ll go through the optimizations now, one at a time.
Keep in mind that you will need to get your hands dirty; these will require you to edit text files, but also keep in mind this is a one-shot deal. Once you change those settings, you will not need to adjust them again unless you wipe your computer and install the system again. (Or unless you are using a LiveCD to actually do work… not really a good idea, since the disc will slow the computer down dramatically every time you launch a new tool.)
In order to do quite a few of these steps, the easiest way to ensure we’re all in the same page, I recommend you open a terminal window now. Different systems have it in different locations, but usually, they go by names like “terminal,” “console,” or “xterm.” (The last is the classic name for them, according to UNIX parlance)
No Disk Access Time Recording
Filesystems are important for hard drives; they create the folder/file structure that allows you to save and open projects and their associated media. However, if the drive moves slowly, then the performance of the project suffers.
One issue in particular is what is known as “atime;” meaning that a date is assigned to a file every single time you access it, whether you move it, write to it, or even just read it. This can happen thousands of times in a single second; files being used to allow the system to run are being updated as well.
In order to resolve this issue, you have the ability to change all mounted drives to not use access time. The file to edit this will be “/etc/fstab” (short for “Filesystem Table”).
The command to edit this file from the command line is:
sudo gedit /etc/fstab
sudo” command tells the system to run the program as an administrator user, “
gedit” is essentially a Linux desktop equivalent for Windows’ “Notepad”, and “
/etc/fstab” is the name of the text file we want to edit.
Now that the editor is open, you’ll see quite a few lines looking like this:
/dev/sda1 / ext4 defaults 0 1
In every line where the third item has “ext2”, “ext3”, “ext4”, or “reiser” (the most common filesystem types), replace “defaults” with “noatime”. For example, the above would then look like this:
/dev/sda1 / ext4 noatime 0 1
If something other than “defaults” appears in that spot (we’ll use “nodev” as an example), then you just add the “noatime” after a comma, like this:
/dev/sda1 / ext4 nodev,noatime 0 1
Newer processors have a power-saving feature; they can reduce their speed when not actually being used very hard. This is referred to as “processor scaling.”
On a time-sensitive process like sound or video editing (where the quality depends on the frame rate remaining perfectly synchronized), this can have a negative effect, possibly ruining the current task in the workflow. So the next thing we need to make sure of is that the processor is not changing its speed on a regular basis.
In a Linux system the speed of a processor is controlled by its governor (and no, I’m not talking Ahnuld). Linux has four kinds of governor, performance (processor is always at its fastest), powersave (processor is always at its slowest), conservative (processor slowly increases and decreases speed as system load requires), and ondemand (system jumps to maximum speed when performance is needed, and remains at slowest speed otherwise). When doing audio or video recording, we always want the most performance, so performance is the governor we want to use.
If you’re using Ubuntu with GNOME, there is a panel program that can control your processor speed. If you have it, start it, and set the processor to its top speed for the time while you’re working. Then, you can change it back when you’re doing things that are not as speed-sensitive.
If you’re not using a desktop capable of adjusting the speed, you may need to use another program to temporarily change your processor’s performance, namely cpufreq-set. The following command can be used to set all cores in a processor to performance governor:
for x in $( seq 0 7 ); do sudo cpufreq-set -c $x -g performance; done
Granted, the command will need to be run each time you want to use the studio software. If you want this to be readily-accessible when you need it, then you can copy and paste the above into a file, and mark it “executable” (right-click on new file, select “properties,” select the “Permissions” tab in the dialog that appears, and check the box labeled “Allow executing file as program”) to make it run when you double-click it.
Memory is a valuable resource, and the more, the better. However, sometimes the amount of memory in the computer is not enough, and it needs a “shot in the arm” to free up some space. Similar to jotting notes to avoid forgetting something, a computer has something called “Swap space,” where it can temporarily jot down what it knows regarding a program it hasn’t updated for a while, so it can free up memory for a more recent program’s use.
However, just as how you’d need to stop for a moment to do the writing, so too does the computer. Not very good when you’re working with time-sensitive work like video and audio. So, you generally want to wait until the absolute last minute before beginning the writing process. This is where “swappiness” comes in.
By default, a computer will begin writing to swap space well before getting near the “full” mark. This means that it will be writing and reading on the hard drive frequently, and each time will require it to pause. So, we want to reduce the frequency of this process, so we can set the system to wait until the memory is much closer (but not all the way) to full.
By default, the “swappiness” value in the system is set to 60, which provides the default behavior. However, by reducing this number to 10, the computer will wait much longer before trying to write to disk. This has a side benefit in that it will rely on swap space less often, increasing the overall performance.
To change the “swappiness” value, you have to add the following line to the “/etc/sysctl.conf” file (the end is fine):
vm.swappiness = 10
The “vm” means “Virtual Memory” (the computer’s equivalent to a note pad), and the period means that “swappiness” applies to virtual memory. Once you become familiar with the system, you can adjust the value to another number, a smaller one meaning the system waits longer to take notes, a larger number means it starts sooner.
A “daemon” is another name for a server program; Windows calls them “services.” If you’re working on audio or video using a system that maintains servers, then you are likely going to have problems when said server kicks in. The way to fix this is pretty simple: If you’re going to work with audio, either use a non-server system, or turn off the server programs while you’re working, unless they’re necessary (such as streaming servers, if you’re performing a streaming broadcast).
The same issue also applies to fancy desktop gadgets and eye candy; it may be nice to know what the weather will be for the next week, or what Lady Gaga’s dress will be made from in her next video, but if you lose frames, then your own video might not be able to compete.
Clocks and Timers
Timing is everything in streaming data. The camera waits for no man, and certainly for no computer. It just sends its signal into the computer, and the computer can either keep up or fall behind. Additionally, if every single frame isn’t timed perfectly, the recording can be ruined, as variations in time between one frame and the next can cause quality issues.
Every computer has an internal clock and timer; these work together to ensure that the computer operates at a steady rate of speed, and accomplishes everything as quickly as possible. More important, these allow time-sensitive programs to operate correctly, and you don’t get much more time-sensitive than audio or video (except in medicine).
By default, Linux systems have these devices enabled, simply because it would be pretty dumb not to; after all, the clock is required to keep the system time correct, and timers are needed to keep the system operating properly. However, they are not accessible to the average user.
However, Linux has a nifty tool that can allow this to be changed. It is called UDev. UDev is the latest in a long line of attempts to set up Linux so it can detect and install new hardware as it’s being plugged in, such as USB devices and newly-inserted optical discs. This program is also capable of assigning permissions on-the-fly, according to rules set in its configuration files, and both the clock and timer are under this awesome program’s control. To tell it that you want them to be accessible requires two steps.
The first step is to create a special file in /etc/udev/rules.d/, let’s call it “50-audio-timing.rules”, and inside this file, put just the following two lines:
KERNEL=="rtc0", GROUP="audio" KERNEL=="hpet", GROUP="audio"
The next step is to create an “audio” permission group, if one doesn’t already exist, by using the following command (if it already exists, the command will let you know):
sudo addgroup audio
This group is going to be VERY important, because it is necessary for limiting the extreme power (and risk) of realtime performance to those people who have the right to use them, namely, you and whoever else needs to work with you on your audio and video. I just use “audio,” because these steps are mainly for preparing for realtime audio work, but video can benefit from these changes as well.
Next, assign yourself to that group using the following line, replacing username with your own username:
sudo adduser username audio
Feel free to add the accounts of any other editors along the way. This change will require you to restart the system before it takes place.
Security limits are important; there are a lot of ways one can H4Xx0r a system, and limiting what an account can do is important for this. However, some limits can be stretched when dealing with high-performance work, once again, including video and audio.
The realtime capabilities of Linux are generally reserved for the operating system itself; after all, if any user had that kind of control, some antisocial punk could make a little program that could completely lock up a computer system in no time… there’d be little challenge in that. However, realtime priority is essential for our purposes, so we need to allow it to happen, at least, for members of the above “audio” group.
The file to edit varies from system to system. If the “/etc/security/limits.d/” folder exists, then you can create an “audio.conf” file in that folder. If it does not exist, you can edit the “/etc/security/limits.conf” file directly, adding the following lines:
@audio - rtprio 90 @audio - memlock unlimited
The “@audio” means that the changes will only apply for people in the “audio” group. The first line gives the highest priority to programs run by the person in the “audio” group, while the second line gives the program unlimited memory space to operate its realtime tasks. Needless to say, these can make your system extremely fragile if you run risky software that try to take it over; it can eat all of the system memory, and lock out all other programs from accessing the processor… the primary reasons these are not set for everyone.
If you made it this far, and you followed the above instructions, then you can pat yourself on the back, your system is now nearly ready to begin working with media. Check the above-mentioned tool, though, to make sure there are no further steps required. It used to be common to download and install a realtime kernel for the process, but these days, the stock Linux kernel has sufficient performance that this is no longer required; I can get very good performance out of a stock kernel with no problems.
From here, we can now begin getting the tools, and with them, make something good!