Starting the Raspi Camera is rather trivial:
raspivid -t 10000 -o test.h264
There is no way to stop this. This seems really stupid to me as, to the best of my knowledge, there is no camera available for retail which requires the user to specify how many seconds to run for, and then runs for that many seconds before stopping.
This presents a huge problem in surveillance. I am creating a program where home surveillance is switched on when the user leaves, and then off again when they return. If motion is detected just before the user returns, the camera starts recording for a predetermined period of time (ie. 10 mins), but since the
raspivid command is blocking, I get a situation where the user is physically in the house, but the program is in the
surveillance state. To get around this, I launch a thread to launch the
raspivid command, so now the states are correctly updated based on when the user comes and goes. However, now other states don't work. For example, I can't switch to the
TV state as I can not record HD footage and watch it at the same time. Similarly, I can't switch to the
Party state (constant video recording of parties) as the camera is already recording.
Using code I found on the web (but can't find the link to any more), I found a hack whereby I kill the thread which launched the
raspivid command. Unfortunately this is considered blasphemy by SO (see here and here), which I agree with not only because it might corrupt the
.h264 files and lead to memory leaks, but also because it is a nightmare for me to code (I have to have locks and semaphores everywhere as I am launching other threads for motion detection as well).
Is there any way to stop a recording raspi camera? If not, why not?