Commit c786a835 authored by Vimalan Reddy's avatar Vimalan Reddy

Update examples/tutorials/python/basic-tutorial-2.py

parent d6145916
Pipeline #250086 passed with stages
in 21 minutes and 37 seconds
#!/usr/bin/env python3
import sys
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
# Define required variables
pipeline = None
source = None
sink = None
bus = None
msg = None
error = None
debug_info = None
state_change = None
# Initialize GStreamer
Gst.init(sys.argv[1:])
# Build the pipeline
source = Gst.ElementFactory.make("videotestsrc", "source")
sink = Gst.ElementFactory.make("autovideosink", "sink")
pipeline = Gst.Pipeline.new("test-pipeline")
if (not pipeline or not source or not sink):
print("Not all elements could be created.")
sys.exit(-1)
pipeline.add(source)
pipeline.add(sink)
if (source.link(sink) != True):
print("Elements could not be linked.")
pipeline.set_state(Gst.State.NULL)
sys.exit(-1)
# Modify the source's pattern property
source.props.pattern = 0
# Start playing
state_change = pipeline.set_state(Gst.State.PLAYING)
if (state_change == Gst.StateChangeReturn.FAILURE):
print ("Unable to set the pipeline to the playing state.\n");
pipeline.set_state(Gst.State.NULL)
sys.exit(-1)
# Wait until EOS or error
bus = pipeline.get_bus()
msg = bus.timed_pop_filtered(
Gst.CLOCK_TIME_NONE,
Gst.MessageType.ERROR | Gst.MessageType.EOS
)
# Parse message
if (msg != None):
error, debug_info = msg.parse_error()
if (msg.type == Gst.MessageType.ERROR):
print(
"Error received from element {}: {}".format(
msg.src.name, error.message
)
)
print(
"Debugging information: {}".format(
"none" if debug_info else debug_info
)
)
error = None
debug_info = None
elif (msg.type == Gst.MessageType.EOS):
print("End-Of-Stream reached.")
else:
# We should not reach here because we only asked for ERRORs and EOS
print("Unexpected message received.")
# Free resources
pipeline.set_state(Gst.State.NULL)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment