from gi.repository import Gst
from gi.repository import GObject
from gi.repository import GLib

p = Gst.parse_launch("v4l2src name=src device=/dev/video1 ! video/x-raw, width=640, height=480 ! xvimagesink")

print p

p.set_state(Gst.State.PLAYING)
src = p.get_by_name("src")

running = True

def restart():
    src.set_state(Gst.State.NULL)
    src.set_state(Gst.State.PLAYING)
    print "restarted"

GLib.timeout_add(1000, restart)

loop = GLib.MainLoop()
loop.run()

