Skip to content

Instantly share code, notes, and snippets.

@MathieuDuponchelle
Last active October 17, 2016 22:16
Show Gist options
  • Save MathieuDuponchelle/5736992 to your computer and use it in GitHub Desktop.
Save MathieuDuponchelle/5736992 to your computer and use it in GitHub Desktop.

Revisions

  1. MathieuDuponchelle revised this gist Feb 22, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions mixit.py
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ def createLayers(timeline, asset):
    for i in range(int(sys.argv[2])):
    layer = timeline.append_layer()
    clip = layer.add_asset(asset, i * Gst.SECOND * 0.3, 0, asset.get_duration(), GES.TrackType.UNKNOWN)
    for source in clip.get_children():
    for source in clip.get_children(False):
    if source.props.track_type == GES.TrackType.VIDEO:
    break

    @@ -58,8 +58,8 @@ def createLayers(timeline, asset):

    layer.add_asset(audio_asset, 0, 0, timeline.get_duration(), GES.TrackType.AUDIO)

    pipeline = GES.TimelinePipeline()
    pipeline.add_timeline(timeline)
    pipeline = GES.Pipeline()
    pipeline.set_timeline(timeline)

    container_profile = \
    GstPbutils.EncodingContainerProfile.new("pitivi-profile",
  2. MathieuDuponchelle revised this gist Jul 3, 2013. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions mixit.py
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,8 @@ def mylog(x):
    return (x / (1 + x))

    def createLayers(timeline, asset):
    alpha = 1.0
    step = 1.0 / int(sys.argv[2])
    alpha = step
    for i in range(int(sys.argv[2])):
    layer = timeline.append_layer()
    clip = layer.add_asset(asset, i * Gst.SECOND * 0.3, 0, asset.get_duration(), GES.TrackType.UNKNOWN)
    @@ -32,7 +33,7 @@ def createLayers(timeline, asset):
    break

    source.set_child_property("alpha", alpha)
    alpha = mylog(alpha)
    alpha += step

    if __name__ =="__main__":
    if len(sys.argv) < 4:
    @@ -51,6 +52,8 @@ def createLayers(timeline, asset):

    createLayers(timeline, asset)

    timeline.commit()

    layer = timeline.append_layer()

    layer.add_asset(audio_asset, 0, 0, timeline.get_duration(), GES.TrackType.AUDIO)
  3. MathieuDuponchelle revised this gist Jun 9, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions mixit.py
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,7 @@ def mylog(x):
    def createLayers(timeline, asset):
    alpha = 1.0
    for i in range(int(sys.argv[2])):
    layer = GES.Layer()
    timeline.add_layer(layer)
    layer = timeline.append_layer()
    clip = layer.add_asset(asset, i * Gst.SECOND * 0.3, 0, asset.get_duration(), GES.TrackType.UNKNOWN)
    for source in clip.get_children():
    if source.props.track_type == GES.TrackType.VIDEO:
  4. MathieuDuponchelle created this gist Jun 8, 2013.
    94 changes: 94 additions & 0 deletions mixit.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,94 @@
    from gi.repository import GstPbutils
    from gi.repository import Gtk
    from gi.repository import Gst
    from gi.repository import GES
    from gi.repository import GObject

    import sys
    import signal

    def handle_sigint(sig, frame):
    Gtk.main_quit()

    def busMessageCb(unused_bus, message):
    if message.type == Gst.MessageType.EOS:
    print "eos"
    Gtk.main_quit()

    def duration_querier(pipeline):
    print pipeline.query_position(Gst.Format.TIME)
    return True

    def mylog(x):
    return (x / (1 + x))

    def createLayers(timeline, asset):
    alpha = 1.0
    for i in range(int(sys.argv[2])):
    layer = GES.Layer()
    timeline.add_layer(layer)
    clip = layer.add_asset(asset, i * Gst.SECOND * 0.3, 0, asset.get_duration(), GES.TrackType.UNKNOWN)
    for source in clip.get_children():
    if source.props.track_type == GES.TrackType.VIDEO:
    break

    source.set_child_property("alpha", alpha)
    alpha = mylog(alpha)

    if __name__ =="__main__":
    if len(sys.argv) < 4:
    print "usage : " + sys.argv[0] + " file:///video/uri number_of_layers file:///audio/uri [file:///output_uri]"
    print "If you specify a output uri, the pipeline will get rendered"
    exit(0)

    GObject.threads_init()
    Gst.init(None)
    GES.init()

    timeline = GES.Timeline.new_audio_video()

    asset = GES.UriClipAsset.request_sync(sys.argv[1])
    audio_asset = GES.UriClipAsset.request_sync(sys.argv[3])

    createLayers(timeline, asset)

    layer = timeline.append_layer()

    layer.add_asset(audio_asset, 0, 0, timeline.get_duration(), GES.TrackType.AUDIO)

    pipeline = GES.TimelinePipeline()
    pipeline.add_timeline(timeline)

    container_profile = \
    GstPbutils.EncodingContainerProfile.new("pitivi-profile",
    "Pitivi encoding profile",
    Gst.Caps("video/webm"),
    None)

    video_profile = GstPbutils.EncodingVideoProfile.new(Gst.Caps("video/x-vp8"),
    None,
    Gst.Caps("video/x-raw"),
    0)

    container_profile.add_profile(video_profile)

    audio_profile = GstPbutils.EncodingAudioProfile.new(Gst.Caps("audio/x-vorbis"),
    None,
    Gst.Caps("audio/x-raw"),
    0)

    container_profile.add_profile(audio_profile)

    if len(sys.argv) > 4:
    pipeline.set_render_settings(sys.argv[4], container_profile)
    pipeline.set_mode(GES.PipelineFlags.RENDER)

    pipeline.set_state(Gst.State.PLAYING)

    bus = pipeline.get_bus()
    bus.add_signal_watch()
    bus.connect("message", busMessageCb)
    GObject.timeout_add(300, duration_querier, pipeline)

    signal.signal(signal.SIGINT, handle_sigint)
    Gtk.main()