2012-07-23 69 views
0

我的iPad應用程序使用戶能夠觀看幾百部視頻。目前iPad應用程序將它們指向MP4文件。不過,我想將它們指向QuickTime參考電影。 (如果用戶通過3G與WiFi連接,則允許該應用發送較低比特率的視頻版本。)iOS自動編碼視頻(以及創建參考電影)

現在,我在QuickTime中創建各種版本以及參考文件,方法是轉到文件 - >導出到Web。但是,這個過程(1)只允許我一次完成一個文件,並且(2)生成大量無用的東西,比如HTML和JavaScript。

我該如何自動化過程?有沒有人知道現有的腳本/工具來完成這項工作?我相信其他開發者之前必須這樣做。

回答

0

我寫的(和其他的東西拼湊起來在網絡上)這個的AppleScript做的工作:

--property exportFolder : (path to documents folder as Unicode text) & "Your Folder:" 
property QTExportPath : (path to movies folder from user domain) 
property completedFolderName : "completion" -- this folder must already exist 
property referenceFiles : {} 
property encodeCount : 0 

on run 
    choose folder with prompt "Choose folder with video files:" -- with multiple selections allowed 
    open (result) 
end run 

on open droppedItems 

    tell application "Finder" 
     set allFiles to every file of entire contents of droppedItems as alias list 
    end tell 

    -- Error checking 
    repeat with testFile in allFiles 

     set myChars to characters of basename(testFile) 

     if count_matches(myChars, ".") > 1 then 
      display dialog "ERROR: The file " & basename(testFile) & " has too many periods." 
      return 
     end if 

    end repeat 

    -- Made it past error checking, let's get started 

    tell application "QuickTime Player" 
     activate 
     close every window 
    end tell 

    repeat with thisItem in allFiles 

     tell application "QuickTime Player" 
      close every window 

      open thisItem as alias 

     end tell 

     activate application "QuickTime Player" 
     tell application "System Events" 
      tell process "QuickTime Player" 
       keystroke "E" using command down 
       repeat until exists sheet 1 of window 1 
        delay 0.2 
       end repeat 
       click button "Export" of sheet 1 of window 1 
      end tell 
     end tell 

     tell application "Finder" 
      set fileExt to name extension of thisItem 
     end tell 

     set fileBaseName to basename(thisItem) 

     set lengthWithoutExtension to (count of fileBaseName) - (count of fileExt) - 1 

     set fileBaseNameWithoutExtension to text 1 thru lengthWithoutExtension of fileBaseName 

     set end of referenceFiles to fileBaseNameWithoutExtension 

     repeat until startedExporting(fileBaseNameWithoutExtension) 

      -- wait for this file to start exporting before beginning another 

     end repeat 


    end repeat 

    repeat until doneExporting(referenceFiles) 

     -- wait for exporting to finish 

    end repeat 

    cleanUpGarbage(referenceFiles) 

    tell application "QuickTime Player" 
     activate 
     close every window 
     quit 
    end tell 

    display alert "finished exporting" 

end open 

on basename(thePath) -- Returns basename of alias 

    set thePOSIXPath to the POSIX path of thePath 

    if thePOSIXPath ends with "/" then 
     set nameIndex to -2 
    else 
     set nameIndex to -1 
    end if 

    set ASTID to AppleScript's text item delimiters 
    set AppleScript's text item delimiters to "/" 
    set thePOSIXPath to text item nameIndex of thePOSIXPath 
    set AppleScript's text item delimiters to ASTID 
    return thePOSIXPath 
end basename 

on startedExporting(fileBaseNameWithoutExtension) -- Checks if QuickTime began exporting a file 

    set moviesPath to QTExportPath as text 
    set fileToTest to ((the POSIX path of moviesPath) & fileBaseNameWithoutExtension & "/Resources/" & fileBaseNameWithoutExtension & ".mov") 
    if FileExists(fileToTest) then 
     -- do nothing 
    else 
     return false 
    end if 

end startedExporting 

on doneExporting(referenceFiles) -- Checks if QuickTime is done exporting everything 

    set moviesPath to QTExportPath as text 
    repeat with thisItem in referenceFiles 
     set fileToTest to ((the POSIX path of moviesPath) & thisItem & "/Resources/" & thisItem & ".mov") 
     if FileExists(fileToTest) then 
      -- do nothing 
     else 
      return false 
     end if 
    end repeat 
end doneExporting 

on FileExists(theFile) -- (String) as Boolean 
    tell application "System Events" 
     if exists file theFile then 
      return true 
     else 
      if exists folder theFile then 
       return true 
      else 
       return false 
      end if 
     end if 
    end tell 
end FileExists 

on cleanUpGarbage(referenceFiles) 

    set moviesPath to QTExportPath as text 
    set donePath to (QTExportPath as text) & completedFolderName as text 
    set POSIXMovies to the POSIX path of moviesPath 
    set POSIXDone to the POSIX path of donePath 

    repeat with thisItem in referenceFiles 
     set directoryToClean to (POSIXMovies & thisItem & "/") 
     set m4vcommand to "find '" & directoryToClean & "' -type f -iname '*m4v' -exec cp -n {} '" & POSIXDone & "' \\;" 
     set movcommand to "find '" & directoryToClean & "' -type f -iname '*mov' -exec cp -n {} '" & POSIXDone & "' \\;" 


     do shell script m4vcommand 
     do shell script movcommand 

     set thefolder to POSIX file directoryToClean 

     tell application "Finder" 
      delete thefolder 
     end tell 

    end repeat 
end cleanUpGarbage 

on count_matches(this_list, this_item) 
    set the match_counter to 0 
    repeat with i from 1 to the count of this_list 
     if item i of this_list is this_item then ¬ 
      set the match_counter to the match_counter + 1 
    end repeat 
    return the match_counter 
end count_matches 

它假定:

  • 你從開始的文件夾只有電影文件,並且您想要轉換所有這些文件。
  • 你已經做一個手工導出到Web

設置您在QuickTime想要的任何出口設置將其導出一次一個。如果要同時轉換多個文件,請修改startedExporting方法以僅檢查文件夾而不是.mov文件(該.mov文件是要生成的最後一個文件)。