PDA

View Full Version : Applescript Quicktime Open Image Sequence


ghull27
11-20-2006, 04:35 PM
Hi,

I have a series of many folders containing individual image sequences that I would like to make movies out of using quicktime pro. Given the large number of folders I must do this for I would like to automate the task with applescript if possible. Unfortunately I have no experience with the language and don't quite know where to start. Can anyone provide any help to get started with this project? I imagine it shouldn't be difficult for someone with some applescript experience, and I'd really appreciate the help!

Thank you!

davidw
11-25-2006, 12:22 AM
not enough details man
see if you can do the whole process using only the keyboard,
if so you will very easily be able to script your operation.

capitalj
11-25-2006, 10:24 AM
You could try this folder action.

Attach it to an empty folder, then drop folders of image sequences onto that folder. The movie will be saved inside the image sequence folder, with the first image's name as the movie name.

Hope that helps.

on adding folder items to thisFolder after receiving droppedFolders
repeat with aFolder in droppedFolders

tell application "Finder" to set theSequence to (get first file of aFolder as alias)

tell application "QuickTime Player"
activate
open image sequence theSequence

set nameSequence to (theSequence as string) & ".mov"

tell movie 1
with timeout of 500 seconds
save self contained in nameSequence
end timeout

close

end tell
end tell

end repeat
end adding folder items to

ghull27
11-27-2006, 12:34 PM
Thanks, this helps a lot. hope it wasn't too much trouble

jan_sobie
12-07-2006, 11:46 AM
This seems very helpful for me as well, but I've encountered a problem. This script doesn't give the possiblity to set the framerate to 25, which is vital for me. I've checked the applescript dictionary on this and here's what I get :

"open image sequence file : the file representing first image of the image sequence
[frames per second real] : the number of desired frames per second
[seconds per frame real] : the duration of each frame in seconds"

Looks obvious..but.. I can't figure out how or where to enter the values on this.
Any ideas ?
Thx
Jan

hayne
12-07-2006, 12:48 PM
From that dictionary info, I think you just put the "frames per second" immediately following the filename in the "open image sequence" command.

E.g. here's an example from: http://news.lugnet.com/trains/?n=19805&t=i&v=a
(which I found by googling for: "open image sequence" "frames per second")

open image sequence thePath & ".1" frames per second 25

capitalj
12-07-2006, 12:57 PM
Hayne found the answer before I did.

on adding folder items to thisFolder after receiving droppedFolders
repeat with aFolder in droppedFolders

tell application "Finder" to set theSequence to (get first file of aFolder as alias)

tell application "QuickTime Player"
activate
open image sequence theSequence frames per second 25

set nameSequence to (theSequence as string) & ".mov"

tell movie 1
with timeout of 500 seconds
save self contained in nameSequence
end timeout

close

end tell
end tell

end repeat
end adding folder items to

jan_sobie
12-08-2006, 05:00 AM
woow
Thx lads.
This makes my life quite a bit easier.

Don't know if I could bother you with one more question on this script. But is there any code I could enter to save the quicktimes in the folder above the sequencefolder, so, inside the actual folder action place ?

I tried setting it as :
save self contained in "hard disk:document: etc..." but then it just asks me if I want to save 'untitled'
;-)
Jan

capitalj
12-08-2006, 10:53 AM
Not a problem.

This script could be condensed, but then you would have a harder time seeing what it does. And it could use some tweaking and error checking (make sure the name isn't too long or a file won't be overwritten) but you can tinker - and ask for help again if you need it.

Check out MacScripters for more AppleScript information and help - http://bbs.applescript.net/

on adding folder items to thisFolder after receiving droppedFolders
repeat with aFolder in droppedFolders
tell application "Finder"

set folderPath to container of aFolder as alias
set theSequence to (get first file of aFolder as alias)
set sequenceName to name of theSequence
set savePath to folderPath & sequenceName

end tell


tell application "QuickTime Player"
activate
open image sequence theSequence frames per second 25

set savePath to folderPath & sequenceName

set nameSequence to (savePath as string) & ".mov"

tell movie 1
set preferred rate to 0.5 as real
with timeout of 500 seconds
save self contained in nameSequence
end timeout

close

end tell
end tell

end repeat
end adding folder items to

To get a better idea of what's happening, run this version (not a folder action) from Script Editor after clicking "Event Log" on the bottom.

set aFolder to choose folder
tell application "Finder"

set folderPath to container of aFolder as alias
set theSequence to (get first file of aFolder as alias)
set sequenceName to name of theSequence
set savePath to folderPath & sequenceName

end tell


tell application "QuickTime Player"
activate
open image sequence theSequence frames per second 25

set savePath to folderPath & sequenceName

set nameSequence to (savePath as string) & ".mov"

tell movie 1
set preferred rate to 0.5 as real
with timeout of 500 seconds
save self contained in nameSequence
end timeout

close

end tell
end tell

marks47
12-10-2006, 03:57 AM
Hey, this is great, and well-timed. I need to set up something to do this automatically with images being pulled off a webcam and then transferred to an ftp site, which I'll probably do with expect...

How do you set a particular folder in the script, where the images will be stored?
ie-I can't have "choose folder" in there...
-thanks...

nik_it
05-26-2008, 11:01 PM
Thanks for the inspiration capitalj - I have been able to use it as well.. but have some challenges.

I used the following

tell application "QuickTime Player"
activate
open image sequence "/Pictures/photo1.jpg" frames per second 10
save self contained document "Untitled" in "/Movies/testmovie.mov"
end tell

In applescript in automater using Leopard - and it works BEAUTIFULLY!

My challenge is that I need to use the script on a machine that is running 10.4. but it throws an error:
QuickTime Player got an error: NSReceiverEvaluationScriptError: 4

It starts up Quicktime ok but doesn't seem to open the image sequence let alone store the file. Any idea what it could be?

Thanks in advance!

capitalj
05-27-2008, 11:08 AM
Hello nik_it

The first problem I see is that you used the POSIX path (with slashes, a bit about them here (http://www.satimage.fr/software/en/smile/external_codes/file_paths.html)) and the second is that the path is incomplete. Assuming your pictures folder is in your home folder, this:
"/Pictures/photo1.jpg"
should look like this:
"Macintosh HD:Users:YourUserNameHere:Pictures:photo1.jpg"

so your script should be:--replace YourUserNameHere with your actual user name

tell application "QuickTime Player"
activate
open image sequence "Macintosh HD:Users:YourUserNameHere:Pictures:photo1.jpg" frames per second 10
save self contained document "Untitled" in "Macintosh HD:Users:YourUserNameHere:Movies:testmovie.mov"
end tellThis works in 10.4.11 (money for the Leopard upgrade keeps getting spent on other things) using Script Editor - I don't know how you are using it in Automator, so I hope that's enough to get you going.

I've never tried using "save self contained document "Untitled" in..." before, so I learned something today, thanks.

nik_it
05-27-2008, 05:27 PM
capitalj - thanks a million for the quick reply.

I actually created folders under the root (Mackintosh HD:Pictures and Mackintosh HD:Movies) just to see if my path was the problem. I can move them back to the home folder and try your suggestions.

This works in 10.4.11 (money for the Leopard upgrade keeps getting spent on other things) using Script Editor - I don't know how you are using it in Automator, so I hope that's enough to get you going.

Automator allows me to add a section that is applescript - it looks like Script Editor. The cool part is that I can add other actions around it without having to learn too much applescript. You can even pass variables!

I've never tried using "save self contained document "Untitled" in..." before, so I learned something today, thanks.

You are welcome! It worked beautifully in Leopard even using the POSIX. path.

nik_it
05-27-2008, 11:46 PM
I'm afraid your suggestions didn't show any change...

This is so frustrating.. I can't get Quicktime to do ANYTHING with the Script Editor aside from
activate application "QuickTime Player"
and
tell application "QuickTime Player" to quit

I can't even get it to open and existing file, let alone play it or open an image sequence... I can do them on the 10.4 machine from within Quicktime, I just can't automate it...

I tried a one line of code approach, opening Quicktime and then executing
tell application "QuickTime Player" to open image sequence "Mackintosh HD:Users:UserName:Pictures:inside:inside1.jpg" frames per second 10
but nothing happens... no errors no nothing.

Do you have any ideas what I could be doing wrong or what I should test?

capitalj
05-28-2008, 07:38 AM
I tried a one line of code approach, opening Quicktime and then executing
tell application "QuickTime Player" to open image sequence "Mackintosh HD:Users:UserName:Pictures:inside:inside1.jpg" frames per second 10
but nothing happens... no errors no nothing.

Do you have any ideas what I could be doing wrong or what I should test?I often use "choose file" while working on my scripts because my typing is terrible and sometimes the error isn't obvious. I mention this because I pasted your code into Script Editor, recreated that path on my computer, and nothing happened - then I noticed the misspelling of "Macintosh HD" (no "k" in Macintosh ;)). As soon as I corrected the misspelling, it worked for me.

nik_it
05-28-2008, 11:50 PM
Thanks capitalj - you certainly helped but it wasn't exactly what you said... you see - I had renamed my HD to "BigD" but changed the name to the more standard Macintosh HD (at least that was my intent ;-) after pasting the code into the example.

But after your post, I decided to see what the Mac gave me as a path if I asked automator to select the file. So in automator I created a short script

Get Specified Finder Item
View Results

Here's what I got: {alias "BigD :Pictures:inside1.jpg"}

So it does work having the Pictures folder under the root - for some reason, it inserted a space after the HD name and I had no idea...

Thanks a million! It works now!

m!tch
11-19-2008, 12:46 PM
Hi,
I'm digging up this thread because I've a quite similar case...
I'm a total noob at scripting so I didn't understand everything that was said here...
anyway here's my problem/workflow need:

I have a lot of image sequences conversion to do using Quicktime so what I do is open the first sequence and export it with the Apple ProRes codec under the same name than the sequence... and I've to do this twice, first time in HD 1080 then in PAL letterboxed (720*576)

now first of all, the naming part. my sequences are named like this "040_002_v03.01.jpg" and I just want to keep the first part with the underscores and remove the ".XX.jpg" part.
The scripts showed above keep all of the name and just add .mov at the end of it...

then I wonder if it is possible to "recognise" all the sequences present in a folder because I have like 100 sequences under the same folder sometimes and ultimately what I was hoping was to make a droplet (or 2) on which I would just drag a folder full of images and let it sort the sequences by name.

well then of course you have the export process. Can one script something like the choice of a particular codec and image size and ratio?
I've found somewhere an automator action which export a movie sequence through the last prefered output options and that would also work for me since I only use one at a time...

Of course I'm not asking for a ready-to-use script response but for someone to tell me what would be possible and what would not as I will try to mix automator actions and applescript...

thanks for your time reading this, hope you would excuse my grammar mistakes...

BabaG
12-23-2008, 03:41 AM
do i understand this correctly?

i attached the following version of one of these scripts to a folder, directly
copied from the above, previously posted version, and absolutely nothing
happens when i copy items to the folder. i lie. if i copy the first file of an
image sequence to the folder, the file simply appears in the new location.
if i drop the entire image sequence folder into the folder with this script
attached, the sequence folder disappears from the finder and qt player
never opens. i have to cmd-z to get the folder back.

on the other hand, if i run the script from the editor, qt player opens the
sequece as expected and renders out a mov file.

am i missing something? am i not correct that i should simply drop my
sequence folder into the folder with this script attached to have a mov
automatically generated from the contained sequence?

script editor Version 2.2 (2.2)
osx 10.5.5

thanks (complete n00b to this, btw),
BabaG


set aFolder to choose folder
tell application "Finder"

set folderPath to container of aFolder as alias
set theSequence to (get first file of aFolder as alias)
set sequenceName to name of theSequence
set savePath to folderPath & sequenceName

end tell


tell application "QuickTime Player"
activate
open image sequence theSequence frames per second 25

set savePath to folderPath & sequenceName

set nameSequence to (savePath as string) & ".mov"

tell movie 1
set preferred rate to 0.5 as real
with timeout of 500 seconds
save self contained in nameSequence
end timeout

close

end tell
end tell

Cmd
06-17-2010, 08:15 PM
These are great time saving solutions but not what I'm looking for exactly. I would like to create an automator action most likely with a custom apple script I'm assuming to create a movie from a selected folder and name the movie the name of the folder and save it in the directory of that folder. The reason being is this takes one step away from having to copy and paste the contents of a folder into the drop bin folder as the examples above and also I don't need to name the image sequence anything other than the image numbers. Also, I'm usually rendering off multiple sequences at a time so I can't just render to that folder.

It would be great if all I had to do is select the folder, right click on it and select the workflow from automator and it would save the contents as the name of the folder. It just seems like it would be better in my case.

This thread is quite old but I'm hoping that someone is still watching it. Your help would be greatly appreciated. Thanks!

capitalj
06-18-2010, 08:31 AM
With Snow Leopard and QuickTime 7, create a service in Automator using the "Run Applescript" action, and paste in following script (read through the thread to set frames per second if you need to).

Pre-Snow Leopard and with QuickTime Pro (if memory serves correctly), change "QuickTime Player 7" to "QuickTime Player" and save the workflow as a plugin.

tell application "Finder" to set theSequence to (get first file of (input as alias) as alias)

tell application "QuickTime Player 7"
activate
open image sequence theSequence

set nameSequence to (theSequence as string) & ".mov"

tell document 1
with timeout of 500 seconds
save self contained in nameSequence
end timeout

close

end tell
end tell

Cmd
06-18-2010, 10:30 PM
Thank you capitalj!

That worked great. The only thing is I might have not explained myself correctly when it comes to naming the file. I want it to be the same as the folder that I'm selecting that contains the files. So right now the script names it the name of the first file in the folder and saves it in the folder. So I want it to be named the folder name and saved in the same directory as the folder.

The way it is right now is very useful but if I could get it that way that I just explained, that would really save me a lot of time.

Thanks Again!

capitalj
06-19-2010, 06:39 PM
... The only thing is I might have not explained myself correctly... You explained yourself fine, I remember reading it. I don't know why I left that part out. There are probably cleaner ways to do this, but...

tell application "Finder"
set theFolder to input as alias
set thePath to container of theFolder as string
set theName to name of theFolder
set theSequence to (get first file of theFolder as alias)
end tell


tell application "QuickTime Player 7"
activate
open image sequence theSequence

set imageSequence to thePath & theName & ":" & theName & ".mov"

tell document 1
with timeout of 500 seconds
save self contained in imageSequence
end timeout

close

end tell
end tell

Cmd
06-20-2010, 02:46 PM
Excellent!!! It worked! Thanks! This is going to save me so much time.

The only thing I changed was where it saves it. I took out " ":" & theName " so that it saves the movie in the same directory as the folder. In my case, it's better because if there are hundreds of images, I'll have to scroll to find it. That's no fun. I'm sure that in some cases it would be better the other way though.

Thanks Again!

capitalj
06-20-2010, 08:22 PM
The only thing I changed was where it saves it.

Well, you did say " saved in the same directory as the folder". I guess it's time to get in the habit of wearing my reading glasses.

switchstudios
10-27-2011, 12:06 AM
CapitalJ you are a life-saver!!

This is exactly the workflow I have been working for! Hooray!

Unfortunately I cannot get the revised script you posted that renames the imageSequence to the name of the folder to work with a dropped folder. I cut and pasted two of your scripts together and perhaps I have screwed up somehow?? Seems like it should work, but not getting anything....

What works (but doesn't rename):

on adding folder items to thisFolder after receiving droppedFolders
repeat with aFolder in droppedFolders

tell application "Finder" to set theSequence to (get first file of aFolder as alias)

tell application "QuickTime Player"
activate
open image sequence theSequence

set nameSequence to (theSequence as string) & ".mov"

tell document 1
with timeout of 900 seconds
export to nameSequence as QuickTime movie using most recent settings
end timeout

close saving no

end tell
end tell

end repeat
end adding folder items to


What doesn't work:

on adding folder items to thisFolder after receiving droppedFolders
repeat with aFolder in droppedFolders

tell application "Finder"
set theFolder to input as alias
set thePath to container of theFolder as string
set theName to name of theFolder
set theSequence to (get first file of theFolder as alias)
end tell

tell application "QuickTime Player"
activate
open image sequence theSequence

set imageSequence to thePath & theName & ".mov"

tell document 1
with timeout of 1800 seconds
export to imageSequence as QuickTime movie using most recent settings
end timeout

close saving no

end tell
end tell

end repeat
end adding folder items to

I have taken the liberty of increasing the timeout interval since some of my sequences are quite long and QT was choking, but otherwise I think this should work. Only it doesn't... What am I missing?

Thanks so much!

capitalj
12-08-2011, 03:41 PM
Try this. (change "QuickTime Player 7" to "Quicktime Player" for pre-Snow Leopard.)

on adding folder items to thisFolder after receiving droppedFolders
repeat with aFolder in droppedFolders

tell application "Finder"
set theFolder to aFolder as alias
set thePath to container of theFolder as string
set theName to name of theFolder
set theSequence to (get first file of theFolder as alias)
end tell

tell application "QuickTime Player 7"
activate
open image sequence theSequence

set imageSequence to thePath & theName & ".mov"

tell document 1
with timeout of 1800 seconds
export to imageSequence as QuickTime movie using most recent settings
end timeout

close saving no

end tell
end tell

end repeat
end adding folder items to

Adam Wilson
01-29-2013, 02:53 AM
Hi
This is my first post here.
I'm using the script that capitalj posted as a folder action within automator.

It's working beautifully, but.... There is always a but..
It won't let me drop multiple folders or a directory folder in it. If I do the script won't run and it just sits there.

I've got thousands of consecutively named folders with 10,000 consecutive jpegs in them.

What I would like to do is drop a directory folder into the "action" folder and have the movies saved in a separate
folder in the "action" folder called 'movies'
Here's the script I'm using;

on run {input, parameters}
repeat with theFolder in input
tell application "Finder"
set theFolder to input as alias
set thePath to container of theFolder as string
set theName to name of theFolder
set theSequence to (get first file of theFolder as alias)
end tell


tell application "QuickTime Player 7"
activate
open image sequence theSequence

set imagesequence to thePath & theName & ":" & theName & ".mov"

tell document 1
with timeout of 500 seconds
save self contained in imagesequence
end timeout

close

end tell
end tell
end repeat
end run

Any input would be hugely appreciated.
Adam