Sunday, January 25, 2009

Mencoder v4l2 - Solving the crackling noise in audio when recording from tv card


One of the few things that I could not get right for many months on my Ubuntu Linux installation is the ability to record television programmes from my low end Hauppauge WinTV-PCI-FM card. Playback was excellent using tvtime, in fact it was better than playing back on Windows using the manufacturer's software. However, whenever I tried recording TV using mencoder (that comes with mplayer), an obvious crackling/clicking noise was always present in the audio stream. This was a shame as the video recording offered higher quality than what I could record using Windows. Furthermore, I was able to directly record into any format that mplayer was capable of playing.

The command I used is shown below, it outputs the tv card's composite video and audio into the file, test.avi. Thinking it was something to do with my audio sampling settings, for months I was twiddling with the command used for recording to no avail by adjusting the both the sampling rates (in red below) between 38400Hz, 44100Hz and 48000Hz. In short, I was recording using PAL-BG encoding from the television signal with sound coming from the first alsa sound driver device (adevice=plughw.0,0). Read more about the various options here

$> mencoder -tv norm=PAL-BG:driver=v4l2:width=768:height=576:input=2:alsa:amode=1:adevice=plughw.0,0:audiorate=48000:volume=0:immediatemode=0 -af resample=48000:volume=-5:1 -oac mp3lame -lameopts preset=medium:vol=0:highpassfreq=0:lowpassfreq=0 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1200 -vf harddup,crop=720:544:24:16,pp=lb -noskip -ffourcc divx -o test.avi tv://

No matter how many audio filters I applied, I could never remove the crackling noise from the audio stream. Finally, after talking to my dad about how crackling noises may enter recorded audio streams due to too high a sampling rate, I decided to lower the sampling rate from the raw audio input stream differently. Where previously I adjusted the sampling rates between only 38400Hz, 44100Hz and 48000Hz (the only values accepted by the lame audio encoder), I decided to sample the input audio stream at a slightly lower rate and then resample the stream to be acceptable to the lame audio encoder as shown below. The sampling of the audio input is set at 47950 but to be resampled to 48000 for the encoder.

$> mencoder -tv norm=PAL-BG:driver=v4l2:width=768:height=576:input=2:alsa:amode=1:adevice=plughw.0,0:audiorate=47950:volume=0:immediatemode=0 -af resample=48000:volume=-5:1 -oac mp3lame -lameopts preset=medium:vol=0:highpassfreq=0:lowpassfreq=0 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1200 -vf harddup,crop=720:544:24:16,pp=lb -noskip -ffourcc divx -o test.avi tv://

To my surprise, that was it. All the irritating crackling noise disappeared! I can now put the command into a bash script for scheduling the recording of my television programmes in better quality and more flexibility than I can on windows.

Sunday, January 4, 2009

Happy Holidays 2008/09


The happy holidays came and went. Before I know it, it's time to get back to work. There were many gatherings during Christmas, one of the more memorable was at my place.


Heating a pre-roasted turkey in my oven, I had to squish it in as it barely fitted


"Boiled vegetables like broccoli is more healthy!", quips my friend


Boiling the pasta


Add oil while and after boiling to prevent sticking


Getting the sauce ready


The roast turkey, we had a free upgrade to a larger size


The simple spread, not too much, not too little


The must have log cake that came free as well

After Christmas and counting down to the New Year, I spent my last weekend with my partner watching Ip Man, an excellent must watch movie, and tried Sakae's Teppanyaki for the first time. While the teppanyaki did taste great, the value for money was average.


Roasting garlic and frying eggs on the pan for the garlic fried rice


We took a 2 person set, it came with some maki and sashimi


Chef in garlic fried rice action


Garlic fried rice garnished with some miniature shrimp, loads of garlic went into it that kept me awake the whole night


Grilling the rest of the items. Unfortunately, not all belonged to us, guess what is in the dome?


It is actually Chawanmushi but in an onion instead of in a tea cup


Prawns almost done


Frying of vegetables


Lots of garlic in these


Chawanmushi done


Teriyaki chicken, I ate the teriyaki cod fish before I could snap it

Overall it was an overload of garlic, giving me insomnia the entire night. I recommend those going for Sakae's Teppanyaki to go for lunch or an early dinner. Somehow we ended up having Japanese food again for lunch the following day at Sun with Moon restaurant.


A set lunch containing a mushroom fire pot, with unagi on rice



Hokkaido miso ramen set complete with corn and butter. Finally, good ramen!


Comes with these variant of gyoza as well

That ends the happy holidays for 2008/09. Oh well, back to work on Monday!