Mittwoch, Januar 18, 2006

Video Streaming Server with VLC from analogue tv card

When this year's skiing season started (including Winter Olympics), we wanted to share some of the events with our colleagues. We reused some of our old hardware (Thunderbird, 900Mhz (a Pentium III, 800MHz had some frames dropped!) 20GB HD, Hauppauge WinTV FM Tv-Card (Connexant 878A chip)) to build a linux tv streaming server. As Kubuntu's vlc (Kubuntu 5.10 Breezy Badger) had problems with multicast streaming (segmentation fault), we used SuSE 10 with the vlc package from packman.

Installation of SuSE10 was easy. The WinTV card was recognized, kdetv did a frequency scan and found all channels that are receivalbe by antenna.

VLC will be used as a multicast streaming server, but the package is no included in the standard SuSE distribution (the open source distribution at least), so the rpm was downloaded from packman. The packman vlc page also indicates some dependencies, that were also downloaded. Additionally I downloaded some other rpms from packman, they might come handy later on:

The packages from packman are:
a52dec-0.7.4-3.pm.1.i586.rpm
alsa-1.0.10-0.pm.1.i586.rpm
divx-6.1.1-0.pm.0.i586.rpm
faac-1.24-0.pm.2.i586.rpm
faad2-2.0-0.pm.7.i686.rpm
ffmpeg-0.4.9-4.pm.cvs20060201.i686.rpm
imlib2-1.2.1-0.pm.0.i586.rpm
lame-3.96.1-pm.1.i686.rpm
libdvbpsi4-0.1.5-1.pm.1.i586.rpm
libffmpeg0-0.4.9-4.pm.cvs20060201.i686.rpm
libmpcdec-1.2.2-1.pm.2.i586.rpm
libvorbis-1.1.1-0.pm.0.i686.rpm
mad-0.15.1b-1.pm.0.i586.rpm
speex-1.1.11.1-0.pm.0.i686.rpm
vlc-0.8.4a-1.pm.4.i686.rpm
w32codec-all-20050412-0.pm.0.i586.rpm
xvid-1.1.0-0.pm.4.i686.rpm
xvid4conf-1.12-0.pm.1.i686.rpm

A "rpm -Uhv *.rpm" resulted in a long list of missing dependencies (db1, dvdread, dvdnav, xosd, etc.). Except for dvdcss all were found in the suse repository and were installed with yast. As we did not want to watch dvds and dvdcss is not that easy to install (see packman) we skipped this dependency with "rpm -Uhv --nodeps *.rpm".

We had some troubles getting the sound to work in vlc. First, we tried a small cable between the line out of the tv-card and the line-in of the soundcard, which gave us sound in kdetv and xawtv (after increasing the level in the mixer for line-in!). But vlc did not use the /dev/dsp device (no idea why!). So after reading a bit on the videolan pages, we used the module "btaudio" to access the audio on the wintv card directly:
modprobe btaudio (as root)
added the module and created the devices /dev/dsp1 and /dev/dsp2 (for digital and analog sound). Please check the log messages with dmesg to find the analog device! When we added the module to the /etc/sysconfig/kernel later to load automatically on startup, the devices were /dev/dsp and /dev/dsp1 (for digital and analog) - so finally the correct device was /dev/dsp1!

/etc/sysconfig/kernel:
MODULES_LOADED_ON_BOOT="btaudio"

So, thats about the configuration/installation. The only thing left is to watch tv with vlc:
This task was not as easy as it could be, as vlc did not give any picture/sound when the device, frequency, etc. were seletected in the dialog for capture device (strange, as this worked perfect on the (k)ubuntu installation! But when we used the command line options

v4l:/dev/video:norm=pal:frequency=189250:size=640x480:channel=0:adev=/dev/dsp1:audio=0

and not the different way to write them all separated (as the dialog shows), it worked!
Please change the tv-norm, frequency and audio device to the values in your country and installation! The frequency was taken from the kdetv channel list.

The complete command line that multicast the tv program to the ip group @239.255.1.1:
vlc v4l:/dev/video:norm=pal:frequency=189250:size=640x480:channel=0:adev=/dev/dsp1:audio=0 --sout '#transcode{vcodec=WMV2,vb=512,scale=0.5,acodec=mpga,ab=128,samplerate=44100,deinterlace}:standard{access=udp,mux=ts,url=239.255.1.1}'
(all in one line!)

The clients connect then with the url:
vlc udp://@239.255.1.1

have fun
Christof