Skip to main content

Ralsina.Me — Roberto Alsina's website

Python-v4l: neat!

Think­ing about Cher­ryTV and ways to turn it in­to a re­al ap­pli­ca­tion, I thought the worse piece of it was the re­liance on v4lctl, and how re­al­ly you just don't know if it works or not, and how you can't fine­tune, and what­ev­er, and run in­to Python-v4l.

It has re­mained ap­par­ent­ly un­touched by two years, but I man­aged to build it with one ed­it and to make it work by switch­ing a line to an al­ter­nate ver­sion (they are both there), and it's nice.

Here's the ex­am­ple TV view­ing ap­pli­ca­tion us­ing it:

#!/usr/bin/env python
# Sample TV viewing application for pyv4l >= 0.3 - by Michael Dove
#<pythondeveloper@optushome.com.au>
# Note: this does the imaging in grab mode. Performance is limited.
# I average 35 fps @ 320x240. Disabling the writes to the tk window yeilds 90+ fps.

import v4l
import Image
import ImageChops
WIDTH = 320
HEIGHT = 240
vid = v4l.video('/dev/video')
cap = vid.getCapabilities()
print "Device Name: %s" % cap[0]
print "Type: %d" % cap[1]
print "Channels: %d" % cap[2]
print "Audios: %d" % cap[3]
print "Maximum Width: %d" % cap[4]
print "Maximum Height: %d" % cap[5]
print "Minimum Width: %d" % cap[6]
print "Minimum Height: %d" % cap[7]
vid.setupImage(WIDTH, HEIGHT, v4l.VIDEO_PALETTE_YUYV)
print vid.getChannel(0) # TV
vid.setChannel(0) # set to TV
vid.setFrequency(216250)

import Tkinter
tk=Tkinter.Tk()
import ImageTk
photo = ImageTk.PhotoImage("RGB",(WIDTH,HEIGHT))
label= Tkinter.Label(tk,text="mini TV",image=photo,width=WIDTH,height=HEIGHT)
label.pack()

vid.preQueueFrames()
nextFrame = 0;
vid.setVolume(5)
vid.mute()

try:
    while 1:
        output = vid.getImage(nextFrame)
        im = Image.fromstring("RGB", (WIDTH, HEIGHT), output)
        # update Tk label
        photo.paste(im)
        tk.update()
        nextFrame = vid.queueFrame()

except Tkinter.TclError:
    print "something"
    pass
vid.mute()

If you have seen the equiv­a­lent C ap­p... well... nice job here!

Daniel / 2006-05-20 22:44:

It's interesting you are trying to process the image internally - hence the FPS limit.

How about processing the channel change only, and just piping the image to a dedicated app, like Kaffeine?

I have a ivtv-based card, which outputs plain MP3 on /dev/video0. I coded a simple SuperKaramba applet for changing the channel (using ivtv-specific command-line app) and starting the Kaffaine with fifo://ved/video0. (Look for kataivtv on kde-look. I'll finish it some time after June 8th) That sure beats trying to process the video yourself.

Roberto Alsina / 2006-05-20 23:04:

I am streaming using vlc, and using python to switch channels via a web page (that's what python-v4l gives me).

This code is the example that comes with python-v4l, I just posted it because I was impressed by the simplicity.

manson54 / 2010-01-07 09:48:

Hi,

where did you found this v4l module
I can't seem to find it anywhere :(

manson54 / 2010-01-07 10:02:

nevermind, I found it :)
but what did you do to build it?

phone number lookup / 2011-12-03 22:39:

this is really interesting viewpoint on the subject i might add

employment background check / 2011-12-27 23:32:


Well, the write-up is truly the freshest on this laudable topic. 


Contents © 2000-2024 Roberto Alsina