|
|
I was going to write a longer page about this, but putting the info up here NOW
is probably better than waiting until it gets pretty.
First, you need to have ffmpeg.exe on your server. It does not need to be
'installed', you just need the file to be available.
Here is the code that will use it. I hope it is fairly well explained. Much
of it only works on my server of course, but you can figure that part out.
<!---create the batch file that will be run to determine the height and width
My server has a 'filenum' variable that is actually the file name of the flv.
You will want to replace that with your file name--->
<cffile
action="write"
file="d:\websites\media\flvinfo#filenum#.bat"
output="d:\websites\media\ffmpeg.exe -i #linkpath#\#trim(filenum)#.flv 2>
d:\websites\media\file#filenum#info.txt">
<!---now execute the file just created. This will create a .txt file to use
to get the information. Also, if you just try to execute the batch file
directly, it won't work. You need to go through cmd.exe--->
<cfexecute
name="c:\windows\system32\CMD.EXE"
arguments="/C d:\websites\media\flvinfo#filenum#.bat">
</cfexecute>
<!---we need to put coldfusion to sleep for a while, to let ffmpeg do its job,
otherwise you will always find that the text file created by ffmpeg is not
available--->
<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfset thread.sleep(5000)>
<!---read in the text file that was created by ffmpeg--->
<cffile action="read" file="d:\websites\media\file#filenum#info.txt"
variable="spewer">
<!---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 johnson=refind("[0-9][0-9]x[0-9][0-9]", spewer)>
<!---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 500px by 400px
.flv files created by some applications will not have the dimensions in the
header--->
<cftry>
<cfset jonesy=mid(spewer, val(johnson-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(jonesy, 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(jonesy, 4)>
<cfset flvspace=find(' ', flvwidth)>
<cfset flvwidth=right(flvwidth, val(4-flvspace))>
<!---set this as the default, this works with the swf file I use to display
the flv--->
<cfcatch>
<cfset flvwidth=500>
<cfset flvheight=400>
</cfcatch>
</cftry>
So now you have the flvwidth and flvheight variables...
|
|