Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. from gi.repository import Gst, GObject, GLib
  2. from gi.repository import GES
  3. from gi.repository import GstPbutils
  4.  
  5. import os, sys
  6. import argparse
  7.  
  8. class TextOverlayExample:
  9. def __init__ (self, args):
  10. self.__loop = GLib.MainLoop()
  11. self.__input = os.path.abspath(args.input)
  12. self.__output = os.path.abspath(args.output)
  13. self.__text = args.text
  14. self.__xpos = 0
  15. self.__ypos = 0
  16.  
  17. self.__pipeline = GES.Pipeline()
  18.  
  19. # setting up profile
  20. self.__container_profile = \
  21. GstPbutils.EncodingContainerProfile.new ("example-profile",
  22. "Text Overlay Profile",
  23. Gst.Caps.new_empty_simple ("video/quicktime"),
  24. None)
  25. self.__video_profile = \
  26. GstPbutils.EncodingVideoProfile.new (Gst.Caps.new_empty_simple("video/x-h264"),
  27. None,
  28. Gst.Caps.new_empty_simple("video/x-raw"),
  29. 0)
  30.  
  31. self.__container_profile.add_profile (self.__video_profile)
  32.  
  33. # building timeline
  34. self.__timeline = GES.Timeline.new ()
  35.  
  36. video_asset = GES.UriClipAsset.request_sync ("file://" + self.__input)
  37. layer = self.__timeline.append_layer ()
  38. layer.add_asset (video_asset, 0, 0, video_asset.get_duration(), GES.TrackType.VIDEO)
  39.  
  40. self.__pipeline.set_timeline (self.__timeline)
  41.  
  42. trackv = GES.VideoTrack.new()
  43. self.__timeline.add_track(trackv)
  44.  
  45.  
  46. # text overlay
  47. self.__textoverlayclip = GES.TextOverlayClip.new()
  48. self.__textoverlayclip.props.text = self.__text
  49. self.__textoverlayclip.props.xpos = self.__xpos
  50. self.__textoverlayclip.props.ypos = self.__ypos
  51. self.__textoverlayclip.props.font_desc = "Sans Italic 50"
  52. self.__textoverlayclip.props.start = 0
  53. #self.__textoverlayclip.props.in_point = 0
  54. self.__textoverlayclip.props.duration = video_asset.get_duration()
  55.  
  56. layer.add_clip (self.__textoverlayclip)
  57.  
  58. # setting render information
  59. self.__pipeline.set_render_settings ("file://" + self.__output, self.__container_profile)
  60. self.__pipeline.set_mode (GES.PipelineFlags.RENDER)
  61.  
  62. # normal pipeline handling
  63. self.__bus = self.__pipeline.get_bus()
  64. self.__bus.connect ("message", self.__bus_message_cb)
  65. self.__bus.add_signal_watch()
  66.  
  67. def run (self):
  68. self.__pipeline.set_state (Gst.State.PLAYING)
  69. self.__loop.run()
  70.  
  71. def __bus_message_cb (self, bus, message):
  72. msg = message.get_structure()
  73.  
  74. if message.type == Gst.MessageType.EOS:
  75. self.__loop.quit()
  76.  
  77. if message.type == Gst.MessageType.ERROR:
  78. print msg.to_string ()
  79. self.__loop.quit()
  80.  
  81.  
  82. if __name__ =="__main__":
  83. parser = argparse.ArgumentParser()
  84. parser.add_argument ("-i", "--input", action="store", dest="input",
  85. help="the input video file to be overlayed")
  86. parser.add_argument ("-o", "--output", action="store", dest="output",
  87. help="the output video file")
  88. parser.add_argument ("-t", "--text", action="store", dest="text",
  89. help="the input text to be overlayed")
  90.  
  91. args = parser.parse_args()
  92.  
  93. Gst.init(None)
  94. GES.init()
  95.  
  96. example = TextOverlayExample(args)
  97. example.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement