One of the problems with scripting is getting the duration of each clip.
I worked out a solution for a guy who wanted to create a bunch of Shake
scripts for applying the same time-stretching to each clip. Here’s a
summary of how I did it. Maybe you’ll find it interesting or useful:
My solution involves learning bash.
Bash is a super nerdy unforgiving scripting environment. However,
if you do a lot of command-line Shake in a large production environment,
it seems to be extremely useful, so I would like to share what I learned
last week. After all, sooner or later we all need to process a bunch
of files through the same Shake script.
Basically bash is a way of taking a bunch of command lines,
and combining them into something you can run as a program.
Here are two excellent resources for learning:
http://www.ibm.com/developerworks/library/l-bash.html
http://www.grymoire.com/Unix/
These two sites are awesome.
__________EXAMPLE ONE
Every bash script includes this line:
#!/bin/sh
Then you just start adding UNIX and/or bash commands.
So copy these two lines into a plain text editor window
and save them as amnesia.sh
#!/bin/sh
whoami
In Terminal you can run your new program!
Use cd to navigate to where amnesia.sh is,
and type
bash amnesia.sh
You will be reminded of your identity.
__________EXAMPLE TWO
Jumping ahead really quickly, here’s a technique for
making a loop that will call up the name of
every Quicktime movie in a folder and send
it to some function in your bash script:
cd ./folder_containing_movies
for i in $(find . -name ‘*.mov’);
do
my_fi=basename $i
my_function $my_fi
done
__________EXAMPLE THREE
Now we’ll define that function: it prints out the name of the movie.
This part of the script must be above the loop
from which it is called.
So here’s the complete bash script:
#!/bin/sh
my_function ( )
{
echo $my_fi
}
cd ./folder_containing_movies
for i in $(find . -name ‘*.mov’);
do
my_fi=basename $i
my_function $my_fi
done
__________EXAMPLE FOUR
In order to have shake do something with these movies,
you could, in the example above, replace
echo $my_fi
with
shake $my_fi
but then you’d just get the first frame, and you’d
have to quit each Viewer to see the next movie.
For normal fully-tweaked dozens-of-nodes Shaking, one would use
shake -exec my_script.shk
The problem is that it’s difficult (impossible?) to pass variables
like my_fi into my_script.shk. I was unable to do it–
probably because I’m just a beginner–
so I used bash to replace key words in a template,
scriptTemplate.shk, to write one shake script for each movie.
To do this, you need to replace parameters in the Shake script
with words that can be searched and replaced. In your Shake
template, the FileIn filename can be something like SEDmy_fi.
In bash you can use the sed command to search and replace
the expressions in the template:
sed -e ‘s/SEDmy_fi/’$my_fi’/g’ scriptTemplate.shk > ./scripts_out/${my_fo}.shk
This does the search and replace, then writes a shake script
named automatically by my_fo, another variable you’ve created:
my_fo=echo $my_fi | sed 's/.mov/_output/'
__________EXAMPLE FIVE
At this point your head is totally spinning. Don’t worry.
This is not a tutorial; I’m just trying to sketch out
the broad ideas here. You’ll still have to learn bash
for this to make sense.
As a special bonus, here’s a really useful bash command I stole from Olli
at vfxtalk.com to get the timerange of a movie using shake -info :
timerange=shake ./folder_containing_movies/$my_fi -info 2>&1 | grep Duration | sed 's/info: Duration: //'
You could then use $timerange elsewhere in your bash script.
Les