title: Raspbian gphoto2: use live view and capture-image on the same camera?
body: <p><strong>The problem:</strong></p>
  
  <p>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:</p>
  
  <pre><code>sudo gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0
  </code></pre>
  
  <p>This gives me a nice live preview on <a href="https://localhost:8081/" rel="noreferrer">https://localhost:8081/</a> which I utilize as a background on the photobooths web interface, so people can see themselves before pressing the „take picture“ button.</p>
  
  <p>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:</p>
  
  <pre><code>sudo gphoto --capture-image-and-download
  </code></pre>
  
  <p>This will create some error like:</p>
  
  <pre><code>Cannot execute: error connecting, ptp already in use
  </code></pre>
  
  <p>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?</p>
  
  <p><strong>Ideas:</strong></p>
  
  <p>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.</p>
  
  <p>My second thought was to launch the live view command as a systemctl service. So I can easily start and stop the live view:</p>
  
  <pre><code># /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
  </code></pre>
  
  <p>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.</p>
  
  <p>So I think the best would be a long terminal capture command, that does the following all at once:</p>
  
  <ol>
  <li>stop gphoto live view stream</li>
  <li>capture picture and download</li>
  <li>Start the live view stream again</li>
  </ol>
  
  <p>Its important that this could be done constantly when taking pictures.</p>
  
  <p>I would be very thankfu for any solution ideas for this command or even some total different solution approaches. Anyone did something similar before?</p>
  
  <p>Thanks a lot for your help and suggestions!</p>