Created
July 7, 2015 18:48
-
-
Save sampsyo/7121923bb6acc8298600 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
from __future__ import print_function | |
import sys | |
import os | |
import gi | |
gi.require_version('Gst', '1.0') | |
from gi.repository import GObject, Gst | |
def on_message(bus, message, udata): | |
pipeline, loop = udata | |
if message.type == Gst.MessageType.EOS: | |
pipeline.set_state(Gst.State.NULL) | |
loop.quit() | |
elif message.type == Gst.MessageType.ERROR: | |
print(message.parse_error()) | |
pipeline.set_state(Gst.State.NULL) | |
loop.quit() | |
return True | |
def on_pad_added(element, pad, udata): | |
pipeline, sink = udata | |
pad.link(sink.get_static_pad('sink')) | |
# Get the duration of the source file. | |
duration, success = pad.query_duration(Gst.Format.TIME) | |
print(duration, success) | |
def decode(input_file): | |
loop = GObject.MainLoop() | |
pipeline = Gst.Pipeline() | |
uridecodebin = Gst.ElementFactory.make('uridecodebin') | |
sink = Gst.ElementFactory.make('fakesink') | |
pipeline.add(uridecodebin) | |
pipeline.add(sink) | |
uridecodebin.link(sink) | |
uridecodebin.set_property('uri', input_file) | |
uridecodebin.connect('pad-added', on_pad_added, (pipeline, sink)) | |
bus = pipeline.get_bus() | |
bus.add_watch(0, on_message, (pipeline, loop)) | |
pipeline.set_state(Gst.State.PLAYING) | |
print(pipeline.get_state(100000000)) | |
duration, success = uridecodebin.query_duration(Gst.Format.TIME) | |
print(duration, success) | |
loop.run() | |
if __name__ == '__main__': | |
Gst.init() | |
input_file = 'file://' + os.path.abspath(sys.argv[1]) | |
decode(input_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment