Capturing Streaming Video Using DCOP + Xine
This morning, the Vice Counselor of my university was interviewed on tv. No one is recording the event and I did not notice about it until it is aired. It will be nice if I can always capable of recording such memorable event. Therefore, I began to write a script that can help me to do a scheduled recording.
From the Internet, I notice that this can be done using mencoder or FFMpeg. However due to some circumstances I can’t use these tools on my PC. That leave me no choice but to use xine.
Xine on my desktop is fine enough to capture the shows on tv but the problem is I could not find any way to schedule the recording using GUI. As time pass, the problems reminds me about my favorite command in past, DCOP!!!
I used to play text based games using DCOP. Actually the idea is not to play games but to learn bash scripting. Learning process made me bored. Therefore, I thought, I need a project that could keep me motivated during the process. So I made a robot that could help me to play games without really touch the game daily. So that was the moment I enjoys using DCOP and the fun of scripting began.
However, the fun with DCOP is not long. I learned Python after that and Python made me completely abandon my old friend. Python is too efficient, as I can reduce my scripts errors almost to zero.
Now, due to the challenge i face, the DCOP is coming again to help me (actually I did not have enough time to do research on doing this using Python).
The idea of the script is to get the video capture done from command line and be scheduled using cron/at. I am using dcop and kmplayer as the GUI for xine. Below is the steps I did to get the recording done:
- get kmplayer process ID
$ dcop | grep kmplayer
- get the kxineplayer process ID
$ dcop kmplayer-10963 kmplayer-mainwindow#1 getWinID
- give the kmplayer the appropriate url
$ dcop kmplayer-10963 KMediaPlayer openURL \ http://www.um.com.my/tv_channels/malaysia/rtm1.asx
- record it using kxineplayer
$ kxineplayer -wid 14680071 -f ‘/home/fadli/.kde/share/apps/kmplayer/xine_config’ -vo xv,sdl,x11 -ao alsa -cb kmplayer-10963/KMPlayerCallback-0 -rec ‘/home/fadli/test.avi’
Sound easy, right? but the challenge is not over yet. What I have done is just to record the video. What I need is a program that are able to be scheduled. Em… well just put all the previous commands into a file. Add some chili sauces and ketchup. A little salt will make it more tasty. Also some sugar. 30 minutes baked in oven should be fine. Finally make the file executable using chmod. Now, it is ready to be served and yummy!
This is what I have in the script:
# Getting IDs
PID=`dcop | grep kmplayer`
if [ -e $PID ] ; then
echo Starting KMPLAYER…
nohup kmplayer &
PID=`dcop | grep kmplayer`
echo KMPLAYER already started.
WID=`dcop $PID kmplayer-mainwindow#1 getWinID`
dcop $PID KMediaPlayer openURL $SRC
echo killall kxineplayer | at now + $TIME minutes
kxineplayer -wid $WID -f ‘/home/fadli/.kde/share/apps/kmplayer/xine_config’ -vo xv,sdl,x11 -ao alsa -cb $PID/KMPlayerCallback-0 -rec $OUTPUT
And finally, put it up on schedule using cron or at.
Powered by ScribeFire.