AppleScripting QuickTime Pro 7导出.png文件

时间:2015-05-07 22:16:42

标签: macos applescript quicktime

我不是专家脚本。我试图专门搜索这个,我发现的一切都与导出图像序列有关。我搜索并发布在AskDifferent上。我想要做的是从.mp4文件的开头和结尾导出一个.png文件。这是一个高度重复的任务,我最近做了很多,我真的想自动化它。例如,我们前几天处理了超过100个.mp4s,导致所有开始和结束.png文件花了一个多小时。如果有一个应用程序可以自动执行此操作,那么QuickTime就可以了。我只是想尝试自动化一个真正重复的任务,所以我认为applescript和QuickTime将是解决方案。

我使用的是QuickTime Pro 7 7.6.6版。我使用导出命令来获取与我的视频文件大小相同的静止帧。

我开始使用Apple递归脚本作为基础,这是我到目前为止所做的,但它不起作用。我在这里发帖,希望有人可能知道我错过了什么。

(* 
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software.

In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software ( the "Apple Software" ), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and / or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated.

The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.

IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright ( C ) 2011 Apple Inc. All Rights Reserved.
*)

(* INSTRUCTIONS
This droplet is designed to process one or more files, or folders containing files, whose icons are dragged onto the droplet icon.
The droplet processes recursively, and will examine the contents of every dragged-on folder, and every sub-folder within those folders, to find and process any files who kind matches the indicated types.
You can set the droplet to process only files of a specific type, such as images, by adding the appropriate data types, name extensions, and type IDs to the values of the properties listed at the top of this script.
Place your script code for processing the found files, within the process_file() sub-routine at the bottom of this script.
*)


(* TO FILTER FOR SPECIFIC FILES, ENTER THE APPROPRIATE DATA IN THE FOLLOWING LISTS: *)
property type_list : {"M4V ", "mpg4"} -- e.g.: {"PICT", "JPEG", "TIFF", "GIFf"} 
property extension_list : {"mp4", "m4v", "mpg"} -- e.g.: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property typeIDs_list : {"public.mpeg-4"} -- e.g.: {"public.jpeg", "public.tiff", "public.png"}

(* IMAGE FILTERING *)
(*
-- QuickTime supported image formats
property type_list : {"JPEG", "TIFF", "PNGf", "8BPS", "BMPf", "GIFf", "PDF ", "PICT"}
property extension_list : {"jpg", "jpeg", "tif", "tiff", "png", "psd", "bmp", "gif", "jp2", "pdf", "pict", "pct", "sgi", "tga"}
property typeIDs_list : {"public.jpeg", "public.tiff", "public.png", "com.adobe.photoshop-image", "com.microsoft.bmp", "com.compuserve.gif", "public.jpeg-2000", "com.adobe.pdf", "com.apple.pict", "com.sgi.sgi-image", "com.truevision.tga-image"}
*)

(* MOVIE FILTERING *)
(*
-- iDVD supported movie formats
property type_list : {"dvc!", "MooV", "M4V ", "mpg4"}
property extension_list : {"mov", "mp4", "dv", "m4v","mpg"}
property typeIDs_list : {"public.mpeg-4", "com.apple.quicktime-movie"}
*)

-- This droplet processes files dropped onto the applet 
on open these_items
    repeat with i from 1 to the count of these_items
        set this_item to item i of these_items
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else
            try
                set this_extension to the name extension of item_info
            on error
                set this_extension to ""
            end try
            try
                set this_filetype to the file type of item_info
            on error
                set this_filetype to ""
            end try
            try
                set this_typeID to the type identifier of item_info
            on error
                set this_typeID to ""
            end try
            if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
                process_file(this_item)
            end if
        end if
    end repeat
end open

-- this sub-routine processes folders 
on process_folder(this_folder)
    set these_items to list folder this_folder without invisibles
    repeat with i from 1 to the count of these_items
        set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else
            try
                set this_extension to the name extension of item_info
            on error
                set this_extension to ""
            end try
            try
                set this_filetype to the file type of item_info
            on error
                set this_filetype to ""
            end try
            try
                set this_typeID to the type identifier of item_info
            on error
                set this_typeID to ""
            end try
            if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
                process_file(this_item)
            end if
        end if
    end repeat
end process_folder

-- this sub-routine processes files 
on process_file(this_item)
    -- NOTE that during execution, the variable this_item contains a file reference in alias format to the item passed into this sub-routine
    -- FILE PROCESSING STATEMENTS GO HERE
    tell application "QuickTime Player 7"
        set xFolder to path to this_item as string

        pause

        #get properties of front document

        # Get some info so the filenames make some sense... 
        -- set t to current time of this_item
        set frameOne of this_item to track (beginning)
        set frameEnd of this_item to track (end)
        set n to name of this_item

        # Remove extension...
        set n to text 1 thru ((offset of "." in n) - 1) of n

        # Use .png since it will be overwritten later on...
        set xFileStart to xFolder & n & "_start.png"
        set xFileEnd to xFolder & n & "_end.png"

        # Export to BMP, no PNG support with 10.6.8 :(
        export frameOne of this_item to xFileStart as BMP using default settings with replacing
        export frameEnd of this_item to xFileEnd as BMP using default settings with replacing

        play front document

        # Do the actual conversion to PNG
        tell application "Image Events"
            set bmpFile to open file xFileStart
            save bmpFile as PNG
            set bmpFileEnd to open file xFileEnd
            save bmpFile as PNG
        end tell

    end tell
end process_file

0 个答案:

没有答案