Tuesday, May 3, 2011

Assignment 4.3

So, here is the completed assignment 4.3 or a finishing up of the test from the last class. In the command line, you enter the name of the script (for example, ./makeNewMovie.sh), then it takes the command line arguments of what movie you want to run the script on and another parameter of whether you want the frame counter. The user has to put in that parameter of whether they want the frame counter, so if they don't they should put something like no. If you don't give the command any arguments, it'll spit back "I need a movie to use" and exit the script. The user can put in any mogrify command they want, such as -charcoal 5.

#!/usr/bin/bash

#These are the command line arguments that the user puts in when calling the script
#This is the name of the movie you give
MOVIE=$1
#This is the mogrify or convert command you want
STRING=$2
#This is where the user tells if they want the frame counter. They have to put frame in the command if they want to use it. They have to write something
TEXT=$3
#If the command line has no arguments...
if [ $# == 0 ];
then
echo I need a movie to use
exit
fi
#It tells the user it needs a movie and exits
echo Processing the video called: $MOVIE

#This will streamline the image files it dumps out
FRAMEPRE=${MOVIE}-frame-
echo I will call the frames this:- $FRAMEPRE -with frame numbers following

#This dumps out the frames
ffmpeg -i ${MOVIE} -r 24 -s 640x360 -f image2 ${FRAMEPRE}%04d-expelled.png

#This compiles the dumped frames into a variable
FRAMES=`ls *expelled.png`
#Set I that we will increment in the loop
I=1

#For every object in the variable FRAMES
for FRAME in $FRAMES
#start the loop
do
#This does what the person wants to do, any string is fine. Imagemagick is preferable
${STRING} $FRAME
#This is for the third argument. The user has to put in SOMETHING or it won't work. They could put no for example.
if [ $TEXT == frame ];
then
#This puts the frame counter on
mogrify -pointsize 16 -font courier -annotate +50+50 "Frame ${I}" $FRAME
fi
#This renames all the expelled names to flop names
NFN=`printf "${FRAMEPRE}%04d-flop.png" $I`
#Increment the loop
I=$(($I+1))
#This moves FRAME to NFN or new file name
mv $FRAME $NFN
#This converts the .png to jpg. I found this gave the movie the best quality than just doing .jpg Just .png gives weird blue fragments
convert $NFN $NFN.jpg
echo converting frame $I
#cp $FRAME $NFN
done

#This compiles the movie at a rate of 24fps
ffmpeg -f image2 -r 24 -s 640x360 -i ${FRAMEPRE}%04d-flop.png.jpg RedoneMovie.mov
#These 2 remove all of the images, so you are left with just the original movie and the changed movie
rm *.png
rm *.png.jpg

This is the original movie that I put in (an image of it).


And this is the movie that the script made.

No comments:

Post a Comment