DSLR image capture 1 per second and video capture

277 views Asked by At

I'm trying to learn to use gphoto2 to control a DSLR camera for image and video capture. I want the camera to take a photo every second, or minimum at a fixed rate but I can't work out how to do it.

I have found that in the command line one can use the command

gphoto2 - -I 2 -F 5 --capture-image and download

to capture an image every 2 seconds for 5 images for example but I don't know how to implement that in Python code and I don't know how many frames will be recorded. I would just like to capture the image, save to the camera SD card and 1 second later capture the next image.

Using

triggerCommand = ["--trigger-capture"]

appears to take images much quicker than

triggerCommand = ["--capture-image"]

but I cannot control the timings, both options also take longer than a second between frame captures.

My current code is below:

#!/usr/bin/env python3
import subprocess
import time
from datetime import datetime
from sh import gphoto2 as gp
import signal, os, subprocess

#kill gphoto2 process that occurs whenever connect camera
def killgphoto2():
    p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
    out,err = p.communicate()
    for line in out.splitlines():
        if b'gvfsd-gphoto2' in line:
            #kill process
            pid = int(line.split(None, 1)[0])
            os.kill(pid, signal.SIGKILL)
   
triggerCommand = ["--trigger-capture"]

killgphoto2()
start_time = time.time()
for i in range(5):
    gp(triggerCommand)
end_time = time.time()
print(end_time - start_time)

If anyone could help, I'd really appreciate it.

Also can one use gphoto2 or something else with the raspberry pi to record the video using the camera SD card, so that the camera native resolution and frame rate can be used?

I currently use opencv on the pi which records the video screen but has difficulty maintaining a stable frame rate.

Thanks

0

There are 0 answers