cassini12
Posts: 6
Joined: Thu Jul 05, 2018 3:33 pm

Camera, Video Past 10seconds?

Mon Jul 09, 2018 8:33 pm

Is it possible to have a trigger for the Pi to "capture and image" when said trigger is launched, but also have the Pi Camera always "open" and set another trigger for "capture past 10 seconds" and save to specific location??

TY

pfletch101
Posts: 187
Joined: Sat Feb 24, 2018 4:09 am

Re: Camera, Video Past 10seconds?

Mon Jul 09, 2018 10:03 pm

Without a time machine or a FTL drive, you can't go back in time! For video, what you have to do is leave the camera running all the time and continuously update a video loop that is longer than your desired 'lookback time'. There are various ways of doing this, in theory, and I am not a Pi video expert, so I can't tell you which is best in practice - I am sure that others can. When the trigger fires, you save the current contents of the loop and prepend it to the continuing live capture (unless you just want to see what happened prior to the trigger firing).

Edit: I see that picamera actually makes this very easy - see 'Recording to a circular stream' in http://picamera.readthedocs.io/en/relea ... ipes1.html.

cassini12
Posts: 6
Joined: Thu Jul 05, 2018 3:33 pm

Re: Camera, Video Past 10seconds?

Wed Jul 11, 2018 1:12 pm

Thank you, Let me see what I can do! Appreciate your help

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5691
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Camera, Video Past 10seconds?

Wed Jul 11, 2018 2:29 pm

raspivid has a circular buffer mode too - "Run encoded data through circular buffer until triggered then save".
You'll want a command similar to

Code: Select all

raspivid -w 1920 -h 1080 -fps 30 -c -t 10000 -b 10000000 -ih -o foo.h264 -k
which should put up a preview, and save the last ~10seconds whenever enter is pressed. There is also a mode where it triggers on being sent a signal from another process.

Any form of circular buffer recording with H264 encoded data has the restriction that it MUST start at a key frame (aka IDR frame, reference frame, or sometime incorrectly as an I-frame). The default is for one every 60 frames (2 seconds), but if you want more accurate splitting than that then you can reduce this value (intra-period is the key phrase. "-g 30" added to the raspivid command-line would reduce it to every 30 frames).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

cassini12
Posts: 6
Joined: Thu Jul 05, 2018 3:33 pm

Re: Camera, Video Past 10seconds?

Wed Jul 11, 2018 7:58 pm

6by9 wrote:
Wed Jul 11, 2018 2:29 pm
raspivid has a circular buffer mode too - "Run encoded data through circular buffer until triggered then save".
You'll want a command similar to

Code: Select all

raspivid -w 1920 -h 1080 -fps 30 -c -t 10000 -b 10000000 -ih -o foo.h264 -k
which should put up a preview, and save the last ~10seconds whenever enter is pressed. There is also a mode where it triggers on being sent a signal from another process.

Any form of circular buffer recording with H264 encoded data has the restriction that it MUST start at a key frame (aka IDR frame, reference frame, or sometime incorrectly as an I-frame). The default is for one every 60 frames (2 seconds), but if you want more accurate splitting than that then you can reduce this value (intra-period is the key phrase. "-g 30" added to the raspivid command-line would reduce it to every 30 frames).
Thank you, Can I ask, in that code example, where is the "enter" key referenced? If I am looking to have this activated via an "analog joystick direction push" . Thank you for your help!

HermannSW
Posts: 769
Joined: Fri Jul 22, 2016 9:09 pm

Re: Camera, Video Past 10seconds?

Thu Jul 12, 2018 7:44 am

See raspivid documentation:
https://www.raspberrypi.org/documentati ... /camera.md

Search for "-k" 6by9 used, that is for "Enter keypress".

Search for "--signal" (just below "-k") for toggling with signal.
The provided example looks simple:

Code: Select all

kill -USR1 <process id of raspivid>
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/fork-raspiraw      https://github.com/Hermann-SW/userland
https://github.com/Hermann-SW/wireless-control-Eachine-E52-drone      https://twitter.com/HermannSW

Return to “Camera board”

Who is online

Users browsing this forum: No registered users and 9 guests