3

I've got a system that plays random video and image files, and I want to set some fading transitions with them. Right now, I want the timing just right, so I figure the best way to start is with determining the duration of the video I'm about to play. I'm having some issues with determining file durations with JavaScript, so I'm putting it to rest for a bit, and figured I may be able to do this through ColdFusion instead.

I've tried letting best friend Google to find the answers, but to no avail. So anyone here know how to determine the duration of a video file that had just been uploaded with ColdFusion?

Thanks.

Update:

I managed to find something:

<!--- Set CrLf definition --->
<cfset CrLf = Chr(13)&Chr(10) />
<!--- Use FF Probe to extract stream information, Stream 1 contains duration, width and height info about the file --->
<cfexecute name="c:\inetpub\wwwroot\ffprobe.exe" arguments="#testFile# -show_streams" timeout="60" variable="info" errorVariable="errorOut" />
<!--- Concentrates on extracting information from the very first stream in the returned variable --->
<cfset StreamStart = Find("[STREAM]", info) />
<cfset StreamEnd = Find("[/STREAM]", info) />
<cfset Stream = Mid(info, StreamStart+9, StreamEnd - StreamStart - 12)&CrLf />
<!--- ^^ Parses out first stream --->
<!--- vv Extracts the duration, don't really mind the long decimal bit at the end! --->
<cfset adRefreshTime = Mid(Stream, Find("duration=",Stream)+9, Find(CrLf, Stream, Find("duration=",Stream)+9)-(Find("duration=",Stream)+9)) />

The stream that's pumped out holds a decimal number of seconds in the duration instead of HH:MM:SS.mmm, so I just parse it out... Instant duration... What do you think?

Eliseo D'Annunzio
  • 592
  • 1
  • 10
  • 26

2 Answers2

4

My own (free / open source) VideoConverter.cfc can usually do that.

https://github.com/sebtools/Video-Converter

 <cfset sInfo = VideoConverter.getVideoInfo(path)>

Look for the "Duration" key in the structure returned by that method. If it exists, then VideoConverter.cfc was able to figure out the duration of the video.

Internally, it is using ffmpeg.exe to get that information.

Steve Bryant
  • 1,046
  • 5
  • 7
  • Have realized that the "path" needs the local video path, what if the video is remote on a url? – Nich May 23 '14 at 02:21
2

For mp3s you can use this. May work with videos if you pass a video file

<cfset mp3File = createObject("java", "coldfusion.util.MP3File").init("C:\music.mp3")>
<cfoutput>mp3File.getDuration() : #mp3File.getDuration()# Sec</cfoutput><br>

EDIT: Tried with a wmv file and it gave me 4076 seconds for an 11 minute 6 second video. Tried with an mp3 and it said 207 seconds for a 3:24 second mp3. I'm using CF9.01

Matt Busche
  • 14,216
  • 5
  • 36
  • 61