gphoto / gphoto2

The gphoto2 commandline tool for accessing and controlling digital cameras.
GNU General Public License v2.0
717 stars 116 forks source link

Remote video recording using Nikon D7200 #557

Open benjyl opened 1 year ago

benjyl commented 1 year ago

I am trying to create a python script that triggesr a video recording that saves to a Nikon D7200 SD card.

I tried using the command line code to see if the video could be recorded gphoto2 --set-config movie=1 --wait-event=10s --set-config movie=0 --wait-event-and-download=2s but received an error "Failed to se new configuration value 0 for configuration entry movie".

I also tried running the following python script:

import time
import subprocess
import signal, os

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)

def record_video():
    subprocess.run(["gphoto2", "--set-config", "movie=1"])
    subprocess.run(["gphoto2", "--wait-event", "10s"])
    subprocess.run(["gphoto2", "--set-config", "movie=0"])

if __name__ == '__main':
    killgphoto2()
    record_video()

The script opens the camera, starts the recording and then stops the recording after around 1s of the wait event (I added a print statement after the wait event that only appeared after 10s) and it always happened after 1s, no matter how long I made the wait-event so something appears to be going wrong during this time.

The following came out in the terminal, I don't know if it is useful.

UNKNOWN PTP StoreAdded, Param1 00010001
UNKNOWN PTP Property 5003 changed
UNKNOWN PTP Property 5003 changed
UNKNOWN PTP Property 500a changed
UNKNOWN PTP Property d030 changed
UNKNOWN PTP Property d0a0 changed
UNKNOWN PTP Property d0a4 changed
UNKNOWN PTP Property d1a2 changed
UNKNOWN PTP Property d1a6 changed
UNKNOWN PTP Property d1a8 changed
UNKNOWN PTP Property d1a9 changed
UNKNOWN PTP Property d1ab changed
UNKNOWN PTP Property d1af changed
UNKNOWN PTP Property d1b1 changed
UNKNOWN PTP Property d20f changed
UNKNOWN PTP Property 500c changed
FILEADDED DSC_1419.MOV /store_00010001/DCIM/111D7200
UNKNOWN PTP Event 400c, Param1 00010001
UNKNOWN PTP Property d030 changed
UNKNOWN PTP Property d0a0 changed
UNKNOWN PTP Property d1b1 changed
UNKNOWN PTP Property d1b4 changed
UNKNOWN PTP Property d1f1 changed
UNKNOWN PTP Property d20f changed

Does anyone know what might be causing the issue and how to solve it?

Thanks

msmeissn commented 1 year ago

you need to have them set-config movie=1 ... wait and --set-config movie=0 in one command.

As soon as gphoto2 commandline tool exits it sends "close session" commands to the camera and the movie capture terminates at this time already.

benjyl commented 1 year ago

Ah Thanks. What's the syntax to do it all in 1 command? I am unfamiliar with the library and have never seen more than 1 setting changed in a single command

msmeissn commented 1 year ago

you had in the first comment:

gphoto2 --set-config movie=1 --wait-event=10s --set-config movie=0 --wait-event-and-download=2s

:)

benjyl commented 1 year ago

Ah ok, I didn't realise I could do that all within one step in python.

Out of curiosity, I'm looking at taking this further, trying to get the camera to start recording and turn off when a signal is generated and sent to the raspberry pi it is plugged in to. Starting the recording is no problem, just an if statement, but given that I can only use one statement to keep the recording going for a certain amount of time, is there a way of changing the 10s recording time to continuous until a pin changes state and if so how does the syntax change? Otherwise I assume ctrl C is the only way of stopping the recording?

Thanks