Skip to content

V0.4 Configuring a DSLR

FormerLurker edited this page Jun 7, 2020 · 7 revisions

DSLR - Configuring a DSLR Video

Getting Started Video

Under Construction

This guide has changed since V0.3.4. I will continue to update this guide to bring it in line with V0.4 ASAP.

Should I use a DSLR?

I do not recommend that you use a DSLR if you have not gotten Octolapse to work with a webcam. There are several reasons for this:

  • It is much more difficult to configure a DSLR, and every DSLR is slightly different. Solving DSLR issues requires a lot of technical knowledge. If you are new to the game, this is not a good starting point
  • If you are uncomfortable or unfamiliar with Octolapse, you may have issues unrelated to the DSLR configuration that are confusing. Ironing out all of the kinks with Octolapse before attempting to use a DSLR is extremely important.
  • If you are having quality issues, using a DSLR will make them worse. Capturing images with a DSLR can take many times longer than a webcam, which will increase artifacts and print time. Make sure you are getting acceptable quality when using a webcam will reduce the chances of having problems when using a DSLR.
  • It is very difficult for me to provide help with DSLR issues. Every camera is different, and I only have access to a single camera: A Nikon D5200. This limits my ability to replicate, and thus debug your issues.
  • Rendering an ultra high resolution video may be beyond the capability of a Raspberry Pi. They are cheap and convenient, but they don't have a lot of memory. You might need to render the timelapse manually, depending on your rendering settings, and some people find this intimidating.
  • Newer cameras might not work properly. It takes time to update the capture software (GPhoto2 in this case) for use with newer cameras. If you have a brand new model, you may have to wait until support is added, if it is even possible.

Despite all of the above, the image quality of a good DSLR is second to none.

How Does Octolapse Support DSLR Cameras?

Octolapse supports external cameras by calling an external script. The script is responsible for acquiring an image. Optionally the script can put the resulting image in the proper place so that Octolapse can render the resulting timelapse.

You will need to create a script that can trigger your camera. This guide uses GPhoto2, which is an extremely sophisticated program for remotely controlling supported cameras using a USB cable.

Important Note: I am NOT the creator or maintainer of gphoto2, nor am I an expert in its operation. I cannot provide support for this software, because each camera is different, and it's very likely that I won't be able to replicate your issue on my camera.

Linux (octopi) installation instructions

These instructions assume that you are running OctoPi v0.15.1. The steps will be similar for other flavors of Linux, though some modifications may be necessary.

Watch a video version of this guild here. I must point out that this video was made for Octolapse v0.3.4, so it is a bit out of date. I will try to update this ASAP.

Step 1 - Update your Raspberry Pi

It is extremely important that you have the latest firmware and packages before attempting to use a DSLR. Follow this guide on the raspberrypi.org site for instructions on how to update your packages and distribution.

Step 2 - Installing the Latest Octolapse and OctoPrint

You must install the newest version of OctoPrint (1.4.0 currently) for full DSLR support. This is very important, so don't skip it!

Make sure that you have the latest version of Octolapse (v0.4.0) installed. If you do not, be sure to read the getting started guide to learn how to install, configure, and use Octolapse. Follow the guide completely, and get to know the new features in V0.4. A LOT has changed, and you'll save yourself a lot of time and grief if you get Octolapse configured properly before you attempt to configure a DSLR.

Step 3 - Gphoto2 Installation

Similar steps would be needed for a non/raspberry pi Linux setup. This example install uses GPhoto2 to acquire the images from your DSLR. I had some trouble with installation on my pi, so let me know if you have problems installing.

Here is a list of compatible cameras.

Use SSH or some other method to open a shell.

Now, follow this guide to install GPhoto2.

Step 4 - Test your camera

Now plug in your DSLR via usb, power it up, and execute the following command to make sure GPhoto2 is detecting your camera:

gphoto2 --auto-detect

If things are working properly You should get something similar to the following:

Model                          Port
----------------------------------------------------------
Nikon DSC D5200                usb:001,016

If there are no cameras detected you will get the following output:

Model                          Port
----------------------------------------------------------

In this case you should move to the official gphoto2 site and try to find a solution. Make sure you check the list of compatible cameras.

If things are working you should be able to run the following command to acquire an image:

gphoto2 --auto-detect --capture-image

Your camera should take a picture and save it on the camera. You should also be able to download an image to the current directory with the following command:

gphoto2 --auto-detect --capture-image-and-download

You should now see a new image in the current folder by entering the ls command. If you have problems here they will need to be corrected before continuing.

Step 5 - Create a snapshot script

Octolapse will soon ship with some default scripts, but for now they need to be created manually. As soon as these scripts are available I will update these instructions.

Below you will find a script that will trigger a snapshot, download the image from the camera's internal RAM to the pi, and move it into the proper directory with the proper name. This method preserves all of the functionality of Octolapse that you normally enjoy when using a webcam, including image transformations, post processing, snapshot preview, rendering, etc.

Now we need to create our snapshot script. I put my script in /home/pi/scripts like so:

cd /home/pi/scripts

nano take-snapshot.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
# 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

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

# IMPORTANT - You must add gphoto2 to your /etc/sudoers file in order to execute gphoto2 without sudo
# otherwise the following line will fail.
sudo gphoto2 --auto-detect --capture-image-and-download --filename "${SNAPSHOT_FULL_PATH}"

if [ ! -f "${SNAPSHOT_FULL_PATH}" ];
then
  echo "The snapshot was not found in the expected directory: '${SNAPSHOT_FULL_PATH}'." >&2 
  exit 1
fi

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 take-snapshot.sh

Finally, we can test our script by entering in the following command (it's long, so make sure you copy everything):

/home/pi/scripts/take-snapshot.sh 1 1 "" "/home/pi/scripts" "" "/home/pi/scripts/test.jpg"

you should see the following output:

New file is in location /capt0000.jpg on the camera
Saving file as /home/pi/scripts/test.jpg
Deleting file /capt0000.jpg on the camera

If you enter ls you should see test.jpg in the current directory. You can delete the test image by entering rm test.jpg.

Step 6 - Configure Octolapse

We're almost done! All that is needed is to create a new DSLR camera profile and to set it up, which is pretty easy and fast compared to the other steps.

First, we'll need to create a new profile.

Open up OctoPrint in a browser window and click on the Octolapse tab. Make sure the Current Settings are expanded. If they are not visible, click on the Current Run Configuration link.

Then open up the camera profiles page within the Octolapse settings by clicking on the 'Cameras' link:

Open the camera profiles page

Next click on the Add Profile... button.

Add a new camera profile

Name your profile so you can easily identify the camera. I'm going to use Nikon D5200 DSLR in this example:

Name and Describe Your Profile

Now, change the Camera Type dropdown box to External Camera - Script:

Select External Camera - Script

Next enter the following for 'Snapshot Acquire Script'

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

Here is what your Snapshot Acquire Script should look like:

External Camera - Script Selected

Now, click the Test button next to the Snapshot Acquire Script:

Click the Test Button

If everything worked, you will see this popup indicating success:

The Snapshot Acquire Script Worked!

If you get a failure message (will be in red) or a warning message (will be orange), there was a problem. I will try to add some troubleshooting steps, but for now I recommend rechecking your script and testing GPhoto2.

Next, set the 'Snapshot Delay' to 0 since the script won't exit until the photo is taken and downloaded. It's a good idea to turn the snapshot timeout up to 10000 (10 seconds) while you are testing to make sure your camera has enough time to take and download the photo, especially at higher resolutions.

Recommended Snapshot Delay and Snapshot Timeout settings for DSLR Cameras

Finally save your profile.

Save Camera Settings

Step 7 - Test Print

That should be it as far as configuration goes! Now run a short test print. Navigate to the Octolapse tab, expand the Current Run Configuration section, and enable the Test Mode slider at the bottom:

Test Mode Enabled

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, and make sure your bed/hotend stay cool.

Make sure you also select your DSLR profile in the dropdown box under the Timelapse Preview:

timelapse_preview_select_dlsr_profile

You will see a message explaining that no snapshots have been taken yet with your DSLR. This is normal, and you should see snapshots here after the first snapshot is taken during a print.

Select a test file to print. I recommend something small and fast, so you don't have to wait long to make sure things are working correctly. Click Print once you have selected your file.

Octolapse should now run as usual. Since Test Mode is enabled, your bed and hotend should stay cool, no fans should turn on, and no plastic should be extruding. Octolapse will now acquire images from your DSLR, and any other cameras you have enabled. You should hear your camera snapping away during the snapshot phase. Octolapse will put all downloaded images into a new folder created within the following directory structure:

/home/pi/.octoprint/data/octolapse/tmp/octolapse_snapshots_tmp/{SOME_LONG_GUID_HERE}/{ANOTHER_LONG_GUID_HERE}

Note: If you changed the default snapshot directory within the Octolapse main settings, your snapshots should go into that directory instead.

Step 8 - Finishing up

Now that you've completed your test print, check out the resulting timelapse (it might take a while to render). You're probably noticing that the quality isn't quite as high as you'd expect. Never fear, this can be corrected!

Open up the 'Rendering' profile. Consider turning up the bitrate to 15M or 20M. The resulting video will be much larger. I do NOT recommend that you use the H264/H265 codec for DSLR timelapses if you are running Octoprint from a Raspberry Pi, because it often results in a malloc error since there isn't enough memory on the Pi to render lots of ultra high res frames. If anyone has any information about how I can fix this, please let me know!

If you have a multi-core computer (Pi3), you may want to turn up the rendering threads. Rendering an ultra high res timelapse can take a very long time, especially on a pi running only a single thread. Ideally you would use one thread per core. Be sure NOT to attempt a new print while Octolapse is rendering unless you are sure there is plenty of processing power. If you MUST print while you are rendering, make sure to leave at least 1 free core when you set the rendering threads, else OctoPrint may become unresponsive.

Now it's time to adjust your camera settings to get the best possible image. I recommend using very bright lights (more than you think is necessary) and setting all camera controls to manual, including focus, exposure and white balance. You will have to refer to your camera manual for instructions on how to configure your camera's settings. You should take pictures manually and look at the results until you are satisfied with the image quality.

Once you get your camera settings dialed in, it's time to run another test print. Repeat this process of adjusting your settings and running a test print until your video quality meets your expectations. If everything is dialed in, and your lighting is adequate and well positioned, your image quality should be outstanding.

Now, turn off test mode:

Disable Test Mode

I would recommend using the same print you were using in test mode, and trying that before you attempt anything larger.

When the print is finished, examine it for quality. If you are having quality issues, check out the Troubleshooting Print Quality guide. There are also some advanced methods for reducing image capture time, which is the most common reason for DSLR print quality issues. These guides aren't completed yet for the newest version of Octolapse (V0.4), but I will add links once those have been finished.

Congratulations, your DSLR is configured and ready to go!

Troubleshooting

Coming Soon

Windows Installation

The instructions for this are coming soon!

Clone this wiki locally