The PiCamera... a peripheral that is perhaps responsible for much of the popularity and success of the Raspberry platform. The current version of the RPi camera is a respectable piece of hardware according to these specs, and has many potentially useful applications. I like cameras; I take pictures... the really nice thing about digital photography today is the instant gratification aspect of it. I thought that setting up X on my Mac would allow me get that instant gratification from the Pi Camera; I thought I'd be able to "preview" the PiCamera output with XQuartz, but then I ran across this statement:
FROM THE RPI DOCS: "Note that the camera preview only works when a monitor is connected to the
Pi, so remote access (such as SSH and VNC) will not allow you to see the camera preview"
So... WTFO?!? How do I see the pics?
Several ways are possible, but perhaps the quickest/easiest way is to mount a network drive in RPi that my Mac also has mounted. Once that drive is mounted, use it as the destination for pictures and video from the RPi. Once that's set up, following are some methods for getting output from the PiCamera:
It's the focus, stupid! OK, I realize that for £24 you can't expect a pro-quality DSLR. But this PiCamera (and the people in the Raspberry Pi organization that make decisions and profit from its sales) is not quite up to snuff when it comes to the simple matter of setting the lens' focus! I'll belay my rant for another day, but here's what you need to know:
Do this before you get started - it will save you a lot of time.
And be careful of speaking your mind about some of the low-quality crap peddled by The Organization
, This forum post got me kicked out of the RPi forums for life :`)
Here's a simple Python script that outputs a single 640x480 picture:
#!/usr/bin/python
import picamera
import time
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
camera.start_preview()
time.sleep(2)
camera.capture('foopic.png')
camera.stop_preview()
There's a lot more you can do in Python... the API gives you a lot of control, and there are reasonably thorough docs covering the PiCamera
You can get photos/snapshots or videos easily and quickly with the following commands; the bad news is no man
pages :( However, there's a page on the .org's website that gives a seemingly complete rundown, though it does have at least one error in the 'Examples'.
raspistill -o image003.jpg
(takes a snapshot, and saves it as image003.jpg
)
raspivid -o mymovie.h264 -t 10000
(creates a 10,000 msec/10 sec video, and saves it as mymovie.h264
)
The command options are 'feature-rich', especially raspivid
, and allows you to create, for example, a time-lapse sequence quite easily:
raspistill -t 600000 -tl 10000 -o image_num_%03d_today.jpg -l latest.jpg
The time lapse images taken using the command above will have to be processed or combined afterward to turn them into a movie or animation. That will require an additional step, and possibly an expensive software package! Alternative: I've not tried this, but the raspberrypi.org website has a "How-To" using raspistill
and other open-source tools to create a time-lapse.
But here's a different way to make a time lapse sequence using video. According to the docs referenced above, there's a lower limit of 2 frames per second on raspivid
, but that may change (if it hasn't already). At any rate, this will also produce a time lapse sequence small enough to include in a text message or email attachment (if you're into that). Yeah... so type that command into your RPi terminal, then get up in front of the camera, do a little dance, then post it to your Facebook account or whatever. Fool, you never looked so good!
raspivid -t 60000 -o mytimelapse.h264 -fps 2 -w 640 -h 480
And there's one more bit of bad news for video producers: the only video format available is H.264; bad news because it's not widely used - in the sense there aren't many apps that will play it directly. However, there is some support for bridging that gap. You can convert the H.264 format videos to MP4 using MP4Box
.
Oddly, it's installed (looks huge) and used as follows:
sudo apt-get install -y gpac
MP4Box -add mymovie.h264 mymovie.mp4
Once installed, GPAC's MP4Box renders H.264 files as MP4 files quickly and efficiently.
I've not had time to actually try streaming myself. Until I do, following are a few URLs with some information that may be useful:
- a post on the StackExchange forum, How to stream video from Raspberry Pi...
- an entry on "instructables.com" that also includes some networking config
- a how-to for streaming PiCamera video to the world via YouTube!
- some documentation and "recipes" for the Python API for manipulating streams that looks really useful