Batch processing large number of images

I have an image sequence of 34,000 jpeg images (640x480) and I want to get these into a quicktime sequence. Opening this sequence from quicktime obviously crashes it.

I wrote an applescript that makes a list of images within a folder, splits them up into groups of 500 into a new folder, then makes 68 videos (each with 500 images) as quicktimes. Later I stitch all of these movies together into 1.

The big problem I have is getting a list of all the files to process. Currently it times out, and so I set the timeout rate to some very high number, but the apple event for getting a list of files still takes too long and doesn’t complet. I’ve been running it for timeout of 50000 secs and still no joy.

It looks like this:


tell application "Finder"
    with timeout 50000 seconds
       set imageFiles to files in rootFolder
    end timeout
    with timeout 50000 seconds
       set imageCount to the number of files in rootFolder
    end timeout
end tell

Any ideas the best way to do this?

Thanks

Try this instead…

Peter B.



with timeout of 50000 seconds
	tell application "Finder"
		set imageFiles to files in rootFolder
		set imageCount to the number of files in rootFolder
	end tell
end timeout

I had already tried it that way first.

It timesout on
set imageFiles to files in rootFolder

either way.

thanks

Hi Peter,

your code wastes also a lot of time, because the Finder must parse (needlessly) the folder twice
and Apple Events are always expensive

Either


with timeout of 50000 seconds
	tell application "Finder" to set imageFiles to files in rootFolder
end timeout
set imageCount to the number of imageFiles

or

with timeout of 50000 seconds
	tell application "Finder"
		tell (files in rootFolder) to set {imageFiles, imageCount} to {it, count it}
	end tell
end timeout

retrieves the files only once.
In the first example counting the items of a list variable is much faster than sending Apple Events to an appliction

Oh, well… I’m glad someone’s around to catch my mistakes… (which occur often).

Thanks, Stefan.

Peter B.


I’ve tried this one


with timeout of 50000 seconds
   tell application "Finder" to set imageFiles to files in rootFolder
end timeout
set imageCount to the number of imageFiles

But it still takes too long and hangs :frowning:

Would something like this work?


set imageFiles to paragraphs of (do shell script "ls " & quoted form of POSIX path of rootFolder)

repeat with i from 1 to count of imageFiles
	set thisFile to item i of imageFiles
	set thisFilePath to (rootFolder & thisFile) as string
end repeat

Hi,

for your purpose it’s not necessary to get all files into a list. I assume, that they are numbered sequentially,
so it’s sufficient to process the files by number

I couldn’t test the following script, because I don’t have this amount of pictures, but
it should create two new folders at desktop then duplicate in a repeat loop 500 files
into the pictures folder and creates the movie in the video folder.
Each mov file has the filename of the first picture of the sequence


set rootFolder to choose folder
set imageFiles to paragraphs of (do shell script "ls " & quoted form of POSIX path of rootFolder)

tell application "Finder"
	set imagesFolder to (make new folder at desktop with properties {name:"images_temp_folder"}) as alias
	set videoFolder to (make new folder at desktop with properties {name:"video_temp_folder"}) as alias
end tell

repeat with i from 1 to (count imageFiles) div 500
	set j to (i - 1) * 500
	tell application "Finder"
		try
			duplicate files (1 + j) thru (500 + j) of rootFolder to imagesFolder
		on error
			duplicate files (1 + j) thru -1 of rootFolder to imagesFolder -- error occurs, if the last portion of files is less than 500
		end try
		tell (get 1st file of imagesFolder) to set {firstPicture, fPName} to {it, its name}
	end tell
	tell application "QuickTime Player"
		activate
		open image sequence (firstPicture as alias)
		tell document 1
			export to file ((videoFolder as text) & fPName & ".mov") as QuickTime movie
			close saving no
		end tell
	end tell
	tell application "Finder" to delete files of imagesFolder
end repeat

Note: the bottleneck is the process to duplicate the files, maybe someone finds a shell version which works faster

Hi chriso,

If you are running Mac OS X 10.5 Leopard or a Mac OS X where PyObjC is installed, then you can also opt for a command line solution that doesn’t require AppleScript and not even a copy of QuickTime Pro. And my wild guess is that it will be significant faster than a pure AppleScript solution interacting with the Finder.

You can find a Python script for creating image sequences right here on MacScripter, it is part of a recent project that I did for my employer. Now if you combine this script with another one managing the image files, that could become a powerful workflow.

Just my 2 cents :wink: