Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from gi.repository import Gst, GObject, GLib
- from gi.repository import GES
- from gi.repository import GstPbutils
- import os, sys
- import argparse
- class TextOverlayExample:
- def __init__ (self, args):
- self.__loop = GLib.MainLoop()
- self.__input = os.path.abspath(args.input)
- self.__output = os.path.abspath(args.output)
- self.__text = args.text
- self.__xpos = 0
- self.__ypos = 0
- self.__pipeline = GES.Pipeline()
- # setting up profile
- self.__container_profile = \
- GstPbutils.EncodingContainerProfile.new ("example-profile",
- "Text Overlay Profile",
- Gst.Caps.new_empty_simple ("video/quicktime"),
- None)
- self.__video_profile = \
- GstPbutils.EncodingVideoProfile.new (Gst.Caps.new_empty_simple("video/x-h264"),
- None,
- Gst.Caps.new_empty_simple("video/x-raw"),
- 0)
- self.__container_profile.add_profile (self.__video_profile)
- # building timeline
- self.__timeline = GES.Timeline.new ()
- video_asset = GES.UriClipAsset.request_sync ("file://" + self.__input)
- layer = self.__timeline.append_layer ()
- layer.add_asset (video_asset, 0, 0, video_asset.get_duration(), GES.TrackType.VIDEO)
- self.__pipeline.set_timeline (self.__timeline)
- trackv = GES.VideoTrack.new()
- self.__timeline.add_track(trackv)
- # text overlay
- self.__textoverlayclip = GES.TextOverlayClip.new()
- self.__textoverlayclip.props.text = self.__text
- self.__textoverlayclip.props.xpos = self.__xpos
- self.__textoverlayclip.props.ypos = self.__ypos
- self.__textoverlayclip.props.font_desc = "Sans Italic 50"
- self.__textoverlayclip.props.start = 0
- #self.__textoverlayclip.props.in_point = 0
- self.__textoverlayclip.props.duration = video_asset.get_duration()
- layer.add_clip (self.__textoverlayclip)
- # setting render information
- self.__pipeline.set_render_settings ("file://" + self.__output, self.__container_profile)
- self.__pipeline.set_mode (GES.PipelineFlags.RENDER)
- # normal pipeline handling
- self.__bus = self.__pipeline.get_bus()
- self.__bus.connect ("message", self.__bus_message_cb)
- self.__bus.add_signal_watch()
- def run (self):
- self.__pipeline.set_state (Gst.State.PLAYING)
- self.__loop.run()
- def __bus_message_cb (self, bus, message):
- msg = message.get_structure()
- if message.type == Gst.MessageType.EOS:
- self.__loop.quit()
- if message.type == Gst.MessageType.ERROR:
- print msg.to_string ()
- self.__loop.quit()
- if __name__ =="__main__":
- parser = argparse.ArgumentParser()
- parser.add_argument ("-i", "--input", action="store", dest="input",
- help="the input video file to be overlayed")
- parser.add_argument ("-o", "--output", action="store", dest="output",
- help="the output video file")
- parser.add_argument ("-t", "--text", action="store", dest="text",
- help="the input text to be overlayed")
- args = parser.parse_args()
- Gst.init(None)
- GES.init()
- example = TextOverlayExample(args)
- example.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement