Created
April 16, 2010 08:45
-
-
Save yuvipanda/368176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prototype code - Messy, Undocumented and Will crash at some point | |
// Pipeline: fakevideosrc -> (effects loaded from the files specified in commandline) -> ogg output | |
// Compile: valac --pkg gstreamer-0.10 --pkg gee-1.0 effects.vala | |
// Run: ./effects output.ogg noir.effect warptv.effect | |
// Author: Yuvi Panda (me@yuvi.in) | |
using Gst; | |
using GLib; | |
using Gee; | |
public const string VIDEO_EFFECT_GROUP_NAME = "VideoEffects"; | |
public class Effect : GLib.Object | |
{ | |
public string name {get; private set; } | |
public string bin_description {get; private set; } | |
public Bin bin {get; private set; } | |
public Effect (string file_name) | |
{ | |
var key_file = new KeyFile(); | |
key_file.load_from_file(file_name, KeyFileFlags.NONE); | |
this.name = key_file.get_string(VIDEO_EFFECT_GROUP_NAME, "Name"); | |
this.bin_description = key_file.get_string(VIDEO_EFFECT_GROUP_NAME, "BinDescription"); | |
this.bin = Gst.parse_bin_from_description(this.bin_description, true) as Bin; | |
} | |
} | |
void link_effects(Bin a, Bin b, Pipeline p) | |
{ | |
if (a.get_pad("src").get_caps().can_intersect(b.get_pad("sink").get_caps())) | |
{ | |
a.link(b); | |
} | |
else | |
{ | |
Element ffmpeg = Gst.ElementFactory.make("ffmpegcolorspace", null); | |
p.add(ffmpeg); | |
a.link(ffmpeg); | |
ffmpeg.link(b); | |
} | |
} | |
MainLoop loop; | |
Pipeline pipeline_from_effects(ArrayList<Effect> effects) | |
{ | |
var pipeline = new Pipeline("pipeline"); | |
pipeline.add(effects[0].bin); | |
for(int i=1; i<effects.size; i++) | |
{ | |
Bin prev = effects[i-1].bin; | |
Bin next = effects[i].bin; | |
pipeline.add(next); | |
link_effects(prev, next, pipeline); | |
} | |
return pipeline; | |
} | |
private bool bus_callback(Bus bus, Message message) | |
{ | |
switch(message.type) | |
{ | |
case MessageType.ERROR: | |
GLib.Error err; | |
string debug; | |
message.parse_error(out err, out debug); | |
stdout.printf("Error: %s\n, Debug: %s", err.message, debug); | |
loop.quit(); | |
break; | |
case MessageType.EOS: | |
stdout.printf("End of Stream\n"); | |
break; | |
default: | |
break; | |
} | |
return true; | |
} | |
static int main(string[] argv) | |
{ | |
Gst.init(ref argv); | |
if (argv.length == 1) | |
{ | |
stdout.printf("Usage: effects <outputfile> <effectfile1> <effectfile2> <effectfile3> ...\n"); | |
return 0; | |
} | |
loop = new MainLoop(null, false); | |
var effects = new ArrayList<Effect> (); | |
for (var i=2; i<argv.length; i++) | |
{ | |
effects.add(new Effect(argv[i])); | |
} | |
var p = pipeline_from_effects(effects); | |
Bus bus = p.get_bus(); | |
bus.add_watch(bus_callback); | |
var output_file = argv[1]; | |
var src = Gst.parse_bin_from_description("videotestsrc", true) as Bin; | |
var sink = Gst.parse_bin_from_description("theoraenc ! oggmux ! filesink location=" + output_file, true) as Bin; | |
p.add(src); | |
p.add(sink); | |
link_effects(src, effects[0].bin, p); | |
link_effects(effects[effects.size-1].bin, sink, p); | |
p.set_state(State.PLAYING); | |
loop.run(); | |
p.set_state(State.NULL); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[VideoEffects] | |
Name=Noir | |
Author=Yuvi | |
BinDescription=videobalance saturation=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[VideoEffects] | |
Name=WarpTv | |
Author=Yuvi | |
BinDescription=warptv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment