GStreamer Daemon - Gapless Playback: Difference between revisions
No edit summary |
mNo edit summary |
||
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{GStreamer Daemon/Head | previous=Simple Examples | next=MP4 Video Recording}} | ||
The Gapless Playback example will run a video from start to end sequentially in an infinite loop. To do so, it will wait for the file playback to finish before rewinding to the beginning of the file and restarting playback. The end of the playback is detected by polling the pipeline bus for the [https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstMessage.html#gst-message-new-eos End Of Stream (EOS) message], which is posted by the Filesrc element when all the content has been read. The rewinding is done by sending a [https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstEvent.html#gst-event-new-seek Seek event] to the pipeline, which effectively restarts the pipeline. | The Gapless Playback example will run a video from start to end sequentially in an infinite loop. To do so, it will wait for the file playback to finish before rewinding to the beginning of the file and restarting playback. The end of the playback is detected by polling the pipeline bus for the [https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstMessage.html#gst-message-new-eos End Of Stream (EOS) message], which is posted by the Filesrc element when all the content has been read. The rewinding is done by sending a [https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstEvent.html#gst-event-new-seek Seek event] to the pipeline, which effectively restarts the pipeline. | ||
== Example == | == Example for Gapless Playback == | ||
The following example is a bash script that demonstrates the simple gapless playback. | |||
<syntaxhighlight lang="bash" line='line'> | <syntaxhighlight lang="bash" line='line'> | ||
#!/bin/ | #!/bin/bash | ||
# Absolute path to the video location | # Absolute path to the video location | ||
VIDEO=$1 | VIDEO=$1 | ||
# Graceful cleanup upon CTRL-C | |||
trap "gstd-client pipeline_delete p; exit" SIGHUP SIGINT SIGTERM | |||
# Make sure there is no pipeline with this name already | |||
gstd-client pipeline_delete p | |||
gstd-client pipeline_create p playbin uri=file://$VIDEO | gstd-client pipeline_create p playbin uri=file://$VIDEO | ||
# Listen to the EOS messages | # Listen to the EOS messages | ||
gstd-client bus_filter eos | gstd-client bus_filter p eos | ||
gstd-client pipeline_play p | gstd-client pipeline_play p | ||
Line 21: | Line 29: | ||
while true; do | while true; do | ||
gstd-client bus_read p | gstd-client bus_read p | ||
gstd-client event_seek 1.0 | gstd-client event_seek p 1.0 | ||
done | done | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | To run the script you will need an existing video. You may use the [[Gstd-1.0 - MP4 Video Recording| video recording simple example]] to quickly use Gstd-1.0 to record one. To run the Gapless script type | ||
<syntaxhighlight lang="bash"> | |||
./simple-gapless-playback.sh /tmp/video.mp4 | |||
</syntaxhighlight> | |||
{{GStreamer Daemon/Foot | previous=Simple Examples | next=MP4 Video Recording}} |
Latest revision as of 18:18, 2 September 2020
The Gapless Playback example will run a video from start to end sequentially in an infinite loop. To do so, it will wait for the file playback to finish before rewinding to the beginning of the file and restarting playback. The end of the playback is detected by polling the pipeline bus for the End Of Stream (EOS) message, which is posted by the Filesrc element when all the content has been read. The rewinding is done by sending a Seek event to the pipeline, which effectively restarts the pipeline.
Example for Gapless Playback
The following example is a bash script that demonstrates the simple gapless playback.
#!/bin/bash # Absolute path to the video location VIDEO=$1 # Graceful cleanup upon CTRL-C trap "gstd-client pipeline_delete p; exit" SIGHUP SIGINT SIGTERM # Make sure there is no pipeline with this name already gstd-client pipeline_delete p gstd-client pipeline_create p playbin uri=file://$VIDEO # Listen to the EOS messages gstd-client bus_filter p eos gstd-client pipeline_play p # Wait for the message to perform seek while true; do gstd-client bus_read p gstd-client event_seek p 1.0 done
To run the script you will need an existing video. You may use the video recording simple example to quickly use Gstd-1.0 to record one. To run the Gapless script type
./simple-gapless-playback.sh /tmp/video.mp4