need a script to put together the rgb and alpha movie ...

What type of scripts do you need?

Moderator: byronnash

Post Reply
pixelarts
Posts: 11
Joined: September 13th, 2007, 11:15 am

Hi All,

I am currently working on a large number of footage items and various compositions..would some kind soul please write a script for the following work..!!

1.i have around 400 quicktime movies..rendered out separately as rgb straight, and alpha movie
after importing them into a project,i need to put them back together as separate comps, one for each set of movies, that is the alpha movie on top as a luma matte for the corresponding rgb mov.

the movie name is say.. movie_01.mov..and the corresponding alpha movie is named..movie_01_alpha.mov ...and so on..movie_09.mov..movie_09_alpha.mov...

Based on this naming pattern or something, i would like separate comps to be created for each set of rgb/alpha qtime movs ,with the alpha movie on top as luma matte for the similarly named rgb movie.
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

Here is a start, perhaps one of the other scripters can help out.

Launch After Effects and then run the script. It will make comps.

This script will scan the folder, make a 2-layer comp with the alpha movie above the diffuse movie.

But I don't know how to set the alpha layer to become a track matte.

Here is the code:

Code: Select all

  {
	//Functions used by this script.
	function processFile (theFile) 
	{
		writeLn("Processing file: " + theFile.name);
		try 
		{
			var importOptions = new ImportOptions (theFile); //create a variable containing ImportOptions
			importSafeWithError (importOptions);
		} 
		catch( error ) 
		{
			// display errors.
			writeLn(error);
		}
	}
	
	function testForSequence (files)
	{
		var searcher = new RegExp ("[0-9]+");
		var movieFileSearcher = new RegExp ("(mov|avi|mpg)$", "i");
		var parseResults = new Array;
		
		for (x = 0; (x < files.length) & x < 10; x++) 
		{ 
			//test that we have a sequence, stop parsing after 10 files
			var movieFileResult = movieFileSearcher.exec(files[x].name);
			if (! movieFileResult) 
			{
				var currentResult = searcher.exec(files[x].name);
				//regular expressions return null if no match was found
				//otherwise they return an array with the following information:
				//array[0] = the matched string
				//array[1..n] = the matched capturing parentheses
			
				if (currentResult) 
				{ //we have a match - the string contains numbers
					//the match of those numbers is stored in the array[1]
					//take that number and save it into parseResults
					parseResults[parseResults.length] = currentResult[0];
				}
				else 
				{
					parseResults[parseResults.length] = null;
				}
			}
			else 
			{
				parseResults[parseResults.length] = null;
			}
		}
		
		//if all the files we just went through have a number in their file names, 
		//assume they are part of a sequence & return the first file
		var result = null;
		for (i = 0; i < parseResults.length; ++i) 
		{
			if (parseResults[i]) 
			{
				if (! result) 
				{
					result = files[i];		
				}	
			} 
			else 
			{
				//case in which a file name did not contain a number
				result = null;
				break;
			}
		}
		return result;
	}

	function importSafeWithError (importOptions) 
	{
		try 
		{ 
			app.project.importFile (importOptions);
		} catch (error) 
		{
			alert(error.toString() + importOptions.file.fsName);
		}
	}

	function processFolder(theFolder) 
	{
		var files = theFolder.getFiles(); //Get an array of files in the target folder
			
		//test whether theFolder contains a sequence
		var sequenceStartFile = testForSequence(files);
		
		//if it does contain a sequence, import the sequence
		if (sequenceStartFile) 
		{
			try 
			{
				var importOptions = new ImportOptions (sequenceStartFile); //create a variable containing ImportOptions
				
				importOptions.sequence = true;
				//importOptions.forceAlphabetical = true; //un-comment this if you want to force alpha order by default
				importSafeWithError (importOptions);
			} 
			catch (error) 
			{
				// display errors.
				writeLn(error);
			}
		}
		
		//otherwise, import the files and recurse
		
		for (index in files) 
		{ //Go through the array and set each element to singleFile, then run the following
			if (files[index] instanceof File) 
			{
				if (! sequenceStartFile) 
				{ //if file is already part of a sequence, don't import it individually
					processFile (files[index]); //calls the processFile function above
				}
			}
			if (files[index] instanceof Folder) 
			{
				processFolder (files[index]); // recursion
			}
		}
	}
	
	// create project if necessary
	var proj = app.project;
	if(!proj) proj = app.newProject();
	try
	{
			//Begin the script by creating an undo group.
			app.beginUndoGroup("Process Folder Of Track Mattes");

			//Ask the user for a folder whose contents are to be imported
			var targetFolder = folderGetDialog("Import Items from Folder..."); //returns a folder or null
			if (targetFolder) 
			{
				//Create project if necessary.
				var proj = app.project; 
				if(!proj) proj = app.newProject(); 
				
				//Import folder items into the project window.
				processFolder(targetFolder);
				
				//Take advantage of the fact that after footage is imported, it is selected in the project window.
				var projSelection = app.project.selection;	//Set selected import items to an array.
				var myCount = 1;

				//Add footage items from the project window to the composition.
				for (i=0; i < projSelection.length; i++)
				{													//loop through and add layers to comp
					//Create new comp for this footage item.
					var compW = 720; // comp width 
					var compH = 480; // comp height 
					var compL = 240;  // comp length (seconds) 
					var compRate = 29.97; // comp frame rate 
					var compBG = [48/255,63/255,84/255] // comp background color 

					var myItemCollection = app.project.items; 
					var myCompName = projSelection[i].name;	//'my track matte comp'+myCount
					var myComp = myItemCollection.addComp(myCompName,compW,compH,1,compL,compRate); 
					myComp.bgColor = compBG; 				
				
					//Add to comp
					if(projSelection[i] instanceof FootageItem)
					{												//test to be sure it's not a comp or folder
						var tempCollection = myComp.layers;					//variable for collection of layer objects in the comp
						thisImageLayer = tempCollection.add(projSelection[i]);		//Add diffuse layer.
						thisImageLayer.trackMatteType.ALPHA
						thisImageLayer = tempCollection.add(projSelection[i+1]);		//Add alpha layer, assume it was imported right after the diffuse layer.
						
					}
					//Make our loop step by 2 to skip adding the alpha again.
					i++;
					myCount++;
				}
				//Blank our folder to prevent a re-run of this script from failing on a browse cancel.
				targetFolder = "";
				writeLn("Finished folder items.");
			}
			else
			{
				writeLn("User cancels import operation.");
			}
			app.endUndoGroup();
	}
	catch(error)
	{
		writeLn ("Select the comp in the project window be fore running this script.");
	}
}	
This line:

Code: Select all

thisImageLayer.trackMatteType.ALPHA
is where revision needs to occur. For some reason, it does not actually set the layer to ALPHA track matte type. It does not produce an error either. Perhaps someone else can figure this out?

Good luck...
Last edited by Atomic on September 14th, 2007, 2:38 pm, edited 1 time in total.
pixelarts
Posts: 11
Joined: September 13th, 2007, 11:15 am

Hi Atomic !


Man, you are a life saver!your script wil save me half my labour at least!
i just wish the newly created comps could take the names from thier rgb files..but again thanks a lot!!
User avatar
Atomic
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

pixelsarts,

This small change to the script will name them as you request.

Code: Select all

var myCompName = projSelection[i].name;			
var myComp = myItemCollection.addComp (myCompName,compW,compH,1,compL,compRate); 
I have updated the original post to reflect this change.

If only someone would pop in with the assign as track matte solution...
pixelarts
Posts: 11
Joined: September 13th, 2007, 11:15 am

Hi Atomic,

Thanks again ! much apprciated!
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

I've made some changes to Atomic's script. It seems to work ok.

Code: Select all

{ 
	//Functions used by this script. 
	function processFile (theFile)
	{ 
		writeLn("Processing file: " + theFile.name); 
		try
		{ 
			var importOptions = new ImportOptions (theFile); //create a variable containing ImportOptions 
			importSafeWithError (importOptions); 
		} 
		catch( error ) 
		{ 
			// display errors. 
			//writeLn(error); 
		} 
	} 
    

   function importSafeWithError (importOptions) 
   { 
      try 
      { 
         app.project.importFile (importOptions); 
      } catch (error) 
      { 
         //alert(error.toString() + importOptions.file.fsName); 
      } 
   } 

	function processFolder(theFolder) 
	{ 
		var files = theFolder.getFiles(); //Get an array of files in the target folder 
          
		for (index in files) 
		{ //Go through the array and set each element to singleFile, then run the following 
			if (files[index] instanceof File && files[index].name != ".DS_Store") 
			{ 
				processFile (files[index]); //calls the processFile function above 
			} else if (files[index] instanceof Folder) 
			{ 
				processFolder (files[index]); // recursion 
			} 
		} 
	} 
	
	// global variables
	var mainLayer, alphaLayer;
	var compW, compH, compL, compRate, compBG, compPixelAspect;
	var myItemCollection, tempCollection, myCompName, myComp;

	//Ask the user for a folder whose contents are to be imported 
	var targetFolder = folderGetDialog("Import Items from Folder..."); //returns a folder or null 
	if (targetFolder) 
		{ 
		//Begin the script by creating an undo group. 
		app.beginUndoGroup("Process Folder Of Track Mattes"); 
			
		//Create project if necessary. 
		var proj = app.project; 
		if(!proj) proj = app.newProject(); 
             
		//Import folder items into the project window. 
		processFolder(targetFolder); 
             
		//Take advantage of the fact that after footage is imported, it is selected in the project window.
		var projSelection = app.project.selection;   //Set selected import items to an array. 
		var myCount = 1; 

		//Add footage items from the project window to the composition. 
		for (i=0; i < projSelection.length; i++) 
		{                                       //loop through and add layers to comp 
			//Create new comp for this footage item. 
			compW = projSelection[i].width; // comp width 
			compH = projSelection[i].height; // comp height 
			compL = projSelection[i].duration;  // comp length (seconds) 
			compRate = projSelection[i].frameRate; // comp frame rate 
			compBG = [48/255,63/255,84/255] // comp background color 
			compPixelAspect = projSelection[i].pixelAspect; // pixel aspect ratio

			myItemCollection = app.project.items; 
			myCompName = projSelection[i].name;   //'my track matte comp'+myCount 
			myComp = myItemCollection.addComp(myCompName,compW,compH,compPixelAspect,compL,compRate); 
			myComp.bgColor = compBG;              
             
			//Add to comp 
			if(projSelection[i] instanceof FootageItem) 
			{		//test to be sure it's not a comp or folder 
				tempCollection = myComp.layers;		//variable for collection of layer objects in the comp 
				mainLayer = tempCollection.add(projSelection[i]);		//Add diffuse layer. 
				alphaLayer = tempCollection.add(projSelection[i+1]);		//Add alpha layer, assume it was imported right after the diffuse layer. 
				mainLayer.trackMatteType = TrackMatteType.LUMA;
			} 
				
			//Make our loop step by 2 to skip adding the alpha again. 
			i++; 
			myCount++; 
				
		} 		
		app.endUndoGroup(); 
	}
}
   

pixelarts
Posts: 11
Joined: September 13th, 2007, 11:15 am

Hello paul,

checked your script, as you said, its working flawlessly.
thanks a lot !
Humlan
Posts: 8
Joined: August 29th, 2004, 5:37 pm
Location: Sweden
Contact:

I removed this post and put it into a new thread here:
http://www.aenhancers.com/viewtopic.php?p=3144
Simma
Posts: 98
Joined: June 8th, 2010, 2:57 pm

Just tried this and it works great on CS4!

I'm looking for a script that does exactly what it already does, but the names would be i.e clip01 and clip01_bg. No alpha. To clip01 an animation preset would be applied that keys the top layer. Would this be hard to do? Also, how would I do to get it to work in CS5?
Simma
Posts: 98
Joined: June 8th, 2010, 2:57 pm

Oh, it actually puts the clip01 above the clip01_bg layer already. Now I would only need to apply a animation preset to the top layer and get it to work in CS5. Ideas?
Simma
Posts: 98
Joined: June 8th, 2010, 2:57 pm

Sorry for all the posts, I got exited of a possible workflow improvement. I managed to add an animation preset.

Is there a lot of work to convert it to work in CS5?


Example script attaced.
Attachments
test01.jsx.zip
(1.56 KiB) Downloaded 901 times
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

I imagine it's just because you're using folderGetDialog which no longer works in CS5. Use Folder.selectDialog instead. Here's a link to the CS5 scripting changes where this is mentioned:
http://blogs.adobe.com/toddkopriva/2010 ... r-eff.html
Simma
Posts: 98
Joined: June 8th, 2010, 2:57 pm

Thank you Paul, that worked perfectly! :)
Post Reply