WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Length of MPEG File


When working with devices you first want to open the device. The following MCI command opens the "MPEGVideo" device:
open %FileName% type MPEGVideo alias myvideo 
The command assigns the device alias "myvideo".

You can eliminate the "type" flag if you combine the device name with the filename. MCI recognizes this combination when you use the following syntax:

device_name!element_name
The exclamation point separates the device name from the filename. The exclamation point should not be delimited by white spaces.

The following example opens the RIGHT.WAV file using the "waveaudio" device:

open waveaudio!right.wav
The registry contains the device tupe names you can use:

For example the registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Multimedia\MPlayer2\Extensions\.mpeg
has a dataitem [MCIHandler] which tells you the device name for .mpeg files is 'MPEGVideo'.

Here is some sample code that shows how to get the length of time it will take for a .mpeg to run.

FileName = "C:\Temp\luckyDude\luckyDude.mpeg"
FileName=FileNameShort(FileName)   ; for 32 bit only

PlayMedia("open MPEGVideo!%FileName% alias myvideo")
;set format to milliseconds
PlayMedia("set myvideo time format ms")
;get length
length = PlayMedia("status myvideo length")
;set format back to frames
PlayMedia("set myvideo time format frames")
;close
PlayMedia("close all")
;calculate total seconds
Sec = length / 1000
; and display in sec format
Message("Number of seconds = ",sec)

exit

For a list of MCI command strings:
http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_multimedia_command_strings.asp?frame=true


Article ID:   W16463
File Created: 2005:02:18:12:20:50
Last Updated: 2005:02:18:12:20:50