Search code examples
applescriptquicktime

can't get quicktime to export mov into pngs with apple script


i was wondering if anyone can tell me how to make this script work. I tried for hours and i can't figure out why it fails.

This script tells Quicktime to advance in a quicktime movie/presentation (generated by keynote) and export a image for every last frame of every chapter in this movie.

property Main_folder : missing value
set Main_folder to choose folder

tell application "QuickTime Player 7"
    if not (exists document 1) then error "No movies are open."
    stop movies
    tell front document to set {currMovie, T_name, duration_list, current time} to ¬
        {it, text 1 thru -5 of (get name), duration of chapters of (get first track whose kind is "Sprite"), 0}
    set T_target to my makeFolder(T_name)

    repeat with i from 1 to (count duration_list)
        tell currMovie
            set current time to current time + (item i of duration_list)
            export to (T_target & T_name & " Chapter " & i) as picture using settings preset "Photo-JPEG" -- or "Uncommpressed", or "PNG"
        end tell
    end repeat
end tell

on makeFolder(n)
    tell application "Finder" to return (make new folder at Main_folder with properties 

My problem here is that it saves the images in PICT format instead of PNG. The relevat part of the script is here:

export to (T_target & T_name & " Chapter " & i) as picture using settings preset "Photo-JPEG" -- or "Uncommpressed", or "PNG"

I tried it with PNG and and Photo-JPEG only but it still only generates images in the PICT format

Does anyone know how to do this? I can't find any mistakes in the script ... it should work.

Any advice is welcome! Thx in advance.

Best regards,

zhengtonic

update

If anyone is interested i found the reason:

Quicktime 7 is not able to grap a still image from a mov and export it as png/jpeg. I found a workaround by converting the videos to mp4 and than extracting certain frames.


Solution

  • There's an easier way than re-encoding the movie to mp4. In quicktime you can export an image sequence from a movie. The images of an image sequence can be png images. As such you can applescript this. Here's the basic outline of what you'd need to do. It might seem complicated but it's really pretty simple.

    First, Create a settings file for the export as image sequence. You can do that by starting an export and setting up the settings for that. Then run this applescript to save the settings in a file...

    set exportFileName to "ImageSequenceExportSettings.qtSettings"
    set exportFilePath to (path to desktop as text) & exportFileName
    
    tell application "QuickTime Player 7"
        tell first document
            save export settings for image sequence to file exportFilePath
        end tell
    end tell
    

    Second, your applescript takes a time where you want the image, then you basically trim the movie so that it contains only the frame for that time, then you use the settings file to export that frame as your image, something like this... NOTE: I didn't test the following script

    set timeOfImage to 60 -- in seconds
    set settingsFile to (path to desktop as text) & "ImageSequenceExportSettings.qtSettings"
    
    tell application "QuickTime Player 7"
        tell document 1
            if (can export as image sequence) then
                -- trim the movie to one frame
                set ts to time scale
                set theFrame to timeOfImage * ts
                select at theFrame to (theFrame + 1)
                trim
    
                -- save the image
                set theName to text 1 thru -5 of (get name)
                set outPath to (path to desktop as text) & theName & ".png"
                export to outPath as image sequence using settings settingsFile
    
                -- close the movie
                close saving no
            else
                error "The front movie cannot be exported to an image sequence!"
            end if
        end tell
    end tell