A simple goal: Record myself playing the piano with nice audio and video quality, do some video/audio editing and upload it to YouTube to share with my friends….using Linux! Especially the audio quality needed to be good. And it should not be to expensive. This turned to be not as easy as it sounds. This will be a big blog message! A lot of experience, mainly based on trial-on-error and lots of Googling is represented here. I believe it will provide a good starting point on audio/video editing and recording in Linux. At least it will describe a working, not to expensive solution, covering all steps from setting up some hardware, to audio/video recording and editing with popular tools in Linux, to uploading the result to YouTube.

The challenges I faced:

  • Getting the audio and video hardware to work in Linux
  • Selection of the audio recording tool and getting it to work with my hardware
  • Selection of the video recording tool and getting it to work with my hardware
  • Placement of the microphones
  • Syncing the recorded audio and video
  • Perform some basic audio editing
  • Perform some basic video editing
  • Transcoding to a video format where YouTube leaves both audio and video in tact ( as much as possible )
  • My level of knowledge of audio/video recording and editing

The Hardware

      •  Logitech HD Webcam C310, good Linux support
        ( not a very good source for recording video, but the best low cost source so far )

 

      • Tascam US-122L, USB Audio recording, good Linux support

 

 

Getting the video hardware to work

The webcam works out the the box. It is detected automatically as an UVC camera on my Ubuntu 11.04 box. With v4l2-ctl I can get and set camera parameters. Not sure if they all have effect. One effect I noticed is that the camera is doing some automatic light balancing, which makes the video all the sudden switch several levels of brightness. Very common functionality for I webcam I assume. But not what I wanted. I tried to counteract this with:

/usr/bin/v4l2-ctl --set-ctrl=white_balance_temperature_auto=0
/usr/bin/v4l2-ctl --set-ctrl=exposure_auto_priority=0
/usr/bin/v4l2-ctl --set-ctrl=backlight_compensation=0

Vlc automatically detected the camera and Kdenlive (which uses ffmpeg) with the following settings:

-f video4linux2 -s 1280x720 -r 25 -i /dev/video0 -vcodec mjpeg -qscale 1

The mjpeg video codec is a very good option for recording. Each frame gets encoded separately, so no fame loss / compression etc which could potentially be one of the sources audio and video can get out of sync, according to some sources on the net. The mjpeg codec will take a little CPU to do it’s work. Another video codec that worked is mpeg1video. Working with mjepg recordings in Kdenlive was impossible on my system (  Intel(R) Core(TM)2 Duo CPU     T9600  @ 2.80GHz ). During just playback of the clip, the kdenlive process would take about 160% or more CPU ( e.g. both cores fully busy ). Not an option. Working with mpeg1video video’s in Kdenlive worked better.

Getting the audio hardware to work

Getting the audio hardware is a whole other story. I might devote an entire blog on that one. For now: put the following in ~/.asoundrc (use the correct card number from cat /proc/asound/cards):

# The usb_stream plugin configuration
pcm.!usb_stream {
  @args [ CARD ]
  @args.CARD {
    type string
    default "1"
  }
  type usb_stream
  card $CARD
}

ctl.!usb_stream {
  @args [ CARD ]
  @args.CARD {
    type string
    default "1"
  }
  type hw
  card $CARD
}

Next run the following commands:

modprobe modprobe snd_usb_us122l ( enable=1 index=1 id=1 )
sudo su -c 'echo @audio - rtprio 99 >> /etc/security/limits.conf'
sudo su -c 'echo @audio - nice -10 >> /etc/security/limits.conf'
sudo su -c 'echo @audio - memlock 250000 >> /etc/security/limits.conf'
/usr/bin/jackd -dalsa -dusb_stream:1 -r48000 -p1024 -n2

At this point jackd is running. You can now use any Jack aware program to record and play audio from and to the Tascam US-122L. It is better to use the great qjackctl: Jack Audio Connection Kit configuration tool written in Qt. jackd is a daemon which sits between the audio hardware (Alsa)  and one ore more programs( Rosegarden, Audacity,  Ardour, … ) for recording or playback. Jack includes support for MIDI and JACK-transport for time synchronization ( see xjadeo for example ). And most important, it can run in Real Time. Using Connect and the Patchbay you can connect input ports to output ports. Multiple connections to the same input or output ports are allowed. Use connect to connect temporarily. Use the Patchbay to automatically connect ports when a jack client program connects to jackd. For example the system in and out ports of the US-122L can be connected to audacity. This will audacity to real-time record and playback using the US-122L. To connect jack to pulseaudio (default audio daemon on Ubuntu) it is needed to load some modules into pulseaudio. To do this from the command line:

/usr/bin/pactl load-module module-jack-source
/usr/bin/pactl load-module module-jack-sink

It took me quite some time to get the right settings for jack to get it to record and playback without jack buffer under or over runs (X-RUN). See above jackd command line or the Setup screen in qjackctl. Most of the times when an XRUN occurs you hear a click in the audio. Not good ;-) . I run jackd with a 48,000 Hz sample rate. 96.000 Hz is both with the Tascam and Jack supported. And in my opinion does give even better sound quality. For reference: HD CD is 48.000 Hz.

 

Selection of the audio recording tool and getting it to work with my hardware

To be continued!!
Selection of the video recording tool and getting it to work with my hardware


Placement of the microphones


Syncing the recorded audio and video


My level of knowledge of audio/video recording and editing

Recording audio and video
Record the audio and video stream with ffmpeg: ffmpeg -ac 2 -f jack -itsoffset -00:00:00.80 -i ffmpeg -acodec copy -y test.wav -f video4linux2 -s 1280×720 -r 25 -i /dev/video0 -vcodec copy -copyts -an -y test.avi. This will create 2 files: audio.wav containing a one-on-one copy of the audio input stream. And video.avi containing a one-on-one copy of the input video stream. No decoding and encoding is done. In this case the audio recording is done using jack. I have and Tascam US122L which is managed by Jack and Alsa. Setting just this up is a whole other story. The Tascam is capable of recording my piano using a very good quality. 2 semi-professional microphones, recording the back of the piano.

Comments are closed.