Skip to content

Instantly share code, notes, and snippets.

@yuvipanda
Created April 14, 2010 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuvipanda/365671 to your computer and use it in GitHub Desktop.
Save yuvipanda/365671 to your computer and use it in GitHub Desktop.
# PROTOTYPE CODE
# ANYONE USING THIS WILL BE SHOT
import sys
import time
from ConfigParser import SafeConfigParser
import pygst
pygst.require("0.10")
import gst
"""
SECTION_NAME = "DEFAULT"
class Effect:
def __init__(self, filename):
cp = SafeConfigParser()
cp.read(filename)
self.name = cp.get(SECTION_NAME, "Name")
self.author = cp.get(SECTION_NAME, "Author")
self.pipeline = cp.get(SECTION_NAME, "Pipeline")
self.colorspace = cp.get(SECTION_NAME, "Colorspace")
"""
player = gst.Pipeline("player")
cam = gst.parse_bin_from_description("v4l2src", True)
sink = gst.element_factory_make("autovideosink", "viewer")
player.add(cam, sink)
gst.element_link_many(cam, sink)
player.set_state(gst.STATE_PLAYING)
effects = [cam, sink]
def link_with_colorspace(a, b):
try:
a.link(b)
except gst.LinkError:
ffmpeg = gst.parse_bin_from_description("ffmpegcolorspace", True)
a.add(ffmpeg)
ghostpad = gst.GhostPad("src", ffmpeg.get_pad("src"))
a.link(ffmpeg)
ffmpeg.link(b)
def insert_at(bin, pos):
prev = effects[pos-1]
next = effects[pos]
effects.insert( pos, bin)
prev.unlink(next)
link_with_colorspace(prev, bin)
link_with_colorspace(bin, next)
effect = gst.parse_bin_from_description("warptv", True)
player.add(effect)
player.set_state(gst.STATE_PAUSED)
insert_at(effect, 1)
player.set_state(gst.STATE_PLAYING)
if __name__ == "__main__":
while True:
raw_input()
"""
while True:
file_name = raw_input("File to load: ")
effect = Effect(file_name)
bin_desc = effect.pipeline
if effects:
if effect.colorspace != effects[-1].colorspace:
bin_desc = "ffmpegcolorspace ! " + bin_desc
else:
bin_desc = "ffmpegcolorspace ! " + bin_desc + " ! ffmpegcolorspace"
bin = gst.parse_bin_from_description(bin_desc, True)
effect.bin = bin
player.set_state(gst.STATE_PAUSED)
player.add(bin)
if effects:
gst.element_unlink_many(effects[-1].bin, sink)
gst.element_link_many(effects[-1].bin, effect.bin, sink)
else:
gst.element_unlink_many(cam, sink)
gst.element_link_many(cam, effect.bin, sink)
player.set_state(gst.STATE_PLAYING)
effects.append(effect)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment