GStreamer pre-record element - Examples - PreRecordSink
GStreamer pre-record element |
---|
Overview |
User Guide |
Getting Started |
Examples |
Contact Us |
PreRecordSink example pipelines
To test the prerecordsink 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 prerecordsink 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:
Single file generation example
The following script is an example where the pipeline will generate a single MP4 file after a trigger. The pipeline will record 10 seconds of video, 5 seconds before the trigger and 5 seconds after the trigger, configured by the buf-time property.
#!/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 ! h264parse ! prerecordsink buffering=true on-key-frame=true name=prerecordsink location=recording_%Y-%m-%d_%H:%M:%S%z.mp4 buf-time=5000 # Run pipeline gstd-client pipeline_play p1 # After 10 seconds, change the video pattern sleep 10 gstd-client element_set p1 src pattern snow # Allow buffer data to pass downstream gstd-client element_set p1 prerecordsink 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), 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.
Multiple triggers
The following script is an example where the pipeline will generate a single MP4 file after multiple triggers. After each trigger, the length of the file will be increased by post-buf-time, which in this case is equal to buf-time. The pipeline in the demo will record 18 seconds of video, 5 seconds before the trigger, and 13 seconds after the triggers, where 3 consecutive triggers will extend the length of the file.
#!/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 ! h264parse ! prerecordsink buffering=true on-key-frame=true name=prerecordsink location=recording_%Y-%m-%d_%H:%M:%S%z.mp4 buf-time=5000 # Run pipeline gstd-client pipeline_play p1 # After 10 seconds, change video pattern sleep 10 gstd-client element_set p1 src pattern snow # First trigger: Allow buffer data to pass downstream gstd-client element_set p1 prerecordsink buffering false sleep 4 # Second trigger: Extend length by 5 seconds gstd-client element_set p1 prerecordsink buffering false sleep 4 # Third trigger: Extend length by 5 seconds gstd-client element_set p1 prerecordsink 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-multiple-triggers.sh), follow the next steps:
sudo chmod 777 prerecord-video-multiple-triggers.sh gstd & ./prerecord-video-multiple-triggers.sh
Then you can observe the recorded video with VLC for example.
Max recording time
The following script is an example where the pipeline will generate a single MP4 file after multiple triggers but will limit the length of the file based on the max-buf-time property. After each trigger, the length of the file will be increased by post-buf-time, which in this case is equal to buf-time, until the time reaches the max-buf-time value. The pipeline in the demo will record one file of 12 seconds of video, 5 seconds before the trigger, and 7 seconds after the triggers, where 2 consecutive triggers will try to extend the length of the file to 14ms, but the limit will be reached at 12ms.
#!/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 ! h264parse ! prerecordsink buffering=true on-key-frame=true name=prerecordsink location=recording_%Y-%m-%d_%H:%M:%S%z.mp4 buf-time=5000 max-buf-time=12000 # Run pipeline gstd-client pipeline_play p1 # After 10 seconds, change the video pattern sleep 10 gstd-client element_set p1 src pattern snow # First trigger: Allow buffer data to pass downstream gstd-client element_set p1 prerecordsink buffering false sleep 4 # Second trigger: Extend length by 5 seconds gstd-client element_set p1 prerecordsink 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-max-time.sh), follow the next steps:
sudo chmod 777 prerecord-video-max-time.sh gstd & ./prerecord-video-max-time.sh
Then you can observe the recorded video with VLC for example.
Extended post recording time
The following script is an example where the pipeline will generate a single MP4 file after one trigger, but the pre-trigger time is different than the post-trigger time. This feature is useful to control different pre and post-trigger lengths based on user needs. The pipeline in the demo will record one file of 15 seconds, 5 seconds before the trigger, and 10 seconds after the trigger.
#!/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 ! h264parse ! prerecordsink buffering=true on-key-frame=true name=prerecordsink location=recording_%Y-%m-%d_%H:%M:%S%z.mp4 buf-time=5000 post-rec-time=10000 # Run pipeline gstd-client pipeline_play p1 # After 10 seconds, change the video pattern sleep 10 gstd-client element_set p1 src pattern snow # First trigger: Allow buffer data to pass downstream gstd-client element_set p1 prerecordsink buffering false # Stop the pipeline after 10 seconds sleep 15 gstd-client pipeline_stop p1 # Delete pipeline gstd-client pipeline_delete p1
Then you can observe the recorded video with VLC for example.