GStreamer pre-record element - Examples - PreRecord

From RidgeRun Developer Wiki



Previous: Examples Index Next: Examples/PreRecordSink





PreRecord example pipelines

To test the prerecord GStreamer element is necessary to change the buffering property while the pipeline is running, thus gst-launch is not the correct application to test the element.

An easy way to evaluate the functionality of prerecord GStreamer element is using GStreamer Daemon, a GStreamer framework developed by RidgeRun that allows the user to control pipeline states and element properties.

You can install Gstd and run the following examples:

Video pre-recording example

The following script is an example where the pipeline will encode video streaming to h264 to a file and the pre-record element will be pre-recording with a buf-time of 5 seconds. After 10 seconds the video pattern will change from ball to snow and the pre-record will pass the buffer data downstream.

#!/bin/bash

# Pipeline definition
gstd-client pipeline_create p1 videotestsrc is-live=true name=src pattern=ball ! x264enc speed-preset=ultrafast key-int-max=30 ! prerecord buf-time=5000 buffering=true on-key-frame=true name=prerecord ! queue ! mpegtsmux name=mux ! filesink location=test_x264.ts qos=false sync=false async=false

# Run pipeline
gstd-client pipeline_play p1

# After 10 seconds, change video pattern
sleep 10
gstd-client element_set p1 src pattern snow

# Allow buffer data to pass downstream 
gstd-client element_set p1 prerecord buffering false

# Stop the pipeline after 10 seconds
sleep 10
gstd-client pipeline_stop p1

# Delete pipeline
gstd-client pipeline_delete p1

To run the example, copy the script on a file (prerecord-video.sh), and follow the next steps:

sudo chmod 777 prerecord-video.sh
gstd &
./prerecord-video.sh

Then you can observe the recorded video with vlc for example.

Video+Audio pre-recording example

The following script is an example where the pipeline will encode video streaming to h264 and audio streaming to AAC and the pre-record element will be pre-recording with a buf-time of 5 seconds. After 10 seconds the video pattern will change from ball to snow and the pre-record will pass the buffer data downstream.

#!/bin/bash

# Pipeline definition
gstd-client pipeline_create p1 videotestsrc is-live=true name=src pattern=ball ! x264enc speed-preset=ultrafast key-int-max=30 ! prerecord buf-time=5000 buffering=true on-key-frame=true name=prerecord ! queue ! mpegtsmux name=mux ! filesink location=test_x264.ts qos=false sync=false async=false audiotestsrc is-live=true name=au ! opusenc ! prerecord. prerecord. ! queue ! mux.

# Run pipeline
gstd-client pipeline_play p1

# After 10 seconds, change video pattern and audio wave 
sleep 10
gstd-client element_set p1 src pattern snow
gstd-client element_set p1 au wave 5

# Allow buffer data to pass downstream 
gstd-client element_set p1 prerecord buffering false

# Stop the pipeline after 10 seconds
sleep 10
gstd-client event_eos p1
gstd-client pipeline_stop p1

# Delete pipeline
gstd-client pipeline_delete p1

Run the example in the same way as the first one and observe the result.

Example pipeline using filesrc

This is another example that you can use as a reference to create your own.

filesrc location=$FILE ! qtdemux name=demux ! queue ! ffdec_h264 !  x264enc speed-preset=ultrafast ! prerecord \
buf-time=5000 buffering=true on-key-frame=false name=prerecord ! qtmux name=mux ! filesink location=test1.mp4 \
async=false demux. ! ffdec_aac ! prerecord. prerecord. ! queue ! opusenc ! mux. fakesink async=false


Previous: Examples Index Next: Examples/PreRecordSink