-
Notifications
You must be signed in to change notification settings - Fork 100
V0.4 Enabling Camera Controls
OctoPi uses mjpg-streamer to create a camera stream, which allows you to monitor your printer via OctoPrint. Mjpg-streamer has the ability to change some camera settings via control.htm. Additionally, mjpg-streamer can create a description of your camera's controls and capabilities, accessible via a file called input.json. Since mjpg-streamer has no authentication or authorization capability, it was decided to disable all access to these pages within OctoPi by default.
If you have not used port-forwarding or some other insecure methods to view your OctoPi instance through the internet, these pages are generally safe to use. If these pages are available, Octolapse can take advantage by using them to create a screen that allows you to control your camera's settings.
- Mjpg-streamer must be installed.
- Some plugins that create their own camera stream must be disabled. Currently this includes OctoPrint Anywhere and The Spaghetti Detective. These are both great plugins, but they are incompatible with custom camera controls.
If you are using a Raspberry Pi Camera, the steps are a bit different. See this comprehensive guide for using a Raspberry Pi Camera.
If you don't know how to connect to your Raspberry Pi, see this guide. When you are connected, continue on to step 2 below.
Open your octopi.txt file with the nano editor by entering the following command followed by the Enter key:
sudo nano /boot/octopi.txt
You may be prompted to enter your password. After the command completes, you will see the nano text editor. Use the arrow keys and edit this section (it may look slightly different than what is pictured here, but it should be close):
Next, using the arrow keys move down to the bottom of the octopi.txt file and find the following section:
change the following text
#camera_http_webroot="./www-octopi"
#camera_http_options="-n"
to this:
camera_http_webroot="./www"
camera_http_options=""
Be sure to remove any # characters at the beginning of the lines! It should look like this when you are finished:
While you're here, you might want to adjust your camera's resolution and frame rate. Find the camera_usb_options section and edit those now. For example, if you want a 1080P image at 30 frames per second, you would use the following:
camera_usb_options="-r 1920x1080 -f 30"
Be sure to refer to your camera's documentation when choosing a resolution and frame rate. Not all resolutions and frame rates are available for all cameras.
Make sure to remove any # characters from the beginning of the line!
and the end result will look something like this:
**Note: The higher the resolution and frame rate, the more bandwidth and CPU power will be used. Higher frame rates will reduce the image acquisition time (possibly improving quality, especially when using a smart trigger with snap-to-print enabled). Also, some versions of Firefox will have trouble showing a high frame rate mjpegstream, but Chrome seems to do just fine. Your mileage may vary, but if you have problems, try lowering your frame rate from 30 frames per second to 10 frames per second.
Now we want to save the file and exit nano. Hold down the ctrl
key and press the letter O (so ctrl+O) to save the file. Press enter to confirm. Then press ctrl+X to exit.
Finally, reboot your Pi by entering the following command followed by the Enter key:
sudo reboot
You may need to enter your password again if prompted. If you are using Putty, your session will end with an error. Wait until your Raspberry Pi has rebooted completely and then verify that OctoPrint is ready by opening it in a new browser window.
If you don't want to change the settings of an existing camera profile (perhaps because you have multiple cameras), the steps below will walk you through adding a new camera profile. If you only have one camera, you can skip this step and move on to Step 4
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 Settings link.
Then open up the camera profiles page within the Octolapse settings by clicking on the 'Cameras' link:
Next click on the Add Profile... button.
Name your profile so you can easily identify the camera. I'm going to use ACME Webcam in this example. Once you are finished lick on the Save button.
Now exit the OctoPrint settings popup by clicking Cancel at the bottom right hand corner.
Click the edit icon next to your your camera profile.
This will open up the existing camera profile settings. If you want to rename your profile, feel free to do so now.
Next, make sure that you are not using an imported profile by selecting `Not Selected' from the dropdown box.
Make sure that the Camera Type dropdown box is set to Webcam. Your settings will look something like this:
Now we need to verify the Snapshot Address Template. Make sure your camera can take snapshots by clicking on the 'Test' button. If it is successful, it will look like this:
If the test failed, you will see this message:
If your test has failed, see this troubleshooting guide for help getting the Snapshot Address Template working.
Find the Custom Image Preferences section within the camera profile and check the Enabled check box. If you see an error like this, follow the troubleshooting guide here:
If custom image preferences were successfully enabled, you will see two new options: Apply Preferences at Startup and Apply Preferences Before Print Start. Enable them both. Your settings should now look like this:
Now, save your profile by clicking the Save button:
Next, select your timelapse preview camera in the dropdown on the Octolapse tab found here:
You will now see a message explaining that no snapshots are available for the webcam. This is normal, and you won't see any snapshots here until you run a print with Octolapse enabled.
Next, click the edit pen to the right of the camera you just selected to open the image preferences:
If everything is working properly, you will be able to see your camera stream at the top of the popup, which will look similar to this:
If the stream is not working, you will see something like this:
If your camera stream will not load, see this troubleshooting guide.
Finally, save your profile by clicking on the Save button at the very bottom.
Dialing in your camera settings is very important for getting a high quality timelapse. Before you start, it is important that you have adequate lighting. Good lighting is critical for getting a high quality timelapse, and it might even improve your print quality by reducing the snapshot acquisition time! Photography LEDs work great, but cheap LEDs that use low frequency pulse width modulation (PWM) might result in a lot of flicker in your final timelapse. Incandescent and halogen bulbs will work well, but they use a lot more power than LED lights. In general, you will want your lighting to be much brighter than is necessary to just see your prints.
I also recommend that you close any blinds in the room with the printer because the light levels in the room may vary, messing up the exposure and leading to a lower quality timelapse.
Once you have improved your lighting, it's time to adjust the camera settings.
Open the Octolapse tab, and select your camera from the dropdown box. Then click the edit pen in the upper right hand corner of the Latest Snapshot image:
If you do not see the edit pencil, custom image preferences have not been properly enabled. Go back to step 7
Here you will find a couple options regarding how the image preferences will display. Feel free to toggle between Single Column and Two Column Mode. You can also switch between the default and custom image preference screen. Please note that this guide assumes you are using two column mode _and _the custom page, so your settings should look like this:
Note that the button above will say Switch to Single Column when it is in two column mode.
The first thing I usually adjust is the focus. If your camera has digital focus, you will see the control within your preferences. Be sure to deselect automatic focus if you have the option. Here is what this looks like for my webcam (a Logitech C920):
Next, I recommend adjusting your exposure and gain. This will vary by camera, but usually you will need to set your exposure to manual and then edit the exposure and gain value. Automatic exposure will usually lead to flickering, as lighting conditions in the room change. Here is how this looks with my Logitech C920:
You want to use as low an exposure setting as possible while maintaining good image quality. If your camera does support gain controls, it's usually better to have a higher gain and lower exposure, since higher exposure times can sometimes increase the time it takes for Octolapse to acquire an image. Experiment a while to determine what works best for your camera and lighting conditions. I also recommend closing your blinds to keep the light levels in your room stable.
Another important setting to adjust is the white balance. Manual settings here can also cause a flickering timelapse. Some cameras have individual adjustments for red and blue, and some only have color temperature. Here is what my white balance settings look like:
I try to adjust my white balance until the color looks as true to reality as I can.
Next you can play around with the rest of the settings. If you run into trouble, you can click the Defaults button at the bottom to restore all of the default camera settings. When you are finished adjusting your image, click 'Save' at the bottom to store the settings and close the popup.
Congratulations! Your USB Webcam is all configured!
If you completed step 5, your camera settings will all be automatically applied when your Raspberry Pi reboots, as well as when a new print starts. You can change this by editing your camera profile.
You can adjust your camera settings at any time, but be sure to save them when you're finished. Also, be careful when adjusting your camera settings in the middle of a timelapse. Changing the settings during a print may be quite noticeable in the timelapse video. It is much better to adjust your camera before starting a print.
Clicking Cancel while editing custom image preferences will undo any settings you have applied by re-applying the old settings.
You can always press the Apply All Settings Now button to ensure that every setting shown is applied to the camera image. It is possible for the camera to become out of sync with the Octolapse settings, and this button will correct the problem.
The other interesting button you might want to use is the Stabilize Extruder button, which will move your extruder to the snapshot position. This works as long as you are not using the 'Snap To Print' smart trigger option, and as long as stabilization is not disabled. Make sure your printer bed is clear before using this feature, else you may run into your print!.
Note that the 'Home Axis Gcode Script' within the printer profile will be executed before your extruder moves into position. You can edit this script within your current Printer Profile. It is important that your printer is homed and in absolute mode before Octolapse can stabilize safely, so make sure that your printer is in absolute xyz mode by using a G90
command. Also make sure it has been moved to the home position (usually accomplished via a G28
command).
Lastly, it may be useful to know that Octolapse dynamically creates the controls on the Custom Image Preferences screen based on the functionality reported by mjpg-streamer. It reads the available options and values from a file called input.json
that can be found by navigating to a page whose URL has the following form: {camera base url}/input.json
. Octolapse also contains a few custom camera pages that have improved over the default dynamic page. You can see if your camera was detected by looking under the camera stream:
To check for a custom page or to switch to the default dynamic page, click this toggle button:
If a page is available, you will see the following popup message:
If a page is not available, consider creating an issue, and be sure to download and provide the input.json
file mentioned above, and include your camera model. I can't guarantee I will be able to test it (odds are I don't have the same camera you do), but I will add it to a list for consideration.
Octolapse is provided without warranties of any kind. By installing Octolapse you agree to accept all liability for any damage caused directly or indirectly by Octolapse.
Use caution and never leave your printer unattended.
If you have a great new guide, see a typo, or have other suggestions for improving the existing documentation, please let me know! You can either submit a feature request or submit a pull request. I would appreciate it greatly!
Consider supporting Octolapse by becoming a Patron, a Github Sponsor, or by sending some coffee/beer money, I would REALLY appreciate it. Almost all of the donations go towards offsetting the cost of development, which are substantial. Plus it always makes my day!
If you cannot afford to leave a tip or just don't want to, that is fine too! Octolapse is free and open source after all. There are other ways you can help ensure that Octolapse continues to be updated and improved:
- Share your Octolapse videos, and be sure to leave a link and explain that the timelapses were captured with Octolapse and OctoPrint (you will be asked how you made the timelapse, so this will also save you some time answering questions). This is not necessary, but it is greatly appreciated.
- Subscribe to my youtube channel.
- Post any bugs you find to the Issues Page. I would like to eliminate as many bugs as possible!
- Participate in the OctoPrint Community Forums, and help all the noobs get OctoPrint and Octolapse working and help expand the hobby. The more people use OctoPrint and Octolapse, the better the software will become!
- If you've created a working and tested printer profile for any printers that aren't in the make/model list, please send it to me! I want to make it as easy as possible for new users to get their printers configured quickly.
- Help me make this documentation better! Octolapse has a LOT of documentation, guides, tips, etc., both here in the Wiki and integrated with the Octolapse plugin. If you find inaccuracies, typos, gaps, or have ideas for improvement, I'd love to hear about them.
- If you have any special talents that could be applied to Octolapse development, like graphic design, video production (think tutorials), programming, etc., maybe you'd like to participate more directly in Octolapse development/documentation?