Skip to content

DSLR with Deferred Image Download

FormerLurker edited this page Oct 5, 2019 · 5 revisions

Note: These instructions are in beta. Please notify me with any issues or corrections, or just to say things worked for you.

Before Using This Guide

This guide assumes you have read and performed all of the steps in the Configuring an External Camera tutorial. If you have not done so, complete the guide at least up to and including step 4.

Deferring Image Download - OctoPi instructions

These instructions assume you are running OctoPi, but the instructions for other types of Linux installations would be very similar.

It is possible to prevent Octolapse from downloading the images from your camera until the print has finished. This method will greatly reduce the amount of time required to take a snapshot (as opposed to downloading each image immediately after it is taken), and will still allow Octolapse to download and render your timelapse from your camera automatically. There are a few downsides as well. You won't get any snapshot previews within the Octolapse tab, and the image transposition options within the camera settings won't work. Also, all of the images on your DSLR will be completely erased before the start of each print so BE SURE TO BACK YOUR IMAGES UP BEFORE STARTING!!

Step 1 - Create Camera Initialization Script

First we have to add a new script, which we'll call our 'Camera Initialization Script'. This script will tell your camera to save all images to the SD card instead of to internal memory. IMPORTANT NOTE - Some cameras do NOT support configuration via GPhoto2. We will run some tests during this tutorial to see if things are working properly.

I put my script in /home/pi/scripts by navigating to the following directory:

cd /home/pi/scripts

Next, create a new script file with the nano editor like so:

nano initialize-camera-erase-all-images.sh

This will open the nano editor. Copy the following script and paste it into the nano editor by pressing the right mouse key.

IMPORTANT NOTE: The very first line #!/bin/sh is important, and must be included.

#!/bin/sh
# Camera Initialization Script
# Sets the capture target to the SD card
# Written by: Formerlurker@pm.me

# Put the arguments sent by Octolapse into variables for easy use
CAMERA_NAME=$1
# Set camera to save images to flash memory
gphoto2 --set-config capturetarget=1
# DELETE ALL FILES ON THE CAMERA, SO BACKUP YOUR FAMILY PHOTOS FIRST!
gphoto2 --delete-all-files --recurse

Now we need to save the script. Press ctrl + o and then Enter to save. Then press ctrl + x to exit.

Now we need to add execute permission to the script with the following command

chmod +x initialize-camera-erase-all-images.sh

Note about the capturetarget setting

The config options vary by camera and by the gphoto2 version. You can run the following command to see what options for capturetarget are available on your camera:

gphoto2 --get-config capturetarget

Here's what my camera reports after running this command:

Label: Capture Target
Readonly: 0
Type: RADIO
Current: Memory card
Choice: 0 Internal RAM
Choice: 1 Memory card
END

If your options aren't the same as mine (Memory card = 1) you will have to adjust the initialize-camera-erase-all-images.sh script accordingly.

Step 2 - Create trigger snapshot script

Next, we will need to create a new script to take the actual snapshot. Again, we need to create a new file with the nano editor like so:

nano trigger-snapshot.sh

Again, this will open the nano editor. Copy the following script and paste it into the nano editor by pressing the right mouse key.

IMPORTANT NOTE: The very first line #!/bin/sh is important, and must be included.

#!/bin/sh
# Camera Capture Script - Leave on Camera, Don't download
# Requires a camera initialization script with the following command:  gphoto2 --capture-image --set-config capturetarget=1
# Written by: Formerlurker@pm.me
# Put the arguments sent by Octolapse into variables for easy use
SNAPSHOT_NUMBER=$1
DELAY_SECONDS=$2
DATA_DIRECTORY=$3
SNAPSHOT_DIRECTORY=$4
SNAPSHOT_FILENAME=$5
SNAPSHOT_FULL_PATH=$6

# trigger the camera and exit immediately
gphoto2 --trigger-capture

Now we need to save the script. Press ctrl + o and then Enter to save. Then press ctrl + x to exit.

We need to add execute permissions to this script as well like so:

chmod +x trigger-snapshot.sh

Step 3 - Create Pre-Render Script

Now we need to create a script that will run after the print is complete, but before rendering takes place. This script will download all of the images from your camera into the proper directory on your server, and will rename them so that rendering will work properly. Again, we need to create a new file with the nano editor like so:

nano download-from-camera-and-rename.sh

Again, this will open the nano editor. Copy the following script and paste it into the nano editor by pressing the right mouse key.

IMPORTANT NOTE: The very first line #!/bin/sh is important, and must be included.

#!/bin/sh
# Camera Pre-Render script
# Written by: Formerlurker@pm.me

# Put the arguments sent by Octolapse into variables for easy use
CAMERA_NAME=$1
SNAPSHOT_DIRECTORY=$2
SNAPSHOT_FILENAME_TEMPLATE=$3
SNAPSHOT_FULL_PATH_TEMPLATE=$4

# Check to see if the snapshot directory exists
if [ ! -d "${SNAPSHOT_DIRECTORY}" ];
then
  echo "Creating directory: ${SNAPSHOT_DIRECTORY}"
  mkdir -p "${SNAPSHOT_DIRECTORY}"
fi

# switch to the snapshot directory
cd "${SNAPSHOT_DIRECTORY}"

# download all of the images on the camera
gphoto2 --get-all-files --force-overwrite

# rename images according to the supplied file template
a=0
for i in *.JPG *.jpg *.JPEG *.jpeg; do
  new=$(printf "${SNAPSHOT_FILENAME_TEMPLATE}" "${a}")
  mv -- "${i}" "${new}"
  a=$((a+1))
done

Now we need to save the script. Press ctrl + o and then Enter to save. Then press ctrl + x to exit.

We need to add execute permissions to this script as well like so:

chmod +x download-from-camera-and-rename.sh

Step 4 - Test Camera Scripts

Finally, we can test our scripts by entering in the following commands (WARNING: THIS WILL DELETE ALL IMAGES ON THE CAMERA! BACK UP ALL IMAGES ON YOUR CAMERA FIRST!):

/home/pi/scripts/initialize-camera-erase-all-images.sh

you should see the following output:

TODO:  FILL THIS IN

Next, enter the following commands to test image capture:

/home/pi/scripts/trigger-snapshot.sh

You should see the following output:

Todo:  Fill this out

Finally, run the following command to download and rename the image we just captured:

/home/pi/scripts/download-from-camera-and-rename.sh  TODO: ADD NECESSARY PARAMETERS

If there were no errors, you can check to make sure the images were downloaded and properly renamed by running the following command:

TODO:  COME UP WITH COMMAND

You should see an image called TODO: INSERT IMAGE NAME HERE in the results.

Step 5 - Configure Octolapse

Finally, we will need to configure Octolapse to use these two new scripts. Open OctoPrint and navigate to the Octolapse tab. Depending on your OctoPrint settings you may have to sign in before you can change Octolapse settings, so do that now if necessary. Edit your 'Camera Profile' and change the following settings:

First, ensure that the camera profile is enabled by checking the 'enabled' checkbox at the top.

Second, make sure the 'Camera Type' drop down box at the top of the page from 'Webcam' to 'External Camera - Script'

Next, type in the following for the 'Snapshot Acquire Script' setting:

/home/pi/scripts/trigger-snapshot.sh

Set the 'Snapshot Delay' setting to 0. This will reduce the total snapshot time since it is unlikely that you will need a delay before attempting to take a snapshot when using a DSLR.

Set the 'Snapshot Timeout' to 10000 (10 seconds). This can be reduced later, but it's useful for testing.

Now move to the 'Custom Camera Scripts' section and set the 'Before Print Start Script' to the following:

/home/pi/scripts/initialize-camera-erase-all-images.sh

Set the 'Before Render Script' setting to the following path:

/home/pi/scripts/download-from-camera-and-rename.sh

Make sure all of the other custom script fields are empty (Before Snapshot Script, After Snapshot Script, After Render Script).

Save your camera profile changes.

Finally, edit your current rendering profile settings and make sure the 'Timelapse Generation' option is checked. If you have multiple processors on your server (for example, the Pi3 B+ has 4 cores), you may want to adjust the 'Rendering Thread Count' under 'Advanced Rendering Settings'. This setting can greatly reduce the amount of time required to render a video. This is really nice because rendering a high res video can take a very long time on a pi! Be careful, however, since setting the available thread count higher than the number of available cores will HURT performance. If you are using a Pi3 B+ it is pretty safe to set the rendering thread count to 3, but NOT more than 4.

Step 6 - Test Print

That should be it as far as configuration goes! Now run a short test print. Change your 'debug profile' within Octolapse to Test Print - Full Diagnostic. This option will cause a diagnostic lot to be recorded. Additionally, test mode will prevent your printer from heating up (bed and extruder) and will strip off all extrusion commands, so you won't waste any time or plastic. I strongly recommend you unload your filament, though, just in case there is a bug or glitch in the test mode code.

Octolapse should now run as usual, but should acquire an image from your DSLR instead of the usual webcam, and it will not download any images to your server until after the print is complete. You will NOT see any preview snapshots in the Octolapse tab, but this is normal (the images are only on your camera's SD card after all). It should take substantially less time to acquire images now that the images aren't being downloaded. You should hear your camera snapping away during the snapshot phase. When the test print is completed, Octolapse will run the pre-render script and will download all images and render your final timelapse. The resulting timelapse will be available within the timelapse tab (not the Octolapse tab, still working on that) as usual. Note that it can take a REALLY long time to render a video depending on the length and settings. Be very patient.

Troubleshooting

If you are having trouble you might consider opening an issue here. Be sure to submit plugin_octolapse.log and your settings.json file, as is requested in the standard issue template. Please note any deviations from the above instructions or anything else you feel is relevant. Before creating an issue please re-read the guide to make sure nothing obvious is wrong, look through Octolapse Issues page and check the gphoto2 website and issues on the gphoto2 github page. It's possible that workarounds already exist!

Windows Installation

The instructions for this are coming soon!

Clone this wiki locally