Computer Hope
Microsoft => Microsoft DOS => Topic started by: GenieBean on September 15, 2010, 10:19:52 AM
-
Hi there,
I can see the "duration" (length of the video) for each of our .wmv files in windows explorer by turning on that column, but can't find how to get that into a text file. We have hundreds and hundreds of files that we need the duration for, and obviously we don't want to have to type it all in by hand when the information is displayed right there in front of us.
I've tried .js as well, but am stumped. My .bat file currently looks like this:
dir /n /a /-p /o:gen >filelisting.txt
This allows me to capture most of the information I need and port it over to our database, but lacks the duration info.
Note that I did come across something called "verbose" (/v) that is supposed to list more information, but the batch file fails when I add it in, and I'm not even sure that would show the duration.
Help?
-
The information you see in Windows Explorer about multimedia files (duration, bitrate, etc) is not available to the command prompt, certainly not via DIR. There is no /V switch for DIR.
But you can use ffmpeg to provide multimedia information, and find to isolate the line with the duration information.
http://www.ffmpeg.org/
Example 1. Use ffmpeg with the -i option to get information about a file
C:\Users\Public\Videos\Sample Videos>ffmpeg -i wildlife.wmv
FFmpeg version SVN-r23418, Copyright (c) 2000-2010 the FFmpeg developers
built on Jun 2 2010 04:12:01 with gcc 4.4.2
configuration: --target-os=mingw32 --enable-runtime-cpudetect --enable-avisynth --enable-gpl --enable-version3 --enable-bzlib --enable-libgsm --enable-libfaad
--enable-pthreads --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libmp3lame --enable-libopenjpeg --enable-libxvid --enable-libschroedinger --
enable-libx264 --extra-libs='-lx264 -lpthread' --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-librtmp --extra-libs='-lrtmp -lssl -lcrypto -lws2_
32 -lgdi32 -lwinmm -lcrypt32 -lz' --arch=x86 --cross-prefix=i686-mingw32- --cc='ccache i686-mingw32-gcc' --enable-memalign-hack
libavutil 50.16. 0 / 50.16. 0
libavcodec 52.72. 1 / 52.72. 1
libavformat 52.67. 0 / 52.67. 0
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.20. 0 / 1.20. 0
libswscale 0.11. 0 / 0.11. 0
Seems stream 1 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 29.97 (30000/1001)
Input #0, asf, from 'wildlife.wmv':
Metadata:
SfOriginalFPS : 299
WMFSDKVersion : 11.0.6001.7000
WMFSDKNeeded : 0.0.0.0000
IsVBR : 0
title : Wildlife in HD
author :
copyright : ┬® 2008 Microsoft Corporation
comment : Footage: Small World Productions, Inc; Tourism New Zealand | Producer: Gary F. Spradling | Music: Steve Ball
Duration: 00:00:30.09, start: 8.000000, bitrate: 6977 kb/s
Stream #0.0: Audio: wmav2, 44100 Hz, 2 channels, s16, 192 kb/s
Stream #0.1: Video: vc1, yuv420p, 1280x720, 29.97 tbr, 1k tbn, 1k tbc
At least one output file must be specified
Example 2. Note that ffmpeg outputs info text to stderr so to pipe to find we need to redirect stderr to stdout using 2>&1
C:\Users\Public\Videos\Sample Videos>ffmpeg -i wildlife.wmv 2>&1 | find "Duration"
Duration: 00:00:30.09, start: 8.000000, bitrate: 6977 kb/s
You can redirect the information to a file, and use standard batch or vbscript methods to process the information.
-
vbscript
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objPlayer = createobject("wmplayer.ocx.7")
strFolder="c:\videos"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) = "mp3" Then
strFileName = strFile.Path
WScript.Echo objPlayer.mediaCollection.add(strFileName).duration
End If
Next
objPlayer.close
c:\test> cscript //nologo myscript.vbs
-
Does that work for .wmv's or just .mp3's?
-
why don't you try it out?
-
Does that work for .wmv's or just .mp3's?
Yes. One would need to change the "if" test but that's not difficult at all.
-
vbscript
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objPlayer = createobject("wmplayer.ocx.7")
strFolder="c:\videos"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) = "mp3" Then
strFileName = strFile.Path
WScript.Echo objPlayer.mediaCollection.add(strFileName).duration
End If
Next
objPlayer.close
c:\test> cscript //nologo myscript.vbs
is it possible in your opinion to use that code in an asp vbscript page?
I try it changing the "WScript.Echo objPlayer.mediaCollection.add(strFileName).duration" line
in Response.write(objPlayer.mediaCollection.add(strFileName).duration), but doesn't work...