Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Support live preview in windows #526

Closed
dadav opened this issue Jan 3, 2024 · 19 comments
Closed

[FEATURE]: Support live preview in windows #526

dadav opened this issue Jan 3, 2024 · 19 comments
Labels
enhancement New feature or request

Comments

@dadav
Copy link
Collaborator

dadav commented Jan 3, 2024

Is your feature request related to a problem?

Yes

Description

Currently the cameracontrol.py script relies on python-gphoto2 which is linux/macos only. It would be cool to have an windows solution too. The digicamcontrol project has the possibility to start a webserver, start the live view and provide access to the stream via http://localhost:5513/live...maybe this can be wrapped in a script.

Describe the solution you'd like

A script which makes it possible to have live preview of the dslr. Something like this:

# start the live view (hidden)
Start-Process -WindowStyle hidden -FilePath CameraControlRemoteCmd.exe -ArgumentList "/c do LiveViewWnd_Show"

# During sleep, access stream at http://localhost:5513/live
Start-Sleep -Seconds 5

# cancel live view
Start-Process -WindowStyle hidden -FilePath CameraControlRemoteCmd.exe -ArgumentList "/c do LiveViewWnd_Hide"

Describe alternatives you've considered

Additional context

No response

@dadav dadav added the enhancement New feature or request label Jan 3, 2024
@andi34
Copy link
Contributor

andi34 commented Jan 3, 2024

Hey and thanks for the report/request.
In General, preview is possible on all OS - but only for Linux there are known ways using gphoto2/libgphoto2 while creating a virtual webcam.

Photobooth uses MediaStreamConstraints to use a webcam/virtual webcam for preview "from device cam". A different way is to use the preview "from URL" using CSS.

For the start preview command we only use the OS command line, this could also be a batch file you call on Windows (for Windows small adjustments might be needed inside api/previewCamera.php if validation is active).

The preview command is executed independent of the preview mode.

In short: If you're able to start the preview via batch file you're able to use the preview "from URL" like this: url(http://localhost:5513/live)

@andi34
Copy link
Contributor

andi34 commented Jan 3, 2024

(you could also try the pre-photo command if start Preview command makes trouble)

@dadav
Copy link
Collaborator Author

dadav commented Jan 3, 2024

Hey and thanks for the report/request. In General, preview is possible on all OS - but only for Linux there are known ways using gphoto2/libgphoto2 while creating a virtual webcam.

Photobooth uses MediaStreamConstraints to use a webcam/virtual webcam for preview "from device cam". A different way is to use the preview "from URL" using CSS.

For the start preview command we only use the OS command line, this could also be a batch file you call on Windows (for Windows small adjustments might be needed inside api/previewCamera.php if validation is active).

The preview command is executed independent of the preview mode.

In short: If you're able to start the preview via batch file you're able to use the preview "from URL" like this: url(http://localhost:5513/live)

Thanks for your reply. Setting the css is a good idea. I'll also have a look in that php file, I think my windows installation is missing pgrep which is used by that script. I also noticed that there is probably a conflict with the running digicamcontrol instance, which is required for the preview, and the capture command, which also wants to access the camera. The digicamcontrol instance needs some startup time, so maybe I'll start it AFTER the photo was taken and kill it before taking the photo.. I'll report back later.

@andi34
Copy link
Contributor

andi34 commented Jan 5, 2024

Yeah, the pgrep would be an issue, but shouldn't be executed if Execute preview commands without validation is enabled (default). Maybe you can call another batch file to kill digiCamControl via stop command?

@andi34
Copy link
Contributor

andi34 commented Jan 5, 2024

And for capture another batch file which will capture
http://localhost:5513/?CMD=Capture and download the image http://localhost:5513/preview.jpg, destination need to be adjusted and is given by Photobooth via %s and can be passed.

See https://www.digicamcontrol.com/doc/userguide/web also for adjusting the default capture folder etc.

@dadav
Copy link
Collaborator Author

dadav commented Jan 5, 2024

And for capture another batch file which will capture http://localhost:5513/?CMD=Capture and download the image http://localhost:5513/preview.jpg, destination need to be adjusted and is given by Photobooth via %s and can be passed.

See https://www.digicamcontrol.com/doc/userguide/web also for adjusting the default capture folder etc.

Thanks for the tips. I wrote this simple wrapper which starts the Liveview, captures an image and kills the Liveview. Only the url(http://localhost:5514/live) setting is not working yet. I need to investigate further..

The script can be used like this, if anyone is interested:

# start Liveview
python digipy.py cmd LiveViewWnd_Show

# Capture a photo
python digipy.py slc capture %s

# Cancel Liveview
python digipy.py cmd LiveViewWnd_Hide

@andi34
Copy link
Contributor

andi34 commented Jan 6, 2024

Great! Thanks a lot for taking this challenge!
Because of the typo 5513 vs 5514?
Can you access the URL independent of Photobooth to see the preview?

About your repo:
Small readme with instructions on how to setup step by step? (Most user might already stuck while installing python)
License?

@dadav
Copy link
Collaborator Author

dadav commented Jan 6, 2024

Great! Thanks a lot for taking this challenge! Because of the typo 5513 vs 5514? Can you access the URL independent of Photobooth to see the preview?

About your repo: Small readme with instructions on how to setup step by step? (Most user might already stuck while installing python) License?

The typo was one problem, yes. 5514 is correct (default in digicamcontrol for the stream). I'm able to view it in the browser, but it crashes sometimes. There are issues in their repo about that, but it's still unfixed (dukus/digiCamControl#403).

I'm still working on the digipy wrapper repo and will add everything needed.

@dadav
Copy link
Collaborator Author

dadav commented Jan 9, 2024

Ok, I found a way better method using the Linux subsystem for windows. I can now use gphoto2 with windows 👍🏻 I will now try to get the preview script working and write everything I did together.

@andi34
Copy link
Contributor

andi34 commented Jan 9, 2024

Great!
To be true, Ive heard it works on wsl but haven't had the chance to test. This would make installation for windows users much easier I think.

I asked Benjamin also to write the steps down to install Photobooth from source on Windows too. This way we wouldn't depend on the release packages.

@dadav
Copy link
Collaborator Author

dadav commented Jan 9, 2024

Great! To be true, Ive heard it works on wsl but haven't had the chance to test. This would make installation for windows users much easier I think.

I asked Benjamin also to write the steps down to install Photobooth from source on Windows too. This way we wouldn't depend on the release packages.

Where I need to send the camera stream to? I've tried to read the cameracontrol.py script, which seems to send the data via ffmpeg to some device file. I think I need to find another way to get the data out of the wsl box..

@andi34
Copy link
Contributor

andi34 commented Jan 10, 2024

Possible to make it an stream available via http?
Maybe parts of https://github.com/photobooth-app/photobooth-app/tree/main/photobooth/services/backends can help?

@dadav
Copy link
Collaborator Author

dadav commented Jan 10, 2024

Possible to make it an stream available via http? Maybe parts of https://github.com/photobooth-app/photobooth-app/tree/main/photobooth/services/backends can help?

I think I could make it work with go2rtc. Will try and give feedback :)

I looked in the python code and think this could also work....but it's complicated

@dadav
Copy link
Collaborator Author

dadav commented Jan 10, 2024

Almost there....AlexxIT/go2rtc#871

@dadav
Copy link
Collaborator Author

dadav commented Jan 11, 2024

I can't seem to execute the capture command:

[cmd] => wsl gphoto2 --capture-image-and-download-filename=C:\Apache24\htdocs\data\tmp\20240111_212300.jpg 2>&1

Fails with Permission denied.

Maybe thats why: https://github.com/PhotoboothProject/photobooth/blob/dev/src/PhotoboothCapture.php#L95

I think I need a wrapper script to have more control over this^^ There is something going on with the path, because the backslashes are treated different in linux.

Another problem is that the connection to the stream stays alive somehow and so the capture-movie commands keeps therefore running. Is it possible to close the preview connection before taking executing the capture command?

@andi34
Copy link
Contributor

andi34 commented Jan 12, 2024

On Linux we use the cameracontrol.py to start the stream, if that's used we also need to capture via cameracontrol.py
Else you can define a stop command which is executed, might need the command validation to be active.

@andi34
Copy link
Contributor

andi34 commented Jan 12, 2024

There's also a docker file, not sure if the USB connected camera can be used there?

@dadav
Copy link
Collaborator Author

dadav commented Jan 12, 2024

There's also a docker file, not sure if the USB connected camera can be used there?

Hm, might worth a try. It's certainly possible in linux, not so sure in windows tho.

@dadav
Copy link
Collaborator Author

dadav commented Jan 12, 2024

Currently trying to run a python script as the capture command. This is driving me insane. The error tells me it can't execute python3.exe or the script (not sure), but everything seems correct.

Edit:
I think I just gonna install everything via wsl...

Edit2:
Running the install script in wsl works perfectly! With usbipd the camera is available inside of wsl, seems like the perfect solution..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants