#!/usr/bin/perl # RenderWithStillLife - This is a quick script that will take a existing iMovie project # and convert each still picture in it into a DV clip using Still Life which should # render the picture much better then iMovie will. # # Use at your own risk, backup your project first, it works for me but may destory your project # # Should work with Still Life > 2.2 (tested on 2.2.5) and iMovie > 3 (tested on 4.0.1) # Get Still Life from http://www.grantedsw.com/still-life/ # # Author: Josh Lukens # Version: 1.0 # Date: June 1, 2004 use Strict; use Getopt::Std; use File::Copy; use File::Basename; use Cwd; my $osa = "/usr/bin/osascript"; # Make sure both iMovie and Still Life are closed # my $iMovie = `/bin/ps x | grep 'iMovie.app/Contents/MacOS/iMovie' | grep -v grep`; my $StillLife = `/bin/ps x | grep 'Still Life.app/Contents/MacOS/Still Life' | grep -v grep`; if($iMovie || $StillLife) { print "Please close both iMovie and Still Life before running.\n"; exit -1; } sub usage { print <$new_file") || die "ERROR: Could not create file: " . $new_file; # Figure out next Clip number to use for new files # my $nextnum = `ls Media | grep '^Clip' | awk '{print \$2}' | sort | tail -1`; chomp $nextnum; print "Last clip has number of $nextnum\n" if($opt_v); # Grab full path for media and output files # my $length = length($nextnum); my $full_path = &Cwd::cwd() . "/"; my $outpath = $opt_o || $full_path . "Media"; print "Will place new clips in $outpath\n" if($opt_v); # Set line seperator for old style mac next lines # and loop through each line of the file # my($l,$count,$buffer,$pointer,$found,$format); my($clipname,$stillnumber,$frames,$imagefile,$timestamp); $/="\r"; while($l=) { chomp $l; # Look for start of Clip if($l=~/^Clip: (.*)/) { $count=0; $clipname=$1; $buffer="$l\r"; print "\nFound Clip $clipname\n" if($opt_v); # Loop through entire Clip entry looking for everything # that makes up an image # this is likely more work then needed as these appear to # always come in this order, but this will handle them in any order do { # Save file pointer so we can go back if its a new clip $pointer = tell FILE; $l=; chomp $l; $buffer .= "$l\r" if($l=~/^ /); if($l=~/^ File: Still:(\d*)/) { $stillnumber = $1; $count+=1; } elsif($l=~/^ Type: 4/) { $count+=2; } elsif($l=~/^ Frames: (\d*) In:/) { $frames = $1; $count+=4; } elsif($l=~/^ Attributes: 0 1 0 0 0 0/) { $count+=8; } elsif($l=~/^ StillImage: ([^ ]*)/) { $imagefile = $1; $count+=16; } elsif($l=~/^ StillImageThumb:/) { $count+=32; } elsif($l=~/^ Timestamp: (.*)/) { $timestamp = $1; $count+=64; } } while ($l=~/^ /); # Reset file pointer to the previous line seek(FILE,$pointer,0); # If count is 127 then we got each of the needed properties above if($count == 127) { print " Thinking clip is an image of $frames frames\n" if($opt_v); # Keep track of how many we convert $found++; # Jump through hoops to get a well formated filename $length++ if(($nextnum == 99)||($nextnum == 999)); $nextnum++; $format = '%0' . $length . "d"; $nextnum = sprintf($format,$nextnum); # Do only single frame clips, like iMovie does if($opt_s) { # Not sure about the timestamp thing # but all stills converted by iMovie end in six 0s so we will to $timestamp =~ s/\.\d*/.000000/; print OUT "Clip: $clipname\r File: Clip:$nextnum\r Type: 4\r Frames: $frames In:0 Out:$frames Thumb:0\r"; print OUT " Attributes: 0 1 1 0 0 0\r Timestamp: $timestamp\r"; $frames = 1; } # Do full length clips else { print OUT "Clip: $clipname\r File: Clip:$nextnum\r Frames: $frames In:0 Out:$frames Thumb:0\r"; print OUT " Timestamp: $timestamp\r RecordDate: 1\r"; } # Tell Still Life to make the new clip and set its properties to match iMovies convert_file($full_path . "Media/" . $imagefile,"$outpath/Clip $nextnum",$frames); set_file_info("$outpath/Clip $nextnum","Hway","dvc!"); } else { print " Not an image I recognize\n" if($opt_v); print OUT $buffer; } } else { print OUT "$l\r"; } } close(OUT); close(FILE); if($found) { print "Found and converted $found images.\n"; close_still_life(); if($opt_c) { print "Leaving new file as $new_file\n" if($opt_v); set_file_info($full_path . $new_file,"Hway","TeXT"); set_hide_extension($full_path . $new_file); } else { print "Moving new file to $orig_file, backing up old one to $orig_file.bak\n" if($opt_v); rename($orig_file, $orig_file . ".bak"); rename($new_file, $orig_file); set_file_info($full_path . $orig_file,"Hway","TeXT"); set_hide_extension($full_path . $orig_file); } } else { unlink($new_file); print "No images found in iMovie project.\n"; } # Make a new DV clip from a still image using Still Life # image - Full path to still image # clipname - Full path to output # frames - Number of frames to make clip # sub convert_file { my($image,$clipname,$frames)=@_; $image = '"' . $image . '"'; $clipname = '"' . $clipname . '"'; print " Converting $image to $clipname ($frames frames)\n"; open(OSA,"|$osa") || die "Could not open pipe to $osa"; print OSA </dev/null") || die "Could not open pipe to $osa"; print OSA </dev/null") || die "Could not open pipe to $osa"; print OSA <