Make an Animated GIF of a Small Object
by adaviel in Circuits > Cameras
2278 Views, 0 Favorites, 0 Comments
Make an Animated GIF of a Small Object
![MVI_0035.wg2.gif](/proxy/?url=https://content.instructables.com/F6V/6OTE/HABC7WMD/F6V6OTEHABC7WMD.gif&filename=MVI_0035.wg2.gif)
![stage1.jpg](/proxy/?url=https://content.instructables.com/F7T/CY39/HABDG5MY/F7TCY39HABDG5MY.jpg&filename=stage1.jpg)
![crop12a.jpg](/proxy/?url=https://content.instructables.com/FKO/NMV8/HABDG5MV/FKONMV8HABDG5MV.jpg&filename=crop12a.jpg)
![crop25a.jpg](/proxy/?url=https://content.instructables.com/FWA/AXIO/HABC7VSD/FWAAXIOHABC7VSD.jpg&filename=crop25a.jpg)
![stage2.jpg](/proxy/?url=https://content.instructables.com/F21/WNXZ/HABC53XZ/F21WNXZHABC53XZ.jpg&filename=stage2.jpg)
![stage3.jpg](/proxy/?url=https://content.instructables.com/FGT/W2XK/HA4M8COQ/FGTW2XKHA4M8COQ.jpg&filename=stage3.jpg)
The idea is to take a short video clip of a rotating object and convert it to a GIF89a file which will play in an endless loop in a web browser.
By using a motorized turntable such as a record player, the object can be made to rotate at a constant speed which makes the process much easier - a norrmal video can be recorded, rather than using stop-motion animation.
By using a motorized turntable such as a record player, the object can be made to rotate at a constant speed which makes the process much easier - a norrmal video can be recorded, rather than using stop-motion animation.
Prepare the Turntable
![stage2.jpg](/proxy/?url=https://content.instructables.com/F21/WNXZ/HABC53XZ/F21WNXZHABC53XZ.jpg&filename=stage2.jpg)
![stage3.jpg](/proxy/?url=https://content.instructables.com/FGT/W2XK/HA4M8COQ/FGTW2XKHA4M8COQ.jpg&filename=stage3.jpg)
Remove the spindle from the record player - the pin that holds the record centered. Place a piece of card or other material over the platter so that it is free to rotate. Place more card underneath and behind the platter to act as a backdrop - or at least, to make it look not so obviously a record player.
If green card is used, the background may later be replaced using a Chroma key process
If green card is used, the background may later be replaced using a Chroma key process
Shoot the Video
![stage1.jpg](/proxy/?url=https://content.instructables.com/F7T/CY39/HABDG5MY/F7TCY39HABDG5MY.jpg&filename=stage1.jpg)
Set up a video camera on a tripod so that the camera has a clear view of the model with the card in the background. It does not matter so much if objects such as the tone arm are visible to one side, as the video may be cropped. But the model should rotate entirely in a space with an unobstructed background.
Set up the lighting. To avoid obvious shadows, I used a small hand-held lamp with a diffuser bounced off a white ceiling, but it is not bright enough for good video quality. (the image here was taken with room lighting)
Place the model in the centre of the platter and start the turntable. Take about a second of video - at least one complete rotation. If desired, take more shots with different lighting, camera height, focus etc.
Set up the lighting. To avoid obvious shadows, I used a small hand-held lamp with a diffuser bounced off a white ceiling, but it is not bright enough for good video quality. (the image here was taken with room lighting)
Place the model in the centre of the platter and start the turntable. Take about a second of video - at least one complete rotation. If desired, take more shots with different lighting, camera height, focus etc.
Process the Video
![crop25a.jpg](/proxy/?url=https://content.instructables.com/FWA/AXIO/HABC7VSD/FWAAXIOHABC7VSD.jpg&filename=crop25a.jpg)
![crop12a.jpg](/proxy/?url=https://content.instructables.com/FKO/NMV8/HABDG5MV/FKONMV8HABDG5MV.jpg&filename=crop12a.jpg)
How to process the video depends on what software you have available. I use Linux with the following programs:
mplayer - video player
ImageMagick - scriptable image manipulation
xv (or eog, display etc.) - image viewer and manipulation
whirlgif or gifsicle - tool to create animated GIFs
xanim - animation viewer
(This is just a collection of free software that I already had and was familiar with, rather than what I would recommend others to
acquire. ImageMagick is pre-installed in many Linux distributions.)
With this tool set, I converted the video to a series of JPEG frames, cropped and selected a subset of these images,
converted them to GIF and assembled them into a composite GIF animation.
$ mplayer -vo jpeg MVI_0035.AVI
This creates one image per frame, 00001.jpg, 00002.jpg, 00003.jpg etc.
Find a boundng box that contains the model in all rotations and excludes unwanted elements such as the tone arm. I used xv to draw a box and show the coordinates, but it was perhaps easier just to guess and adjust the crop box later. The picture below shows a typical bounding box.
Identify two frames exactly one rotation of the turntable apart (about 2 seconds for an LP setting of 33 RPM). Save all the intervening frames. I found it easiest to delete the unwanted ones. E.g. if frames 1 and 54 were identical, I deleted frames 54, 55, 56 ... 103,
leaving seqentially numbered files 0001.jpg etc.
Convert and crop the images to GIF. The following worked for me, using the ImageMagick "convert" command in bash:
$ for f in 0*jpg ; do
g=`echo $f|sed s/jpg/gif/`
convert -crop 400x350+160+78 $f tmp.jpg
convert -resize 200x175 tmp.jpg $g
done
That gives sequential images 00001.gif, 00002.gif etc. half the size of the original, cropped from the middle of each frame.
If the cropped area is not right, it's easy to change the numbers and re-run the command with a couple of keystrokes.
The intermediate JPEG is probably not necessary, but without it my final image was offset on the screen.
Assemble the individual GIF frames into a single animation, e.g.
$ whirlgif -loop 0 -o MVI_0035.gif
or
$ gifsicle --colors 64 -O1 --careful --delay 10 --loopcount=forever 00*gif > MVI_0035.gif
The resulting GIF can be viewed in a web browser such as Firefox, or in e.g. xanim (which can single-step through the animation
Adding a Background
![MVI_0046.gs.gif](/proxy/?url=https://content.instructables.com/F8F/FSAV/HA4MDCFU/F8FFSAVHA4MDCFU.gif&filename=MVI_0046.gs.gif)
![frame.gif](/proxy/?url=https://content.instructables.com/FJ0/KI5J/HABDGM1L/FJ0KI5JHABDGM1L.gif&filename=frame.gif)
![back.gif](/proxy/?url=https://content.instructables.com/F85/ZICW/HA4M4IZO/F85ZICWHA4M4IZO.gif&filename=back.gif)
![minus.gif](/proxy/?url=https://content.instructables.com/FFA/6C0P/HA4MBFI1/FFA6C0PHA4MBFI1.gif&filename=minus.gif)
![neg-mask.gif](/proxy/?url=https://content.instructables.com/FOR/S0TS/HAFHKSJ6/FORS0TSHAFHKSJ6.gif&filename=neg-mask.gif)
![mask.gif](/proxy/?url=https://content.instructables.com/FQ6/ZESJ/HAE69HX9/FQ6ZESJHAE69HX9.gif&filename=mask.gif)
![masked-frame.gif](/proxy/?url=https://content.instructables.com/F79/5A10/HAFHKSJ7/F795A10HAFHKSJ7.gif&filename=masked-frame.gif)
![beach.gif](/proxy/?url=https://content.instructables.com/FQP/G95G/HA4MDCGO/FQPG95GHA4MDCGO.gif&filename=beach.gif)
![masked-beach.gif](/proxy/?url=https://content.instructables.com/FA6/1X3Y/HABC85US/FA61X3YHABC85US.gif&filename=masked-beach.gif)
![final.gif](/proxy/?url=https://content.instructables.com/FJ2/WT9F/HAFHKSJA/FJ2WT9FHAFHKSJA.gif&filename=final.gif)
In order to add a background, I covered the brown card background with blue paper, and took another video of the rotating models. Then with the same lighting I removed the models and took some video of the turntable without moving the camera. Then, using ImageMagick, I subtracted the background image from the foreground and made two masks, a positive and negative.
I then masked out the background in each video frame, masked out the shape of the models in a background picture, and added the two images.
All this goes inside the loop, so each frame is processed separately before being combined in the animated GIF.
$ composite -compose minus back.gif frame.gif minus.gif
$ convert -white-threshold 8000 -gamma 0.3 -colors 2 minus.gif mask.gif
$ convert -negate mask.gif neg-mask.gif
$ composite -compose multiply frame.gif mask.gif masked-frame.gif
$ composite -compose multiply -geometry +50+90 neg-mask.gif beach.gif masked-beach.gif
$ composite -compose add -geometry +50+90 masked-frame.gif masked-beach.gif final.gif
Many video-editing software packages would have this function built-in as "chroma key"
I then masked out the background in each video frame, masked out the shape of the models in a background picture, and added the two images.
All this goes inside the loop, so each frame is processed separately before being combined in the animated GIF.
$ composite -compose minus back.gif frame.gif minus.gif
$ convert -white-threshold 8000 -gamma 0.3 -colors 2 minus.gif mask.gif
$ convert -negate mask.gif neg-mask.gif
$ composite -compose multiply frame.gif mask.gif masked-frame.gif
$ composite -compose multiply -geometry +50+90 neg-mask.gif beach.gif masked-beach.gif
$ composite -compose add -geometry +50+90 masked-frame.gif masked-beach.gif final.gif
Many video-editing software packages would have this function built-in as "chroma key"