2011-10-21 38 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中的文件夹,在文件夹上执行批量导出,并且导出了一个纯文本文件,我可以导入该文件>导出>批量列表在电子表格中作为日志的开始并计算总持续时间。

也许这有助于他人。