代码之家  ›  专栏  ›  技术社区  ›  zhengtonic

无法使用apple脚本快速将mov导出到PNG

  •  0
  • zhengtonic  · 技术社区  · 14 年前

    我想知道是否有人能告诉我如何使这个脚本工作。我试了好几个小时,却不明白为什么失败了。

    此脚本告诉Quicktime在Quicktime影片/演示文稿(由keynote生成)中前进,并为影片中每一章的最后一帧导出图像。

    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 
    

    脚本的相关部分如下:

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

    我试过只使用PNG和Photo JPEG,但它仍然只生成PICT格式的图像

    有人知道怎么做吗?我在剧本里找不到任何错误。。。它应该有用。

    欢迎任何建议!提前付款。

    正统

    更新

    我找到了一个解决办法,把视频转换成mp4,而不是提取某些帧。

    1 回复  |  直到 14 年前
        1
  •  3
  •   regulus6633    14 年前

    有一种比将电影重新编码为mp4更简单的方法。在quicktime中,您可以从电影导出图像序列。图像序列的图像可以是png图像。因此,您可以应用此脚本。这是你需要做的事情的基本轮廓。可能看起来很复杂,但其实很简单。

    首先,为导出为图像序列创建一个设置文件。可以通过启动导出并设置导出的设置来完成此操作。然后运行此applescript将设置保存在文件中。。。

    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
    

    其次,你的applescript需要一段时间在你想要图像的地方,然后你基本上修剪电影,使它只包含该时间的帧,然后你使用设置文件将该帧导出为你的图像,如下所示。。。注意:我没有测试下面的脚本

    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