Simple 3D Printing Timelapse Setup with Raspberry Pi
3D Printing is a really fun hobby… until it isn’t. When the printer is tuned and working, 3D printing is a very enjoyable hobby. It’s filled with learning and tons of online resources. For a few years my Prusa i3 MK3S+ was working great and then one day during an 11+ hour print I came into my office to find an overnight print failed and I had the rats nest of filament piled up along with an even bigger problem. A big cooled bundle of filament caked to my hot end. Ultimately, I had to recalibrate the whole printer, readjust the SuperPINDA sensor, and basically start from day 1. I have no idea why this happened.
I don’t know of anyone that has time to wait around and watch long print jobs. Even starting it early in the morning and attempting to check on the print all day is a distraction. So with that in mind, I wanted to know why my prints kept failing and I set out to set up a timelapse capture. There are many great resources available online for how to setup a timelapse camera on a Raspberry Pi and it really depends on what you want individually. However, many of the guides I found took me down the path of using Octoprint with the Octolapse plugin or a smartphone or DSLR setup. I was doing this for basic shooting and the main tenants of my setup was that I wanted it to be simple and use products I already had laying around the office. Additionally, I wanted to use exsiting software tools readily available on the Raspberry Pi Linux OS.
*NOTE: Why I didn’t choose the Octoprint route
I used the Rapsberry Pi 3.0 B+ since it was sitting idle in my office. Running Octopi on it was very slow and overkill for what I was attempting to do. Furthermore, I didn’t want to connect and configure Octopi to the printer. The goal was simplicity and I wanted a setup that could snapshot images in an interval.
Parts Bin
- Raspberry Pi 3 Model B+
- Logitech C270 Webcam
- 128GB USB Stick
Streaming Live & Capturing Images
I already has attempted to install Octopi and had the mjpg_streamer
binary installed on my Pi.
*NOTE: If you have Octopi installed and you have already configured the Octolapse plugin the webcam will likely already be in use and running mjpg_streamer. I had to kill the webcamd and mjpg_streamer process prior to running the command above.
I wanted to configure my setup to capture images every 10 seconds and also stream the print so I could check on it periodically from my phone. In order to do this you need to do the following:
mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480 -f 30" \
-o "output_http.so -w ./www" -p 8888 \
-o "output_file.so -f /path/to/save/images -d 10000"
- input_uvc.so: Captures video from the webcam.
- -d /dev/video0: Identifies the webcam device to use (yours may be different).
- -r 640x480: Resolution
- -f 30: Frame rate.
- output_http.so: Streams video via HTTP using `/www` as the directory to output HTML and supporting files.
- -w ./www: Use the default web server directory for mjpg_streamer.
- -p 8888: Set the port for the HTTP server to listen on
- output_file.so: Saves snapshots as jpeg.
- -f /path/to/save/images: Directory to store snapshots.
- -d 10000: Interval in milliseconds (10000ms = 10 seconds).
Notes on the above
- Replace /path/to/save/images and /path/to/www with actual paths. I used $HOME/images mounted to a 128GB USB stick
- Make configuration adjustments to optimize resolution, frame rate, and snapshot intervals based on your preferences.
- Go to http://<raspberry_pi_ip>:8888 (replace <raspberry_pi_ip> with your Pi’s IP address) to watch the live stream.
Making the Timelapse Video
ffmpeg -framerate 30 -pattern_type glob -i "*.jpg" -s 1280x720 -c:v libx264 -pix_fmt yuv420p timelapse.mp4
- -framerate 30: Sets the input frame rate to 30 frames per second.
- -pattern_type glob: Allows for pattern matching, using *.jpg to include all jpg files in the directory.
- -i "*.jpg": Specifies the input images.
- -s 1280x720: Resizes the output video to 1280x720 resolution.
- -c:v libx264: Uses the H.264 codec for high-quality compression.
- -pix_fmt yuv420p: Ensures compatibility with most media players.
- timelapse.mp4: The output video file name.
Final Result
{{ }}