DaffyDubz
Posts: 8
Joined: Mon Nov 12, 2018 9:21 pm

Pi Zero Camera v1.3 dropped frames

Mon Nov 12, 2018 9:51 pm

Hello all,

I'm hoping to get some assistance with this. So just a little background, I'm using a Pi Zero with the Pi Camera module (5mp) as an alternative to an action cam (like GoPro). I don't like the cropped look for 1080p so I've been playing around with Modes 4 and 5 for the higher FOV (and 720p is good enough for me) So I've wired a switch to one of the GPIO and I'm using Python scripts to start and stop recording since the time of each recording is always going to be different. The first script is just a listener script that is run at boot and if the switch is turned to the "On" position it runs the main Python script which is where the recording code takes place. That script will record and then stop recording and close the PiCamera object when the switch is put into the "Off" position.

Everything is working as intended and it's been loads of fun thus far, however, when I go back and watch the recorded videos there are so many dropped frames it makes for quite an un-enjoyable experience. Mind you the camera is moving quite fast (attached to 5-inch race/freestyle Quad-copter) and I understand the limitation of 49fps in 720p (mode 5), but even at 25fps the frame drop is too much. Now I'm sure the shock of the quick movements don't help, but even on the shelf while testing I can't seem to get a solid fps with out dropping frames. I'll have to edit this post with the actual script when I get home, but while using PiCamera the only settings I'm adjusting are Mode, Resolution, and FPS, everything else is default. Before I go too crazy, is the Pi Zero capable of actually getting a solid 30fps on 720p while recording without dropping frames? This Pi is not used for anything other than this application (aside from a Samba share for Windows PC to copy the video files to, and VNC for when I'm too lazy to hook up KVM)

I've tried resetting ribbon cable several times, updates and upgrades, playing with bitrates and levels and all types of settings, GPU split from 128 all the way up to 384 (currently set back to 256, CPU seems happier with 256 rather than 128)

My next thought is to try fresh install of Raspian and disable everything but the camera? Mind you, I'm running the OS on a Class 10 (16Gb) SD.

I also have a Pi Zero W, but decided to go with my regular Pi Zero because I didn't need the wifi for this application, is there a difference with performance with the recording video between the two?

Thanks in advance!
-DaffyDubz

First is the listener script:

Code: Select all

import RPi.GPIO as GPIO
from time import sleep
from os import system

pin = 24

while True:
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    sleep(2)

    while True:
        sleep(0.3)
        if (GPIO.input(pin) == GPIO.HIGH):
            break
    
    GPIO.cleanup()
    system("python /home/pi/run.py")
    sleep(5)
And the main script:

Code: Select all

from datetime import datetime
from os import path
from os import system

d = datetime.now()
dfilex1 = d.strftime("%m"+"%d"+"%Y"+"_")
dfilex2 = d.strftime("%H")
dfilex3 = d.strftime("%M")

tname = '/home/pi/fpv/'+dfilex1+dfilex2+dfilex3+'.h264'

if path.isfile(tname):
    id2 = int(dfilex2)
    id3 = int(dfilex3)
    while True:
        id3 = id3 + 1
        if (id3 > 59):
            id3 = 00
            id2 = id2 + 1
        t2name = '/home/pi/fpv/'+dfilex1+str("%02d" % (id2))+str("%02d" % (id3))+'.h264'
        if path.isfile(t2name):
            t2name = None
            continue
        else:
            fname = t2name
            t2name = None
            id2 = None
            id3 = None
            break
else:
    fname = tname

tname = None
dfilex1 = None
dfilex2 = None
dfilex3 = None
d = None

import RPi.GPIO as GPIO
from time import sleep

pin = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
sleep(1)

from picamera import PiCamera

try:
    camera = PiCamera()
    camera.sensor_mode = 4
    camera.framerate = 30
    camera.rotation = 270
    camera.resolution = 1280,720
    sleep(3)
    camera.start_recording(fname)
    while True:
        if GPIO.input(pin) == 0:
            camera.wait_recording(0.5)
            camera.stop_recording()
            sleep(1)
            break
        else:
            camera.wait_recording(0.5)
finally:
    GPIO.cleanup()
    camera.close()

Last edited by DaffyDubz on Tue Nov 13, 2018 7:17 pm, edited 2 times in total.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20946
Joined: Sat Jul 30, 2011 7:41 pm

Re: Pi Zero Camera v1.3 dropped frames

Tue Nov 13, 2018 9:46 am

This sounds like a SD card writing speed limitation. The camera/Zero should be capable of those sorts of speeds. What bitrate are you using for the video? You could try dropping it to reduce the amount of data written to the card.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

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

Re: Pi Zero Camera v1.3 dropped frames

Tue Nov 13, 2018 11:20 am

You've not given the Python scripts so we can't comment on them.

Simplest test is to run

Code: Select all

raspivid -t 60000 -w 1280 -h 720 -o /dev/null -pts pts.txt -fps 30
Add any extra parameters that you're using. That will record with the camera for a minute and save the timestamps of every frame to a text file called pts.txt. The timestamps should all be 33ms apart for 30fps. Anything greater than that is a dropped frame.
I haven't run the test myself recently on a Pi 0, but everything except the file saving is done on the GPU and therefore the ARM should be totally capable of saving the data.

You aren't doing something silly and taking all the CPU in your polling the GPIO?
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.

DaffyDubz
Posts: 8
Joined: Mon Nov 12, 2018 9:21 pm

Re: Pi Zero Camera v1.3 dropped frames

Tue Nov 13, 2018 11:33 am

First is the listener script:

Code: Select all

import RPi.GPIO as GPIO
from time import sleep
from os import system

pin = 24

while True:
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    sleep(2)

    while True:
        sleep(0.3)
        if (GPIO.input(pin) == GPIO.HIGH):
            break
    
    GPIO.cleanup()
    system("python /home/pi/run.py")
    sleep(5)
And the main script:

Code: Select all

from datetime import datetime
from os import path
from os import system

d = datetime.now()
dfilex1 = d.strftime("%m"+"%d"+"%Y"+"_")
dfilex2 = d.strftime("%H")
dfilex3 = d.strftime("%M")

tname = '/home/pi/fpv/'+dfilex1+dfilex2+dfilex3+'.h264'

if path.isfile(tname):
    id2 = int(dfilex2)
    id3 = int(dfilex3)
    while True:
        id3 = id3 + 1
        if (id3 > 59):
            id3 = 00
            id2 = id2 + 1
        t2name = '/home/pi/fpv/'+dfilex1+str("%02d" % (id2))+str("%02d" % (id3))+'.h264'
        if path.isfile(t2name):
            t2name = None
            continue
        else:
            fname = t2name
            t2name = None
            id2 = None
            id3 = None
            break
else:
    fname = tname

tname = None
dfilex1 = None
dfilex2 = None
dfilex3 = None
d = None

import RPi.GPIO as GPIO
from time import sleep

pin = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
sleep(1)

from picamera import PiCamera

try:
    camera = PiCamera()
    camera.sensor_mode = 4
    camera.framerate = 30
    camera.rotation = 270
    camera.resolution = 1280,720
    sleep(3)
    camera.start_recording(fname)
    while True:
        if GPIO.input(pin) == 0:
            camera.wait_recording(0.5)
            camera.stop_recording()
            sleep(1)
            break
        else:
            camera.wait_recording(0.5)
finally:
    GPIO.cleanup()
    camera.close()

Not the cleanest, but it works haha. I had to get a little creative with the filename creation, I guess the Pi needs internet to get most recent date/time? Now, the listener script never actually ends, unless I force it to end, but I don't think it's using that much CPU. If I connect monitor while I test I can see CPU is hovering around 30% while recording.

Edit: It just dawned on me I could sort the files by name in the /home/pi/fpv directory and find the greatest number and inc by 1 to create a more elegant naming convention... but as far as the recording and GPIO part, am I doing everything ok? I'm fairly new to the Pi and Linux (and Python) but I work in IT with Windows so it's a pretty easy transition, just not entirely sure how the Pi handles resources and the most efficient ways of doing things. I should also mention I'm powering the Pi with a 3.7v lipo battery stepped up to 5v, the lipo is capable of outputting around 20 to 30 amps, but I believe the step-up module is nerfed to 2amp, but that's enough for just Pi and camera. Results of dropped frames also happen on 2amp 5v wall-wart.

PS, thank you for the quick reply's, from the many posts I've read through on this forums this seems like a great community, I always seem to forgot that communities like this are always so much better than the PC gaming community LOL
Last edited by DaffyDubz on Tue Nov 13, 2018 7:17 pm, edited 1 time in total.

DaffyDubz
Posts: 8
Joined: Mon Nov 12, 2018 9:21 pm

Re: Pi Zero Camera v1.3 dropped frames

Tue Nov 13, 2018 4:31 pm

6by9 wrote:
Tue Nov 13, 2018 11:20 am
You've not given the Python scripts so we can't comment on them.

Simplest test is to run

Code: Select all

raspivid -t 60000 -w 1280 -h 720 -o /dev/null -pts pts.txt -fps 30
Add any extra parameters that you're using. That will record with the camera for a minute and save the timestamps of every frame to a text file called pts.txt. The timestamps should all be 33ms apart for 30fps. Anything greater than that is a dropped frame.
I haven't run the test myself recently on a Pi 0, but everything except the file saving is done on the GPU and therefore the ARM should be totally capable of saving the data.

You aren't doing something silly and taking all the CPU in your polling the GPIO?
So I've been doing a few tests with this, also saving the output and converting to mp4 to rule out the conversion (I used ffmpeg in my testing) And I've gotten it to not drop frames on a few tests which is very good, not perfect but good, however it seems to be recording in a lower framerate than specified... 30fps gives me 34.7ms time stamps, and 40fps gives me 26~ so I found if I set -fps to 42, then I can get pretty close to 40fps (I'm assuming this has something to do with the timing on the camera?) Also, is the default bitrate 17mb? I've yet to try lowering the bitrate...

Now, is there a way to get this same test using PiCamera in Python? Or, is there a way to stop recording using GPIO if I use system("raspivid -t 0 ...") ?

PS, here's a neat little tool I used to find dropped frames (I did have some drops of 700+ ms)

Code: Select all

lines = [line.rstrip('\n') for line in open('pts.txt')]

i = 2     #you need to skip the header and the 0.00
op = open('out.txt','w')
while i <= len(lines):
    x = float(lines[i]) - float(lines[i - 1])
    if x > 27:     #27 for 40fps or 37+ for 30fps
        op.write("%s\n" % str(x))
    i = i + 1
    
op.close() 
This way I didn't have to scroll though thousands of lines, just look at the out.txt and it will tell me if there were any dropped frames or not :)

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20946
Joined: Sat Jul 30, 2011 7:41 pm

Re: Pi Zero Camera v1.3 dropped frames

Tue Nov 13, 2018 4:33 pm

Try dropping the bitrate, that can make quite difference on slower cards.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

DaffyDubz
Posts: 8
Joined: Mon Nov 12, 2018 9:21 pm

Re: Pi Zero Camera v1.3 dropped frames

Tue Nov 13, 2018 5:12 pm

Going to try that now, being that it's Class 10 (10MB/s) are SD cards mis-labeled by sellers? Do they really mean 10Mb/s (Bytes and bits are way different)

regardless of that, would you say 9.5Mb is ok for bitrate? or go even lower? (9.5 is recommended for 720p 60fps, figured it cant hurt to go that high for 40fps, and it's almost half the default of 17Mb/s)

My tests with raspivid and the pi being stationary are much more stable, going to test it with the scripts now.

Just tested it on 9.5 with the battery powering it, I can't fly today but I walked around so the Pi was not stationary, I'll have a look at the results (~5min recording) once I can (I should probably get back to my day job haha)

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

Re: Pi Zero Camera v1.3 dropped frames

Tue Nov 13, 2018 5:20 pm

DaffyDubz wrote:
Tue Nov 13, 2018 4:31 pm
So I've been doing a few tests with this, also saving the output and converting to mp4 to rule out the conversion (I used ffmpeg in my testing) And I've gotten it to not drop frames on a few tests which is very good, not perfect but good, however it seems to be recording in a lower framerate than specified... 30fps gives me 34.7ms time stamps, and 40fps gives me 26~ so I found if I set -fps to 42, then I can get pretty close to 40fps (I'm assuming this has something to do with the timing on the camera?)
We have a register set that is defined for the camera modules that are sold by Raspberry Pi Trading Ltd (RPT). RPT has not sold the OV5647 5MPix sensor since the V2 8MPix sensor came out in April 2016.

If you are using a 3rd party clone of the Pi V1 camera (and I suspect you are) then there are no guarantees as to how well they copied the design, and they may well have different oscillators. Sorry, complain to the supplier.
We went to great pains back in viewtopic.php?f=43&t=98541 and had frame durations being correct to less than 0.07%, so you either have a clone or a faulty camera.
DaffyDubz wrote:Also, is the default bitrate 17mb? I've yet to try lowering the bitrate...
What command are you actually running? The one I gave you should throw away the encoded data, so the actualy bitrate makes little difference. Saving data will interrupt the processing of buffers as they come back, but there is a several MB FIFO on the output of the codec which should smoothe most SD card writing out.
DaffyDubz wrote:Now, is there a way to get this same test using PiCamera in Python? Or, is there a way to stop recording using GPIO if I use system("raspivid -t 0 ...") ?
All frames back from the encoder include a timestamp - https://picamera.readthedocs.io/en/late ... .timestamp documents where it appears through PiCamera.
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.

DaffyDubz
Posts: 8
Joined: Mon Nov 12, 2018 9:21 pm

Re: Pi Zero Camera v1.3 dropped frames

Tue Nov 13, 2018 7:15 pm

6by9 wrote:
Tue Nov 13, 2018 5:20 pm
We have a register set that is defined for the camera modules that are sold by Raspberry Pi Trading Ltd (RPT). RPT has not sold the OV5647 5MPix sensor since the V2 8MPix sensor came out in April 2016.

If you are using a 3rd party clone of the Pi V1 camera (and I suspect you are) then there are no guarantees as to how well they copied the design, and they may well have different oscillators. Sorry, complain to the supplier.
We went to great pains back in viewtopic.php?f=43&t=98541 and had frame durations being correct to less than 0.07%, so you either have a clone or a faulty camera.
DaffyDubz wrote:Also, is the default bitrate 17mb? I've yet to try lowering the bitrate...
What command are you actually running? The one I gave you should throw away the encoded data, so the actualy bitrate makes little difference. Saving data will interrupt the processing of buffers as they come back, but there is a several MB FIFO on the output of the codec which should smoothe most SD card writing out.

All frames back from the encoder include a timestamp - https://picamera.readthedocs.io/en/late ... .timestamp documents where it appears through PiCamera.
Thank you for the information, in my script I'm running PiCamera, where the only things I'm setting are Mode 4 Resolution 1280,720 fps 42 and rotation 270 (the full script has been added to the First post) so default bitrate of PiCamera? I'm assuming there's a default since I'm not specifying it with "bitrate=x"

Code: Select all

import RPi.GPIO as GPIO
from time import sleep

pin = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
sleep(1)

from picamera import PiCamera

try:
    camera = PiCamera()
    camera.sensor_mode = 4
    camera.framerate = 30
    camera.rotation = 270
    camera.resolution = 1280,720
    sleep(3)
    camera.start_recording(fname)
    while True:
        if GPIO.input(pin) == 0:
            camera.wait_recording(0.5)
            camera.stop_recording()
            sleep(1)
            break
        else:
            camera.wait_recording(0.5)
finally:
    GPIO.cleanup()
    camera.close()
While running your test with raspivid and sending the output to null I was getting near flawless results, so I ran some tests (still using raspivid) and actually saving the output file, again near flawless results (with default bitrate, was not setting it to anything) I tried once more with bitrate set to 10Mb and I was happy with results.

Most recently, I altered my script to set bitrate=9500000 and recorded a ~5min walk. Results were very good, however, I got a big drop, only once, but towards the beginning of the recording (~30 seconds in). I briefly put the Pi in my pocket and then took it out and it then angled it at the sky (it's overcast today) and most of the duration of going from ground to sky is missing. (at first I thought maybe the change in light upset the camera, but later in the vid I angled ground to sky several times with no issue) Other than that the remainder of the video is pretty flawless. I'll have to run some real tests next time the weather permits me to fly... I can live with dropping a little (once or twice), but before it was constantly dropping. Thank you both for the help, I guess I'll keep playing with it, for now it seems much better though.

DaffyDubz
Posts: 8
Joined: Mon Nov 12, 2018 9:21 pm

Re: Pi Zero Camera v1.3 dropped frames

Wed Nov 14, 2018 7:05 pm

So I haven't tested the following, but was hoping to make the scripts more efficient. With regards to the Listener script, do I need to worry about GPIO.cleanup because I'm running "run.py" in another process (which uses the same GPIO pin#) Also is an infinite loop ok without any delays like "sleep(x)"? I wasn't sure if the Sleep function is using CPU or freeing CPU... (Same question applies to the actual run.py there's a while loop during the recording) Or would "GPIO.wait_for_edge(...)" be better?

Any syntax issues I'll fix when I'm back on the actual Pi (I wrote the ffmpeg part from memory), but as far as efficiency goes, is this looping and using an interrupt better than checking the actual GPIO.input(pin) every loop?

The reasoning behind these changes is I think the CPU is getting pinned somewhere causing frame drops, if I lower bitrate further than 7.5Mb/s I'm not sure if I also have to lower framerate to compensate? (I also would like to learn better practice in Python - I have another project in mind already for my Pi0W and V2 NOIR cam)

First is the listener script:

Code: Select all

import RPi.GPIO as GPIO
from time import sleep
from os import system

def init():
    flag_callback = False
    pin = 24
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    sleep(1)
    GPIO.add_event_detect(pin, GPIO.RISING, callback=my_callback, bouncetime=300)

def my_callback():
    flag_callback = True

def process_callback():
    GPIO.cleanup()
    system("python /home/pi/run.py")

if __name__ == '__main__':
    try:
        init()
        while True:
            if flag_callback is True:
                process_callback()
                sleep(1)
                init()
    finally:         		
        GPIO.cleanup()
And the main script:

Code: Select all

from os import path
from os import system
import glob
import RPi.GPIO as GPIO
from time import sleep
from picamera import PiCamera

def get_cam():
    camera = PiCamera()
    camera.sensor_mode = 5
    camera.framerate = 42
    camera.rotation = 270
    camera.resolution = 1280,720
    sleep(2)

def get_mp4():
    sleep(1)
    system('ffmpeg -i '+fname+' --fps 40 -c copy '+fname+'.mp4'')
    sleep(1)
    system('rm -f /home/pi/fpv/*.h264')
	
def get_fname():
    x = len(glob.glob('/home/pi/fpv/*.mp4'))    # assuming len() returns 0 if it's null and starts the count at 1 instead of 0
    tname = '/home/pi/fpv/fpv'+x+'.h264'
    if path.isfile(tname):    # put this here just as a fail-safe, assuming the length of the glob is correct this will never execute
        while True:
            x = x + 1
            t2name = '/home/pi/fpv/fpv'+x+'.h264'
            if path.isfile(t2name):
                t2name = None
                continue
            else:
                fname = t2name
                t2name = None
                x= None
                break
    else:
        fname = tname
    tname = None
    x = None

def init():
    flag_callback = False
    get_fname()
    pin = 24
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    sleep(1)
    get_cam()
    GPIO.add_event_detect(pin, GPIO.FALLING, callback=my_callback, bouncetime=300)

def my_callback():
    flag_callback = True

def process_callback():
    camera.stop_recording()
    sleep(1)

if __name__ == '__main__':
    init()
    try:
        camera.start_recording(fname,bitrate=7500000)
        while True:
            if flag_callback is True:
                process_callback()
	        break
    finally:
        GPIO.cleanup()
        camera.close()
        get_mp4()
EDIT:
Here's a short clip of the original script using Mode 4 and the full FOV in 4:3 aspect ratio. I'll add one the next time I can fly with the new 16:9 720p, hopefully with no more dropped frames. (Still trying to figure out the best angle to mount it on the quad)
https://www.youtube.com/watch?v=oD_CUc_xa3k

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

Re: Pi Zero Camera v1.3 dropped frames

Thu Nov 15, 2018 10:15 am

Nice video.

I did attach a v1 camera with Pi Zero to RC airplane last year:
viewtopic.php?t=190407

I used a bash script started automatically on boot, calling raspivid to record a sequence of configurable long video clips.
I would expect raspivid to produce much less frame skips/higher framerates than raspicam.
So if there is no option only available with picamera, you may want to try raspivid, especially because of its "-pts" option:

Code: Select all

$ raspivid  | grep pts
-pts, --save-pts	: Save Timestamps to file for mkvmerge
$ 
You can analyze frame delta distribution and frame skips of the recorded timestamps with this tool:
https://github.com/Hermann-SW/userland/ ... ptsanalyze

For my rapiraw based high framerate recordings I always did such analysis as part of the tools:
https://stamm-wilbrandt.de/en/Raspberry ... l#raspiraw

P.S:
I do have one v2 camera (many v1 cameras), but never attached it to RC airplane or my dones.
But with v2 you can do roughly the double framerate of v1 camera for a given resolution:
viewtopic.php?t=212518#p1320034

While that table is for raspiraw, you can record eg. [email protected] with v2 camera and raspivid, and v1 camera allows for 90fps only.
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

DaffyDubz
Posts: 8
Joined: Mon Nov 12, 2018 9:21 pm

Re: Pi Zero Camera v1.3 dropped frames

Thu Nov 15, 2018 6:31 pm

HermannSW wrote:
Thu Nov 15, 2018 10:15 am
Nice video.

I did attach a v1 camera with Pi Zero to RC airplane last year:
viewtopic.php?t=190407

I used a bash script started automatically on boot, calling raspivid to record a sequence of configurable long video clips.
I would expect raspivid to produce much less frame skips/higher framerates than raspicam.
So if there is no option only available with picamera, you may want to try raspivid, especially because of its "-pts" option:

Code: Select all

$ raspivid  | grep pts
-pts, --save-pts	: Save Timestamps to file for mkvmerge
$ 
You can analyze frame delta distribution and frame skips of the recorded timestamps with this tool:
https://github.com/Hermann-SW/userland/ ... ptsanalyze

For my rapiraw based high framerate recordings I always did such analysis as part of the tools:
https://stamm-wilbrandt.de/en/Raspberry ... l#raspiraw

P.S:
I do have one v2 camera (many v1 cameras), but never attached it to RC airplane or my dones.
But with v2 you can do roughly the double framerate of v1 camera for a given resolution:
viewtopic.php?t=212518#p1320034

While that table is for raspiraw, you can record eg. [email protected] with v2 camera and raspivid, and v1 camera allows for 90fps only.
Thank you, I actually stumbled on that thread a while back, very nice. I debated on using raspivid but since I already had the switch soldered to the GPIO pins I decided to stick with PiCamera in Python. The only way I could figure out to start and stop raspivid with a switch was by calling raspivid in a subprocess and then terminating that subprocess, and I wasn't sure how elegant of a shutdown that would be for raspivid. I did get some very nice results using raspivid on the bench, but I think I have it fairly stable in Python. I had to scrap the interrupt idea because I'm running 2 different scripts that use the same GPIO pin# so it wasn't the cleanest. (I honestly don't remember why I went with 2 scripts instead of just 1, maybe I'll have better results if I scrap the second script and only use the listener script?) but with 5 minute videos I only get 1 or 2 sections of dropped frames (no more than few 100 ms lost, so it's not the end of the world) I'll keep playing since the weather is bad and I can't fly anyway...

In regards to your bash script, does it constantly record while power is applied to the Pi?

I also own a v2 camera, but it's the NOIR version so it looks silly in the daylight, I plan on using it on a different project anyway.

I guess I'll continue the trial and error in pursuit of perfection haha

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

Re: Pi Zero Camera v1.3 dropped frames

Thu Nov 15, 2018 8:43 pm

> In regards to your bash script, does it constantly record while power is applied to the Pi?
>
The while loop is endless and calls raspivid to reciod a video for a given time.
So a sequence of videos gets stored on SD card, each of some chosen length.

> I also own a v2 camera, but it's the NOIR version so it looks silly in the daylight
>
Only outside, and I would say "different". This is from v1 NoIR camera, view through green(!) meadow of camera mounted on small caterpillar robot:
https://forum.arduino.cc/index.php?topi ... msg3268945
Image


> The only way I could figure out to start and stop raspivid with a switch was by calling raspivid in a subprocess and then terminating that subprocess,
>
There is a much better way, use "-t 0" for forever record time and this:

https://www.raspberrypi.org/documentati ... /camera.md
Sending a USR1 signal to the raspivid process will toggle between recording and paused. This can be done using the kill command, as below. You can find the raspivid process ID using pgrep raspivid.

kill -USR1 <process id of raspivid>
Note that the timeout value will be used to indicate the end of recording, but is only checked after each receipt of the SIGUSR1 signal; so if the system is waiting for a signal, even if the timeout has expired, it will still wait for the signal before exiting.
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

DaffyDubz
Posts: 8
Joined: Mon Nov 12, 2018 9:21 pm

Re: Pi Zero Camera v1.3 dropped frames

Sat Nov 17, 2018 1:42 am

Thank you for the info Herman, I'll have to play around now with trying to get the exact PID of raspivid now. It's still going to be headless, mounted to a quadcopter, but I think (according to a quick google search) that I should be able to get it in python, this seems easy enough: https://stackoverflow.com/questions/266 ... -in-python so then I could do something like:

Code: Select all

if switch ON then raspivid...
if switch OFF then get the PID and kill it
Is there any reason why raspivid would have better results recording than picamera? Just can't help but think I'm doing something to mess it up some how haha. Oh well, this has turned out to be quite the fun project :)

Return to “Camera board”