ColdFusion:有没有办法获得视频的尺寸?

时间:2012-03-23 16:15:50

标签: coldfusion

ColdFusion中有没有办法获取视频文件的宽度和高度?

2 个答案:

答案 0 :(得分:4)

答案 1 :(得分:1)

我使用ffmpeg.org路线获取上传到我们其中一个维护系统的Flash视频的大小。我有一个批处理文件,我通过CFEXECUTE执行并输入ffmpeg.exe的参数。这段代码很多来自其他人,但我似乎没有将他们的网站加入书签。

<!--- Check if the file is a flash video --->
<cfif Form.FILETYPE IS "Flash Video" AND UCase(ListLast(Main, ".")) IS "FLV">
    <!--- Execute batch file to create Information txt file --->
    <cfexecute name="c:\windows\system32\CMD.EXE"
               arguments="/c #App.DocPath#\FFmpeg\GetFLVSizes #App.DocPath#\FFmpeg\ffmpeg.exe #App.RootPath#\files\#Main# #App.RootPath#\files\#ListDeleteAt(Main, ListLen(Main, '.'), '.')#_Info.txt"
               timeout="5">
    </cfexecute>

    <!---read in the text file that was created by ffmpeg--->
    <cffile action="read" file="#App.RootPath#\files\#ListDeleteAt(Main, ListLen(Main, '.'), '.')#_Info.txt" variable="strInformation">

    <!---find the pattern of two numbers, an 'x' then two more numbers
    These are the dimensions of the file there are no other items that will match
    this pattern, so this is safe--->
    <cfset strPattern=refind("[0-9][0-9]x[0-9][0-9]", strInformation) />

    <!---grab the 4 characters before the x, the x itself, then the 4 characters
    after Essentially this will be:

    1240x1000

    But sometimes the numbers will be 2, or 3 digits, but grab the whole thing--->

    <!---if this does NOT work, then set the size to 320px by 212px
    .flv files created by some applications will not have the dimensions in the
    header--->

    <cftry>
        <cfset strTemp=mid(strInformation, val(strPattern-2), 9)>

        <!---take the value of the last 4 digits for the width this will always
        end up with a number--->
        <cfset FLVHeight    =val(mid(strTemp, 6, 4)) />

        <!---to get the first number, we just need to isolate the first 4
        characters. But find out if there is a space, just in case this is less than 4
        digits--->
        <cfset FLVWidth = left(strTemp, 4) />
        <cfset flvspace = find(' ', Variables.FLVWidth) />
        <cfset FLVWidth = right(Variables.FLVWidth, val(4-flvspace)) />

        <!---set this as the default, this works with the swf file I use to display
        the flv--->
        <cfcatch>
            <cfset FLVWidth     = 320 />
            <cfset FLVHeight    = 212 />
        </cfcatch>
    </cftry>
</cfif>