Thursday 15 June 2017

Chicks at play: RaspiCam 90fps

Our blue tit chicks came out of hiding a few days after leaving the nest, and now they are regular visitors at our feeders.


They need to learn the snatch-and-run technique, rather than spending too much time out in the open where they are vulnerable to predators.


Using a RaspiCam to capture video at 90fps results in slow-motion video and gives a better idea of their behaviour.


One of my favourite uses for the Raspberry Pi camera is taking slow motion video to observe the fast moving world of our garden birds. And at this time of year there are many chicks on the bird feeders, both feeding themselves and still being fed by their parents.

I'm convinced that many chicks are "playing" with each other, while presumably learning vital skills. But it also looks like the adults are also having fun.

I have several video clips where chicks appear to try to push their siblings off the feeders, often without any attempt to take the space they have freed up.

"Bandits at 10 o'clock"


The blue tit dad was very successful at driving away other birds earlier this year, and he appears to enjoy a bit of rough and tumble with his own chicks. Maybe this is part of their education...

Notice that the blue tit adult hits the juveniles chest with both feet to spin him upside down, then grabs his legs.

...However, he plays the same game with great tits, even though he could feed from the feeder by simply using another hole.



Chicks sometimes do the unexpected by challenging great tits. Watch this cheeky chick.



There does not appear to be any real violence in these encounters. In most cases the game seems to be to pull your competitor off the perch and hang onto them until the last possible moment (i.e. within a few inches of hitting the ground).

When small birds really want to damage their opponent, they generally try to peck the others eyes.

its good fun, but time consuming


The problem with taking 90fps video with a RaspiCam is that it is very time consuming.

This PiCam is multi-purpose,
so the motion sensor is not used for this project


A one minute video clip 640 x 480 at 90fps creates a file approximately 90-100MB and takes about 1 minute to download over wifi from my PiCam to my laptop.

Each 1 minute 90fps clip runs for nearly 4 minutes at 25fps (the encoded playback speed) and has to be edited. So if you spend 30mins taking video plus 30mins to download, plus 2hrs to play/review it... well, you get the picture!

A related problem is: "when do you push the record button?" If you just let it record in the hope that something interesting will happen, you will end up with a huge file and waste a lot of time downloading and reviewing it.

So I have tried to minimise the pain by creating a simple Gambas program to control the camera. The idea is that the program records short, 1minute video clips and saves each clip to a new file. The current file name is displayed. I watch what is happening in real time (i.e. I look out of the window) and if anything happens that looks like it might be interesting I jot down the number of the current file.

showing the current file is number 3


Only noted files are downloaded, so I simply delete the rest on the PiCam via VNC.

The downloaded files are .h246 format, therefore I use my MP4Box program (also written in Gambas) and convert/encode to .mp4.

I can do simple edits using AviDemux (e.g. trim video, reduce frame rate still further & so on). Or I use Shotcut for anything more complicated such as adding clips together, create video fades & stuff like that.

the Gambas code


My PiCam code has a simple user interface which I access remotely via VNC. The Gambas code executes a raspivid command to record 90fps video like this:-

Exec ["raspivid", "-w", "640", "-h", "480", "-fps", "90", "-t", "60000", "-o", strFileID]

Rather than wait for the raspivid command to complete, the program just checks whether the raspivid process is still running using a 500ms timer like this:-

Public Sub tmrProcessCheck_Timer()
Dim sOutput As String
  
  Exec ["pgrep", "-f", "-l", "raspivid"] Wait To sOutput
  'still running?
  If Split(Trim$(sOutput), gb.newLine).Count > 0 Then
    blnRaspiVidRunning = True
    
  Else
    blnRaspiVidRunning = False

When raspivid has stopped, the program can create a new file ID and run raspivid again.

If the user interface button is pressed to stop recording, I simply allow the current 1 minute recording to complete, then disable restarting.

I'm using df to check and display the amount of data/space on the Pi SD card like this:-

Exec ["df", "-H", "/"] Wait To strFreeSpace

The output (strFreeSpace) is just displayed in a TextArea control.



See also:-


2 comments:

  1. Hello Steve,
    Would you like to share the gambas program?

    Regards
    Sony (gambas guru forum)

    ReplyDelete
    Replies
    1. Hi Sony, the Gambas code has not been completed, but I'll try to post what I have on the GambasONE forum, probably in your thread here: https://forum.gambas.one/viewtopic.php?f=4&t=549

      Delete