I am new to gstreamer and trying to use it for some GPU accelerated video decoding on my NVIDIA Jetson ARM based board. I found some python code online which creates a gstreamer pipeline and I was trying to use it to familiarize myself. The code that creates the pipeline is as follows:
def new_pipeline(self, mediauri):
pipeline = Gst.Pipeline()
if (not pipeline):
print ('Failed to create pipeline')
exit (-1)
# Create bus to get events from GStreamer pipeline
bus = pipeline.get_bus()
self.bus.append(bus)
bus.add_signal_watch()
bus.connect('message::error', self.on_error)
# This is needed to make the video output in our DrawingArea:
bus.enable_sync_message_emission()
bus.connect('sync-message::element', self.on_sync_message)
# Create GStreamer elements
decodebin = Gst.ElementFactory.make('uridecodebin', 'decodebin')
videosink = Gst.ElementFactory.make('nveglglessink', 'videosink')
if (not decodebin or not videosink):
print ('Failed to create uridecodebin and/or nveglglessink')
exit(-1)
# Set properties
decodebin.set_property('uri', mediauri)
videosink.set_property('create-window', False)
# Add elements to the pipeline
pipeline.add(decodebin)
pipeline.add(videosink)
decodebin.connect("pad-added", self.decodebin_pad_added)
return pipeline
The full project can be found here (https://github.com/kulve/gst-multiwindow)
Now, whenever I try to create a pipeline from a local file I get the error:
on_error(): (GError('Invalid URI "testfile.avi".',), 'gsturidecodebin.c(1373): gen_source_element (): /GstPipeline:pipeline0/GstURIDecodeBin:decodebin')
I have a feeling this error is because a local file is not a valid uri. I tried passing it as file://testfile.avi
but that did not work either returning could not open resource for reading
error.
Is there a change in this code that may help me play local video files?
Playbin is a GstPipeline. It will notify the application of everything that's happening (errors, end of stream, tags found, state changes, etc.) by posting messages on its GstBus. The application needs to watch the bus. Playback can be initiated by setting the element to PLAYING state using gst_element_set_state() .
gst-launch-1.0 is a tool that builds and runs basic GStreamer pipelines. In simple form, a PIPELINE-DESCRIPTION is a list of elements separated by exclamation marks (!). Properties may be appended to elements, in the form property=value.
The file/URI to play should be set via the “uri” property. This must be an absolute URI, relative file paths are not allowed.
Ex:
The file.avi is in /home/user/Downloads, then:
uri=file:///home/user/Downloads/file.avi
URI Must be starts with URI Tag, like http, tcp, rtsp, file. and then : and at the end Location of the resource.
For Ex : for file /home/Desktop/a.avi
URI : file:/home/Desktop/a.avi
For RTSP,
URI : rtsp://<IP>:<PORT>/<PATH>
ex: rtsp://192.168.1.1/test
You are only giving the file name as input. The URI property takes standard URI's as input. Moreover only reletive URI's are not supported for uridecodebin. The correct URI is like:
file://localhost/absolute/path/to/file
or if you want to remove the host name (note the additional slash):
file:///absolute/path/to/file
Some parsers are intelligent enough to parse relative paths as well (uridecodebin doesn't support this). In your case it could've been specified as:
file:./testfile.avi
For more details about the File URI scheme.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With