mycroes

There's always time to play

Wednesday, June 18, 2008

gstreamer television recording

I've been trying to record stuff from my tv tuner card using gstreamer. I like gstreamer as a multimedia framework and I like some apps that use it, so although there are enough other options I wanted to try this using gstreamer first.

The first issue was to record something from the tv card. I started by installing the video4linux gstreamer plugin. I actually started with installing version 1, then noticed there was a version 2 and because that's what the kernel uses natively I decided to go for v4l2. The gstreamer plugin is called v4l2src. I already read that to display something you need to run it through ffmpegcolorspace. To get it more useful you also need to specify resolution and framerate so to get something useful on my screen I started with
gst-launch-0.10 v4l2src device=/dev/video0 ! \
video/x-raw-yuv,width=768,height=520,framerate=\(fraction\)30000/1001 ! \
ffmpegcolorspace ! ximagesink

This works, but you still need to control the tv card or else you'll probably just see snow. There's a few different ways to control the tv card, but I wanted something as small as possible because I only needed to change the frequency to a desired frequency. I found dov4l, a small program that can do all the basic stuff that I needed done. To switch to discovery channel I could do a simple
./dov4l -f 496000000
from the folder where I unpacked the dov4l sources after I ran make. So now I actually had discovery channel displaying on my computer screen. Next step was audio. I use a bt878 tv card so I can use snd_bt87x to capture audio from the tuner device. A simple
gst-launch-0.10 alsasrc device=hw:1,0 ! alsasink
gave sound, so now I had audio and video from my tv card.

Now the hardest part was to get it all into a file. I'd seen various websites explaining some simple gstreamer stuff, and that at least taught me about muxing and demuxing. Actually, I didn't know much about the basics either. In short you usually want to encode video into something, encode audio into something and then dump it into a media container. So one common media container everyone knows is the avi format. I actually started out with ogg (vorbis and theora in an ogg container), but that gave me issues with both picture and sound so I soon moved to lame to convert my audio into mp3 and used ffenc_mpeg4 to convert my video into mpeg4. Dumping that into an avi container I ran into audio sync issues. After asking in #gstreamer on freenode I was told that the avi container doesn't handle time very well (or at all), so I should use another container and they pointed me to matroska. At this moment I was able to record to a file and view it afterwards, but that was not enough for me...

I wanted to use something modern. Although I quite like matroska containers because they're quite well supported on all platforms (vlc supports them, so any platform that supports vlc can in some way handle them) I was looking more for something like mp4. ffmpeg offers a muxing plugin for mp4, but I haven't gotten it to also use audio and I can only play it with mplayer then, so that's not really an option. I could however use something else in the matroska container. So I decided to use x264 for video. I'm on gentoo so I prefer to install by using ebuilds (although I'm using paludis so importare works for me too), so I went looking for an ebuild. The easy solution is to copy an existing gst-plugins-bad plugin ebuild (like the lame ebuild) and name it gst-plugins-x264-0.10.6.ebuild and place it in a correctly named folder in an overlay. Remove the deps that don't make sense (only lame for this specific plugin) and you should be able to install the plugin. I first tried with -0.10.7, but that wants gstreamer-0.10.19, so I decided to stick with gst-plugins-x264-0.10.6. Now I also needed something decent for audio, and I decided to go for faac, which seems to be reasonably supported these days and I ended up with the following line to do nice gstreamer recording from my tv card:
gst-launch-0.10 matroskamux name=mux ! \
filesink location=test.mkv alsasrc device=hw:1,0 ! \
audio/x-raw-int,channels=2,rate=32000,depth=16 ! \
audioconvert ! faac ! queue ! \
mux. v4l2src device=/dev/video0 ! \
video/x-raw-yuv,width=768,height=520,framerate=\(fraction\)30000/1001 ! \
ffmpegcolorspace ! x264enc ! queue ! mux.

I started with a capture resolution of 924x576, because that's what my card supports, but x264enc doesn't like that. Besides the fact that it complains that it can't encode fast when the width or height is not a multiple of 16 it wasn't properly encoding on that resolution. So as you can see I dropped it to 768x520, which gives a very decent picture, even for full screen viewing. Have fun watching!

Thursday, June 5, 2008

Ripping audio from youtube movies (using gstreamer)

Today my girlfriend needed the audio from a youtube clip, so I decided to see how easy I could get it. I started by getting the flv from the clip, one useful source for that is downloadflv.com. After I had the file I verified I could actually play it, double clicking opened totem and started playing, so far so good.

Because totem managed to play I thought gstreamer should be able to open the file and I already knew gstreamer was capable of converting and after about 3 tries I came up with the following command:
gst-launch-0.10 filesrc location=file.flv ! decodebin ! audioconvert ! lame ! filesink location=file.mp3

This
- opens the file
- decodes the file (I guess this is needed to rip audio only)
- does something with audio, I don't know if you always need this but I think this is a sort of wrapper to match input with output plugins
- encodes to mp3 audio
- writes to a file

There's much more you can do with gstreamer, so if you found another one of those 'this might be useful every once or twice in five years' commands please let me know in comments.

Wednesday, June 4, 2008

How to get google gadgets to get gadget metadata

So it seems that now google gadgets for linux has been announced a lot of people want to try it. Seems most of them are retarded too and can't get it working. Because I have nothing against retarded people I'm going to list what I've found out:
- The error "Failed to update gadget metadata" can mean a couple of things.
- Curl needs to use openssl for cryptography to work with ggl.
- On gentoo you seem to need recent ca-certificates. In my case, upgrading from amd64 to ~amd64 worked.
- a simple `curl https://desktop.google.com/desktop` can show you why ggl can't fetch metadata.

I hope someone reads this and thinks it's useful, please leave a comment if so.

Wednesday, December 12, 2007

ubuntu-desktop meta-package

Sometimes you're looking for something, could be a word, package name or whatever. You're so close, but still you can't remember. That is, until you worked around `the problem' and you suddenly remember what it was. Now I for one had to install ubuntu using an alternative method. I don't know why, but ubuntu (7.10) wouldn't properly boot off the cd. All I got was a busybox shell, not something I'm really happy with. So I decided I'd try some other liveCDs from other distros and because I'm a long-time Gentoo user I decided I'd first see if the Gentoo liveCDs work and when they did I decided to try archLinux. I never used it before or anything, but I remember that archLinux is based on Gentoo... I might very well be wrong, but that seems to has gotten stuck in my brain. So I dled archlinux, it booted fine, was able to run the installer, but couldn't mount the cd, so I dropped archLinux and decided to try to install ubuntu in another way (I wanted the machine to be up and running within a day or so, and wasn't willing to spent some hours doing it the gentoo way). So I found directions to install Ubuntu dapper using debootstrap. Worked quite well for feisty too (yes I know, gutsy is newer, just overlooked it), so I had feisty up and running, but no X or anything. Now I know my way on the terminal, but I wanted to see how well this box would do as a Playstation One emulator. And then I came to the problem I started this post with. I remembered there was some meta-package that would give me gnome and all, so I started searching for gnome metapackages. There was something like gnome-environment or whatever, when I installed it I still had no X. So I installed X (by installing Xorg) and then I noticed an error when I started GDM, stating that it couldn't find the human theme. And as soon as I logged in I remembered; the meta-package is called ubuntu-desktop.

Sunday, August 5, 2007

Synergy when you need it

Perhaps some of you people have already heard about synergy. For those of you who haven't heard about it before, synergy allows you to share one keyboard and mouse between multiple computers. Synergy works on *nix and windows, that'll do for most people. When I bought my Mac Mini I decided that I'd hook up my Razer Diamondback to it, and I also bought an apple (wired) keyboard with my Mac Mini so the mini was going to be my synergy server.

From that point there's just 2 problems left to solve. The first is, how to connect to the synergy server. You need to specify an hostname or ip-address to connect to the server, so there's an easy solution: avahi/bonjour/rendezvouz/zeroconf. OS X supports bonour out of the box. Just give your Mac a nice name and you'll be able to reach it at .local. Mine's called Mini, so I can reach it at mini.local. Now the clients need bonjour support, which you can get with avahi. Ubuntu includes avahi by default, so if you're on ubuntu there's no extra work involved. I'm more of a Gentoo user though, and if you're on Gentoo you can just get Avahi from portage. Read the comments while it's emerging, they'll tell how to enable hostname resolving.

The first problem's solved. The second problem is how to start synergy. On your Mac you can get SynergyKM: Synergy and a nice GUI in one package. It'll add a system preferences item for synergy where you can change everything you'll ever need for synergy. On the clients I added synergy to the Gnome session startup programs. Now when you log in they'll start. This leaves part of this problem unsolved, how do you log in? The solution is quite simple. If you use GDM there's a /etc/[X11/]gdm/Init/Default, which can also be used to execute extra commands. Just add a line synergyc mini.local before the exit statement (replace mini.local with your synergy server hostname of course) and you'll be able to log in using synergy. So now all you need is one keyboard and one mouse to control your 5 computers ;-)

Saturday, August 4, 2007

Mac and Myth

It's been a while since I've posted anything here, actually it's been a while since I've really done anything online other then reading... Anyway, this is the place to tell everyone I also own a Mac now (Mac Mini/Core Solo/512MB/60GB/Combodrive). Some people immediately scream that you should buy a Mac if you like stuff like AWN, but I still don't agree. Don't get me wrong, I love my Mac, but it's not all there is. I now have my 'old' computer as a home-theatre PC, recording tv shows and stuff, it works great except that now that I came back from my holiday I noticed it didn't fetch tv guide information so it didn't record everyhting it should've recorded. Other than that I hope to post here a little more often, and some more useful stuff too...

Sunday, May 20, 2007

Don't you, forget about me...

The title was this time sung by the nptl useflag. On a new Gentoo server install I set -* and forgot about nptl and nptl-only for glibc, so glibc was build with linuxthreads instead of nptl. Not much of a problem you probably think, but there seems to be some bug in mysql that when running on amd64 with linuxthreads it just won't stop... Killing by hand won't stop mysql either, unless I use -9. So from now on I'll remember to put nptl and nptl-only in my useflags...