Turn your Rasp­berry Pi into a stop-mo­tion video stu­dio

Build your own an­i­ma­tion stu­dio by us­ing your Rasp­berry Pi as a stop-mo­tion camera.

APC Australia - - Contents -

What have you done with your Rasp­berry Pi camera lately? While it gives us plenty of new ways to use the Pi, un­less you’ve got your com­puter set up as a se­cu­rity we­b­cam or you’re par­tic­u­larly a fan of time-lapse pho­tog­ra­phy, the chances are that you’ve over­looked the Pi camera mo­d­ule for a while.

If you’re a fan of an­i­ma­tion or you sim­ply want to ex­tend the pos­si­bil­i­ties of the mo­d­ule, why not build a stop­mo­tion camera? By us­ing Python and an ex­ter­nal but­ton to cap­ture im­ages, the Rasp­berry Pi can ac­tu­ally be the per­fect tool for an­i­ma­tors.

Bet­ter still, you can go be­yond an­i­mat­ing toys or bits of Lego and go old school by mount­ing the Pi on a ros­trum and cre­at­ing a car­toon. Even if you can’t buy or build one, you can mount the stop mo­tion Pi camera with a smart­phone mount for sta­bil­ity.


Be­fore you get started, think about the type of an­i­ma­tion you’re go­ing to be cap­tur­ing. If you’re us­ing the tra­di­tional top-down method, as used by clas­sic car­toon an­i­ma­tors, then you’ll need a ros­trum to mount the Rasp­berry Pi.

Al­ter­na­tively, you may be an­i­mat­ing some­thing on a desk, ta­ble or per­haps the floor, but you’ll need your Pi camera mounted in a sim­i­lar way, look­ing across rather than look­ing down.

Var­i­ous op­tions are avail­able, such as smart­phone tripods and dash­board mounts. Most of th­ese should be suit­able for se­curely mount­ing your Rasp­berry Pi.


For your first at­tempts at shoot­ing a stop-mo­tion video, you should use a wide and un­clut­tered space. This might be a desk, a kitchen work sur­face or even the floor, but it should be a hard and flat area in most cases (un­less you have need for a bumpy car­peted en­vi­ron­ment for your video) to aid with the cre­ation of your stop-mo­tion film.

As time pro­gresses and your skill de­vel­ops, other sur­faces can prove use­ful al­ter­na­tives, but keep it sim­ple for now and stick with flat sur­faces while you get to grips with the art form us­ing the Rasp­berry Pi stop-mo­tion camera.


Next you’ll need to con­nect the Pi camera mo­d­ule to your Rasp­berry Pi. All mod­els have the nec­es­sary con­nec­tor, al­though where it is found on the de­vice will de­pend on the ver­sion of your Rasp­berry Pi.

The Model A has the Pi-camera con­nec­tor next to the Eth­er­net port, as does the Model B.

On the B+ and the Rasp­berry Pi 2, the con­nec­tor is in a sim­i­lar po­si­tion, but it’s a lit­tle fur­ther from the Eth­er­net port be­tween the au­dio-out and HDMI ports.

Con­nect­ing the camera mo­d­ule can be tricky. Be­gin with tak­ing your Pi out of its case or re­move the top where pos­si­ble and dis­con­nect all ca­bles. Take pre­cau­tions be­fore re­mov­ing the de­vice from its an­ti­static bag, as the camera mo­d­ule is very sen­si­tive to static elec­tric­ity.

On the Pi, lift the plas­tic catch on the con­nec­tor and slot the camera mo­d­ule flex into place with the shiny con­tacts fac­ing away from the Eth­er­net port. Once the flex is fully slot­ted in, push the plas­tic catch back into place.


Af­ter con­nect­ing the Pi camera, check that it works by boot­ing the Rasp­berry Pi (we’re as­sum­ing you’re run­ning Rasp­bian) and en­ter­ing this in the com­mand line: sudo raspi-con­fig

With the key­board ar­rows, move down to op­tion five, ‘En­able Camera’, and tap En­ter. In the fol­low­ing screen, hit En­ter again to en­able the camera and exit. If you’re not al­ready signed into the GUI, do so now (if you’re in the com­mand line in­ter­face, en­ter “startx” to launch the desk­top view). Open the ter­mi­nal and en­ter: raspis­till -o im­age1.jpg You can re­view the re­sult­ing im­age in your Home direc­tory.


With the Pi camera up and run­ning, you may no­tice that it’s out­putting the im­age with the axes flipped. We can fix this us­ing Python, so open the ter­mi­nal and en­ter:

sudo apt-get in­stall python­picam­era python3-pi­cam­era

sudo idle3

In the Python ed­i­tor, open ‘File > New Win­dow’ and en­ter the code be­low, set­ting the ‘camera.vflip’ and ‘camera. hflip’ as True or False as re­quired. Save (per­haps as ‘cam­flip.py’), then press F5 to run the script and view the cor­rectly out­putted im­age.

To save time, how­ever, you might try ro­tat­ing the po­si­tion of your camera or Pi camera mo­d­ule! im­port pi­cam­era from time im­port sleep with pi­cam­era.Pi­Cam­era() as camera: camera.vflip = True camera.hflip = True camera.start_ pre­view() sleep(3) camera.cap­ture(‘/home/pi/ im­age2.jpg’)

camera.stop_ pre­view()


We have two ways to add a but­ton to the Rasp­berry Pi, but be­fore pro­ceed­ing, en­sure you have switched the com­puter off and dis­con­nected it from the mains. You should also dis­con­nect any ca­bles and hard­ware.

The sim­plest method of adding a but­ton is to em­ploy a sol­der-free breadboard and a sin­gle-state push­but­ton. Con­nect the but­ton to the breadboard with two male-to-fe­male wires run­ning to GPIO pins GND and 17. With a script de­signed to de­tect ac­tion from the but­ton on the GPIO, each frame of your an­i­ma­tion can be cap­tured with a sin­gle but­ton push.


Once sat­is­fied with the re­sults of your Pi camera, it’s time to turn it into a stop-mo­tion camera. The first step is to type up the code shown be­low, which will cap­ture an im­age of your sub­ject and save it into a folder called ‘Stop mo­tion’. Each im­age is num­bered se­quen­tially and they can all be stitched to­gether once your an­i­ma­tion is com­plete. Save the code as an­i­ma­tion.py: im­port pi­cam­era from RPi im­port GPIO but­ton = 17 GPIO.set­mode(GPIO.BCM) GPIO.setup(but­ton, GPIO.IN, GPIO.PUD_ UP)

with pi­cam­era.Pi­Cam­era() as camera: camera.start_ pre­view() frame = 1 while True:

GPIO.wait­_­for_ edge(but­ton, GPIO.FALL­ING)

camera.cap­ture(‘/home/ pi/an­i­ma­tion/

frame%03d. jpg’ % frame) frame += 1 camera.stop_ pre­view() Then, in a new ter­mi­nal win­dow, en­ter the fol­low­ing: sudo python3 an­i­ma­tion.py

Press the but­ton to cap­ture each frame, mov­ing the sub­ject as needed. When you’re all done, hit ‘Ctrl-C’ to ter­mi­nate the script.


For true an­i­ma­tion, the col­lected im­ages will need to be com­piled into one sin­gle file. In the ter­mi­nal, in­stall ffmpeg: sudo apt-get in­stall ffmpeg

Once in­stalled, you will then need to con­vert your im­ages into a video clip, as fol­lows:

ffmpeg -y -f im­age2 -i /home/ pi/Desk­top/stop-mo­tion/ frame%03d.jpg -r 24 -vcodec libx264 -pro­file high -pre­set slow /home/pi/Desk­top/stop­mo­tion/an­i­ma­tion.mp4 With this file cre­ated, open with the com­mand: omx­player an­i­ma­tion.mp4 The video will then be played in full-screen mode.


Don’t fancy us­ing the script? Try this stop-mo­tion ap­pli­ca­tion. Be­gin by in­stalling the raspi­camex­tras pack­age that in­cludes the UB4L drives for the Pi:

wget http://www.lin­ux­pro­jects.org/list­ing/uv4l_

repo/lrkey.asc && sudo ap­tkey add ./lrkey.asc

sudo sh -c ‘echo “deb http:// www.linux-projects.org/ list­ing/uv4l_ repo/rasp­bian/ wheezy main” >> /etc/apt/ sources.list’ sudo apt-get up­date sudo apt-get in­stall uv4l uv4l-raspi­cam uv4l-raspi­camex­tras With that done, en­ter: sudo apt-get in­stall stop­mo­tion

Launch with the stop­mo­tion com­mand to open a GUI with a live camera for you to line up each shot. This is a more el­e­gant so­lu­tion and cap­tured im­ages can be stitched to­gether us­ing the ‘Num­ber of im­ages’ slider and the camera but­ton above it.


Now you have the camera set up, a de­vice for keep­ing it steady (whether a DIY ros­trum or a tri­pod), and you’ve con­structed a but­ton or plan to cap­ture each frame via SSH. Your stop-mo­tion Rasp­berry Pi camera is fi­nally ready!

By now, you’re prob­a­bly aching to get started, so with your stop-mo­tion Pi camera ready to use (and close to a power sup­ply), it’s time to start build­ing your film set. While this might sim­ply be an empty ta­ble top, there might equally be a few props you would like to in­clude.


It’s easy to get tied up with the idea of cre­at­ing a stop-mo­tion camera and for­get all about a sub­ject and how it will act.

You can avoid any prob­lems here by tak­ing the time to care­fully plan what will hap­pen in your film: your story. Re­mem­ber, each sec­ond of the video will re­quire 26 frames!

The best way to plan at this level is to sim­ply write up an out­line, but be­yond this, you may pre­fer to storyboard in­stead by mak­ing pen­cil sketches to help you progress the story.


You’ll also need a good idea of what your sub­ject will be; this means who or what you’re go­ing to be us­ing the stop-mo­tion camera to cap­ture frames of. Typ­i­cally, ama­teur stop-mo­tion films make use of house­hold ob­jects, toys and child’s play clay.

The beauty of this kind of an­i­ma­tion is that you can use al­most any­thing that you can get your hands on, from a cup and saucer to an Ac­tion Man, as long as you have a way to sup­port the sub­ject(s) in the po­si­tions you wish them to take through­out.


If you cast toys as your stop­mo­tion stars, you will get a much bet­ter re­sult from some­thing that is built to stand up on its own than toys that tend to sit or fall over. Lego sets and Minifigs ap­pear in many stop-mo­tion pro­duc­tions on YouTube. This is with good rea­son, as they’re re­ally easy to place in a de­sired po­si­tion. The con­struc­tion el­e­ment of the bricks is also a ma­jor at­trac­tion. An­other pop­u­lar op­tion is Trans­form­ers toys. Th­ese are both good places to start, but you should aim to de­velop your own ap­proach over time.

“Don’t want to build your own ros­trum? Why bother when a camera tri­pod can be po­si­tioned.”

It isn’t only inan­i­mate ob­jects that you can in­clude in stop-mo­tion films. Peo­ple can fea­ture too! Pop videos such as Peter Gabriel’s 1985 hit ‘Sledge­ham­mer’ have taken ad­van­tage of stop mo­tion (that video was pro­duced by Aard­man An­i­ma­tions, the even­tual cre­ators of Wal­lace and Gromit) and the tech­nique can be used on hu­mans to cre­ate sur­real ef­fects. If you want your sub­ject to be mov­ing around a room too, they can ap­pear to be float­ing or glid­ing. The re­sults can be strange, but use­ful if you know what you want.


Known as ‘clay­ma­tion’, the prac­tice of an­i­mat­ing lumps of clay has been a pop­u­lar form of an­i­ma­tion for years, but there’s more to it than just clay. Th­ese forms, whether they’re cheeselov­ing old men, re­mark­ably clever dogs or the wrong pair of trousers, have a wire skele­ton that is used to keep move­ment in the de­sired po­si­tion.

This makes it much eas­ier to cap­ture the frames ef­fi­ciently, but for the best re­sults, you should also have sev­eral ver­sions of the same fig­ures avail­able. This is just in case one gets de­formed and dam­aged dur­ing pro­duc­tion!


Sim­i­lar to stop mo­tion, time lapse is a tech­nique that au­to­mat­i­cally cap­tures im­ages on a pre­set timer. We can use a Python script to con­trol this, sav­ing the cap­tures in a direc­tory and us­ing ffmpeg to com­pile them into a film.

How­ever, what you may not want for this project is a mains ca­ble trail­ing all over, es­pe­cially if you’re at­tempt­ing to cap­ture the move­ment of the stars at night or na­ture ac­tiv­ity. We sug­gest em­ploy­ing a Pi-com­pat­i­ble bat­tery pack to make your time-lapse Pi camera truly mo­bile, us­ing SSH to run the script re­motely: im­port time im­port pi­cam­era VIDEO_ DAYS = 1 FRAMES_ PER_ HOUR = 60 FRAMES = FRAMES_ PER_ HOUR * 24 * VIDEO_

DAYS def cap­ture_frame(frame): with pi­cam­era.Pi­Cam­era() as cam: time.sleep(2) cam.cap­ture(‘/home/pi/ Desk­top/frame%03d.jpg’ % frame) # Cap­ture the im­ages for frame in range(FRAMES):

# Note the time be­fore the cap­ture start = time.time() cap­ture_frame(frame)

# Wait for the next cap­ture. Note that we take into

# ac­count the length of time it took to cap­ture the

# im­age when cal­cu­lat­ing the de­lay time.sleep(

int(60 * 60 / FRAMES_ PER_ HOUR) - (time.time() v- start) )


At the risk of en­cour­ag­ing you to be­come the next Ivor Wood (cre­ator of The Wombles, Padding­ton and Post­man Pat, among oth­ers), it is pos­si­ble to use the Rasp­berry Pi’s camera mo­d­ule for am­bi­tious projects, as well as small ones. Af­ter all, this de­vice pho­to­graphs in high res­o­lu­tion so there is no rea­son not to adopt this setup and in­cor­po­rate it into a work­ing stop-mo­tion stu­dio with a minia­ture set.

Shar­ing your work through YouTube is a great idea, as well, es­pe­cially as it will make it sim­ple to add a sound­track over the top, us­ing YouTube’s browser­based ed­i­tor.

Here’s the stop mo­tion pro­gram in ac­tion — it’s a sim­ple enough GUI to get your head around and gives you a nice pre­view win­dow.

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.