Raspbian gphoto2: use live view and capture-image on the same camera?

7.4k Views Asked by At

The problem:

I am running gphoto2 on a raspberry pi 4 with raspbian os lite. I am using it as a photo booth together with a canon EOS 100d cannected to USB. The cameras live view is passed to a http address with ffmpeg and motion. That works great so far. Two components are running for this: a motion webserver that grabs the video feed from whatever gets send to /dev/video0 And the actual gohoto command that starts the live view feed. For this I use the command:

sudo gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0

This gives me a nice live preview on https://localhost:8081/ which I utilize as a background on the photobooths web interface, so people can see themselves before pressing the „take picture“ button.

The problem is that the live view is now blocking the USB ptp connection with the camera: so when I hit the „take picture“ button on my web application it triggers this gphoto command:

sudo gphoto --capture-image-and-download

This will create some error like:

Cannot execute: error connecting, ptp already in use

So the gphoto live view stream blockades the capture image command. It seems you can only use one gphoto function at a time. What can I do?

Ideas:

The obvious would be to run the live view from a different webcam but I don‘t want that as it will not reflect the actual position of people in front of the camera accurately.

My second thought was to launch the live view command as a systemctl service. So I can easily start and stop the live view:

# /lib/systemd/system/mygphoto.service
[Unit]
Description=gphoto2 live view service
After=multi-user.target 

[Service]
Type=simple
ExecStart=/usr/bin/sudo /bin/bash -lc 'gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0'
Restart=on-abort

[Install]
WantedBy=multi-user.target

But this service only works the first time, and then after couple of stop and starts it crashes and is never able to run again until a reboot.

So I think the best would be a long terminal capture command, that does the following all at once:

  1. stop gphoto live view stream
  2. capture picture and download
  3. Start the live view stream again

Its important that this could be done constantly when taking pictures.

I would be very thankfu for any solution ideas for this command or even some total different solution approaches. Anyone did something similar before?

Thanks a lot for your help and suggestions!

0

There are 0 best solutions below