May 22, 2020
My kids bought one of these terrible books at a school book fair. By terrible, I mean the type that cost a lot for not a lot of content. To add insult to injury, this book was about making stop-action movies with Legos™, only provided one minifigure, discussed the set design aspect and totally skimped on getting the technicals aspect of getting all of the hardware and software components to work. When I was attempting to help my kid get the first video made, my frustrations just got bigger.
The book suggested using a smart phone camera or a point-and-shoot camera. I wasn’t going to turn over my phone to my kid (sorry, kid), and only had a DSLR camera in the other category (ok, same, sorry kid). I thought a webcamera would be the best option, but even then, auto focus screws up some shots. Some webcam viewers had a bug where some frames had a blue cast to them. Our family is now a 100% linux house, so how do you shoot the video and edit it in that environment?
I’ll quickly take you through our family’s protocol. At this point, both kids can set up their scenes and grab the images by themselves. The older kid’s videos are more elaborate, and acquiring the images takes about 45 minutes. Then I put the videos together from the image files (create).
My kids have been on a Lego kick, but you can use any toys you like. We had this long sequence with a wooden train set once – getting the train to go down the hill, one frame at a time, was a fun challenge.
Figure 1. An illustration of our image acquisition setup: cheap laptop, webcam with mini tripod, a background (here, a dry-erase board), and subjects for the movie. We also use the tripod in its more traditional, upright configuration.
The computer is a cheap laptop that the kids are allowed to use. Then we have a mini-tripod for the webcam. The webcam, when I bought it, was ~$40, and is of Logitech brand. We tried a bunch of free webcam acquisition tools and settled on kamerka. In Ubuntu, install:
sudo apt install kamerka
While kamerka worked the best for this project, there are some quirks on the limited laptop we use. Adjust the resolution of the images to the maximum for that camera to get the best quality images for the camera you have. Then resize the kamerka window to be sort of small – we’ve had freezing otherwise (I know, this is a great advertisement!). From here, the kids seem to be able to set up their shot, click through on ‘Take a photo’, and go to the next shot. The laptop we use is a touch-screen, so they can even use their finger.
Kamerka conveniently numbers the images
image%d.png, which comes in handy for the next step.
To create the videos from the images, I use the not-very-intuitive command-line-tool ffmpeg. This link will take you to the download page for various OS’s, and in Ubuntu, install is
sudo apt install ffmpeg
I’ve used ffmpeg for lots of things. I never remember any of the options, and just keep lots of notes with projects that require it. Like this one!
In the case you used kamerka, you get images with a nice image numbering and short filenames. Assuming that your first image was in the range 0-4 (this is what the error message says ?!), you can run
ffmpeg -framerate 6 -i 'image%d.png' \ -c:v libx264 -r 6 -pix_fmt yuv420p out.mp4
in this example, the framerate is 6 frames per second (
-framerate flag), and the resulting .mp4 video also has 6 frames per second (
-r flag). I haven’t been able to find good documentation on the framerate flag – this is my best guess from experience.
You might have a different image naming pattern, in which case you can use the
glob input pattern.
ffmpeg -framerate 6 -pattern_type glob -i '*.png' \ -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
Here you will notice the output video has a 30 frames per second (fps) framerate, even though 6 fps was used as the input.
With kamerka, the number of the images will keep going up over time. This is fine. Just add a flag when you create the videos:
-start_number. In this example, the first image was number 606.
ffmpeg -start_number 606 -framerate 6 -i 'image%d.png' \ -c:v libx264 -r 6 -pix_fmt yuv420p out.mp4
Sometimes the scenes will get a little too rushed, and you can slow those sections down, and then concatenate the video sections together. Your kid(s) can be involved in saying which frames are involved at what rates – it is their movie, after all.
So suppose the first section is shot at the normal rate:
ffmpeg -start_number 606 -framerate 6 -i 'image%d.png' \ -frames:v 64 -c:v libx264 -r 6 -pix_fmt yuv420p part1.mp4
I use flag
-frames:v 64 to indicate that this section is 64 frames long. That’s how you indicate to ffmpeg a ‘stop frame’ point.
Then suppose the next section gets a little wild with background changes, too much action to follow, whatever. We slow the framerate down to 3 frames per second, and start it where the previous section stopped (
ffmpeg -start_number 672 -framerate 3 -i 'image%d.png' \ -c:v libx264 -r 6 -pix_fmt yuv420p part2.mp4
Now comes the glue – we need to convert the two parts to an intermediate format (.ts), and then concatenate them together:
ffmpeg -i part1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1.ts ffmpeg -i part2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2.ts ffmpeg -i "concat:temp1.ts|temp2.ts" -c copy -bsf:a aac_adtstoasc all.mp4
Note: you can do this with as many sections as you have, not just two.
Creating a video from an image is easy:
ffmpeg -loop 1 -i image606.png -c:v libx264 -t 4 -r 6 out.mp4
In this example, the duration of the video will be 4 seconds (
-t 4) and the video fps is 6 (
-r 6). To add this to your other videos, see recipe 4.
I have done this to create title cards for the webinar series I host. I take a screenshot of a slide in beamer/latex, and create a 5 second title card. An example is here (YouTube).
I use ffmpeg a lot to compress video. Adjust the
-crf flag to do so. Larger values result in MORE compression. I start with 24 and adjust up until I get a small enough-sized video, with decent visual quality.
ffmpeg -i input-vid.mp4 -vcodec libx264 -crf 24 output-vid.mp4
A I mentioned previously, there’s no need to be constrained by Legos. You can use any toy as your subject.
Figure 2. Flying characters using fishing line.
The kids have used fishing line to create flying characters (Figure 2). Then, they can argue (collaborate?) about how to hold the line while one of them is capturing the images.
Figure 3. Sound-effect captions written on the dry-erase board (combined with flying objects).
We have been using dry-erase boards around our house since school was put on hold (covid-19), and they used one as a background and then write the characters’ dialogue on the board, as in the video above. This was a neat addition. They have also used the whiteboard to express sound effects. In Figure 3, the girl’s hair popped off.
© Amy Tabb 2020-2020. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.