2011-10-21 39 views
4

我有以下內容可以返回選定視頻文件的多少秒鐘。在文件夾中循環播放視頻文件以獲得視頻長度

然而,我後來的方式只是給它的電影文件夾,然後它遍歷所有子目錄並找到所有視頻文件類型。

一旦有了這些,我想列出在「1小時53秒」類型格式的視頻長度爲「7990秒」不是太有用。

感謝

set macPath to (choose file) as text 
tell application "System Events" 
    set ts to time scale of movie file macPath 
    set dur to duration of movie file macPath 
    set movieTime to dur/ts 
end tell 
+0

他們不是教你在學校使用標點符號嗎?無論如何,將秒轉換成小時的數學是(秒/ 60)/ 60。實施起來不應該太困難。 – Griffin

回答

8

你參與你的問題的幾個小問題。

1)我如何獲得所有文件的文件夾中,包括子文件夾 2)我怎麼篩選列表中只包含視頻文件 3)我如何通過視頻文件和列表循環4)如何將秒轉換爲可用的字符串

通常我會問你是否把它分解成單個問題,因爲對於有人爲你寫整個事情是個大任務。然而,在這種情況下,你是幸運的,因爲我已經在自己之前完成了這件事......所以你可以擁有我的腳本。我在代碼中提出了很多評論,以幫助您瞭解它的工作原理。

-- I found these extensions for video files here http://www.fileinfo.net/filetypes/video 
-- we can check the file extensions of a file against this list to evaluate if it's a video file 
set video_ext_list to {"3g2", "3gp", "3gp2", "3gpp", "3mm", "60d", "aep", "ajp", "amv", "asf", "asx", "avb", "avi", "avs", "bik", "bix", "box", "byu", "cvc", "dce", "dif", "dir", "divx", "dv", "dvr-ms", "dxr", "eye", "fcp", "flc", "fli", "flv", "flx", "gl", "grasp", "gvi", "gvp", "ifo", "imovieproject", "ivf", "ivs", "izz", "izzy", "lsf", "lsx", "m1v", "m2v", "m4e", "m4u", "m4v", "mjp", "mkv", "moov", "mov", "movie", "mp4", "mpe", "mpeg", "mpg", "mpv2", "msh", "mswmm", "mvb", "mvc", "nvc", "ogm", "omf", "prproj", "prx", "qt", "qtch", "rm", "rmvb", "rp", "rts", "sbk", "scm", "smil", "smv", "spl", "srt", "ssm", "svi", "swf", "swi", "tivo", "ts", "vdo", "vf", "vfw", "vid", "viewlet", "viv", "vivo", "vob", "vro", "wm", "wmd", "wmv", "wmx", "wvx", "yuv"} 

-- get the folder to check 
set f to choose folder 

-- notice the use of "entire contents" to also go through subfolders of f 
-- use a "whose" filter to find only the video files 
tell application "Finder" 
    set vidFiles to (files of entire contents of f whose name extension is in video_ext_list) as alias list 
end tell 

-- use a repeat loop to loop over a list of something 
set vidList to {} -- this is where we store the information as we loop over the files 
repeat with aFile in vidFiles 
    -- get some information from aFile 
    tell application "System Events" 
     set vidFile to movie file (aFile as text) 
     set ts to time scale of vidFile 
     set dur to duration of vidFile 
    end tell 

    -- add the information to the "storage" list we made earlier 
    set end of vidList to {POSIX path of aFile, secs_to_hms(dur/ts)} 
end repeat 

return vidList 

(*=================== SUBROUTINES ===================*) 
-- convert seconds into a string of words 
-- the use of "mod" and "div" here makes it easy 
-- we also make sure that each value is at least 2 places long to make it look nicer 
on secs_to_hms(the_secs) 
    set timeString to "" 
    set hr to the_secs div hours 
    if hr is not 0 then set timeString to timeString & (text -2 thru -1 of ("0" & (hr as text))) & " hours " 

    set min to the_secs mod hours div minutes 
    if min is not 0 then set timeString to timeString & (text -2 thru -1 of ("0" & (min as text))) & " minutes " 

    set sec to the_secs mod minutes div 1 
    if sec is not 0 then 
     set fraction to text 2 thru 3 of ((100 + the_secs mod 1 * 100) as text) 
     set timeString to timeString & (sec as text) & "." & fraction & " seconds" 
    end if 

    if timeString ends with space then set timeString to text 1 thru -2 of timeString 
    return timeString 
end secs_to_hms 
0

我遇到這篇文章,因爲我想在一個文件夾中有一個視頻文件的日誌;我可以在電子表格中導入,也可以計算總持續時間,但不僅是。

發佈的腳本不適用於我,所以我最終導入了Final Cut Pro中的文件夾,在文件夾上執行批量導出,並且導出了一個純文本文件,我可以導入該文件>導出>批量列表在電子表格中作爲日誌的開始並計算總持續時間。

也許這有助於他人。