from gi.repository import Gtk, Gdk, Clutter, GtkClutter, Gst

gst_source_description = "v4l2src device=/dev/video0 ! " + \
    "queue ! " + \
    "video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! " + \
    "videoflip method=horizontal-flip"

Gst.init([])
GtkClutter.init([])

window = Gtk.Window()
window.connect("destroy", Gtk.main_quit)

embed = GtkClutter.Embed()
window.add(embed)

stage = embed.get_stage()
video_texture = Clutter.Texture()
stage.add_actor(video_texture)

source = Gst.parse_bin_from_description(
    gst_source_description,
    True
)

wrapper = Gst.ElementFactory.make("wrappercamerabinsrc", "wrapper")
wrapper.set_property("video-source", source)

camerabin = Gst.ElementFactory.make("camerabin", "camera")
camerabin.set_property("camera-source", wrapper)

sink = Gst.ElementFactory.make("cluttersink", "videosink")
sink.set_property("texture", video_texture)

camerabin.set_property("viewfinder-sink", sink)

camerabin.set_state(Gst.State.PLAYING)
camerabin.emit("start-capture")

window.show_all()
Gtk.main()
