I am working on a project with a Raspberry Pi 3B to record videos that I later want to analyse with software such as ImageJ or Python. The setup I am using consists of the Pi, connected to the camera module (v2.1) and a temperature/humidity probe, model AM2302.

I save the video in the h264 format, that I then convert into a MP4 with mp4box. After this I use virtualdub to convert the MP4 into separate jpeg files that I can then analyse.

When I was going through the data I noticed that the frame rate wasn't constant. The MP4 I get out of the mp4box indicates that it runs at 25 fps. When I divide the total number of frames by the total time of my experiment, I end up at just over 30 fps on average. However, this number is not constant throughout the video, and I have no idea why.

I use the following code to run the setup:

import Adafruit_DHT
import time
import csv
import picamera
from time import sleep

print('running, press ctrl+c to stop')

camera = picamera.PiCamera()

camera.hflip = True
path = '//path//to//save//location//'
folder = 'save_folder' #not created automatically, will prompt an error if no folder found
file_name = 'file_name'

pin = 12 #change this to whatever pin the sensor is connected to
sensor = Adafruit_DHT.AM2302

stime = open(path+folder+'//'+'starttime_'+file_name+'.csv', 'w')
start = time.time()
startwrite = csv.writer(stime)


i = 0

    while True:
        i = i+1
        log = open(path+folder+'//'+file_name+'_log'+str(i)+'.csv', 'w')
        logdata = [[0]]
        write = csv.writer(log)
        j = 0

        while(j <= 3600):
                humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
                current = time.time() - start
                camera.annotate_text = str(round(current*10)/10) + '  ' + str(round(temperature*10)/10)
                timestamp = round(current)
                logdata = [[timestamp, temperature, humidity]]
                j = j+1


except KeyboardInterrupt:

etime = open(path+folder+'//'+'endtime_'+file_name+'.csv', 'w')
endwrite = csv.writer(etime)


The videos are usually rather long (4 hours or more) and are therefore saved to an external hard drive connected through USB. Does anyone have an idea why the frame rate in my videos isn't constant?

  • Is there any connection between the content of the videos and the frame rate - do busy scenes cause the rate to drop, and still scenes cause it to increase? – goobering May 17 '17 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.