7

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!

daveloyall
  • 2,140
  • 21
  • 23
MonkeyKingFlo
  • 143
  • 2
  • 7
  • just an idea, maybe you could use the video stream and extract the most recent frame ? – Bertrand Martel Jun 09 '20 at 00:03
  • Thank you Bertrand! I thought about it, but the problem is that the video stream is in a much lower resolution than the picture. And you would always have 16:9 images. If you bump up the quality of the stream, the CPU of the pi won't drop a lot in fps with ffmpeg. So i think pausing the stream, take picture and resume stream might still be a good compromise to make both functions happen. – MonkeyKingFlo Jun 09 '20 at 16:18
  • 2
    @MonkeyKingFlo Have you solved this challenge? – Mathias Aichinger May 01 '21 at 08:09
  • @monkeykingflo did you find a fix? – Sascha Wolff Jul 03 '21 at 21:11
  • You can use python-gphoto2, example is here: https://github.com/jim-easterbrook/python-gphoto2/blob/9448eb30ae4166ea4a67f43f51e735f46b600c8c/examples/time_lapse.py – ffsedd Sep 14 '21 at 13:33
  • @MonkeyKingFlo Did you managed to solve this issue ? I am actually facing the same problematic. – The_Average_Engineer May 25 '23 at 09:17
  • In the C libgphoto2 library, there is a sample code of a photo booth (examples/sample-photobooth.c): https://github.com/gphoto/libgphoto2 – The_Average_Engineer May 25 '23 at 12:53

0 Answers0