Thursday, 28 July 2011

Making videos from photos

There are a lot of ways for make a video from several photos. My camera (a Nikon D3000) can do it automatically with a few pictures. Today I'm going to write about ffmpeg and how to write our own shell script under Linux.

Firstly, you have to download ffmpeg. This software is a powerful command line video edition tool. In Ubuntu Linux you only have to write in console:
sudo apt-get install ffmpeg

After, you must put all the photos that you want include in the video in the same folder. You have to rename them, and numerate them (1.jpg, 2.jpg, etc.). Finally, you must execute ffmpeg with the correct parameters. There are several alternatives, I use this:
ffmpeg -y -f image2 -i %d.jpg -vcodec mpeg2video -s 1920x1080 -aspect 16:9 -b 25000k -g 12 -trellis 1 videoHDVpan.m2t

Am I going too much fast? Don't worry! I'm going to give you a script that do it automatically!
#!/bin/bash
#
#                        J P G 2 V i d
#                        -------------
#
#    The easiest way to make videos from your Nikon's pictures.
#    By Astaroth (O.R.G.).
#    Website:    https://sites.google.com/site/astarothsphotography
#    Blog:        http://asphblog.blogspot.com
#
#
# This script make a high definition vídeo (1920 x 1080) with your photos.
#The names of the photos must be "DSC_####.JPG".
#
clear
echo "********************"
echo "Welcome to JPG2Vid"
echo "********************"
echo " "
echo "This script is made by Astaroth (O.R.G.)."
echo " "
echo "Now must be showed all the frames (and only those frames) you want to include in the final video and the script."
echo " "
ls
echo " "
echo "WARNING: This script DOES NOT work in copy. You must make first a security copy."
echo " "
echo "Press ENTER if you want continue."
read nvpn
# First frame:
pf=`ls | grep -m 1 -o [0-9][0-9][0-9][0-9]`
# Last frame:
uf=`ls | grep -o [0-9][0-9][0-9][0-9] | sed -n '$p'`
echo " "
echo "The frames from DSC_$pf.JPG to DSC_$uf.JPG will be joined."
echo " "
echo "Renaming..."
# Renaming:
j=0
for i in $(seq $pf $uf) ; do
    if [ -e DSC_$i.JPG ] ; then
        j=`echo "$j + 1" | bc`
        mv DSC_$i.JPG $j.jpg
    fi
done
echo " "
echo "The $j frames are ready to be joined."
echo "Making video..."
# Making video:
ffmpeg -y -f image2 -i %d.jpg -vcodec mpeg2video -s 1920x1080 -aspect 16:9 -b 25000k -g 12 -trellis 1 videoHDVpan.m2t
echo " "
echo "FINISHED!"
echo "Thank you very much for use this script :)! Don't forget visit my website:"
echo "https://sites.google.com/site/astarothsphotography"
echo "http://asphblog.blogspot.com"
cvlc videoHDVpan.m2t

You can download it from 4Shared.

All the pictures must be in the same folder that the script, and their names must be "DSC_####.JPG" (it's the typical format for Nikon, but you can modify the code for other cameras).

Correct name format for pictures

The script running

Making the video (with ffmpeg)

The final result is a high definition video (1920x1080) with our animated photos. This is a (bad?) example with the bee pictures that I took recently.


I don't took those photos thinking in making a video. Now, I show a better example: one of my time-lapses:


All the videos of my gallery are made with this script (or similar). The quality is high, and the movement could also be interesting for photographers :). Now you have other way to make your stop-motions and time-lapses :)!

No comments:

Post a Comment

Do you like these pictures? Do you want share your point of view about this post? Would you like ask me anything? Please, comment :)!

LinkWithin

Related Posts Plugin for WordPress, Blogger...