

InterviewSolution
Saved Bookmarks
1. |
Solve : Getting duration of .wmv files using: dir >filelist.txt? |
Answer» <html><body><p>Hi there, <br/><br/>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 <a href="https://interviewquestions.tuteehub.com/tag/get-11812" style="font-weight:bold;" target="_blank" title="Click to know more about GET">GET</a> 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. <br/><br/>I've tried .js as well, but am stumped. My .bat file currently looks like this:<br/><br/>dir /n /a /-p /o:gen >filelisting.txt <br/><br/>This allows me to capture most of the information I need and port it over to our database, but lacks the duration info. <br/><br/>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.<br/><br/>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.<br/><br/>But you can use <strong>ffmpeg</strong> to provide multimedia information, and <strong>find</strong> to isolate the line with the duration information. <br/><br/><a href="https://www.ffmpeg.org/">http://www.ffmpeg.org/</a><br/><br/>Example 1. Use ffmpeg with the -i option to get information about a file<br/><br/> Code: <a>[Select]</a>C:\Users\Public\<a href="https://interviewquestions.tuteehub.com/tag/videos-25654" style="font-weight:bold;" target="_blank" title="Click to know more about VIDEOS">VIDEOS</a>\Sample Videos>ffmpeg -i wildlife.wmv<br/>FFmpeg version SVN-r23418, Copyright (c) 2000-2010 the FFmpeg developers<br/> built on Jun 2 2010 04:12:01 with gcc 4.4.2<br/> configuration: --target-os=mingw32 --enable-runtime-cpudetect --enable-avisynth --enable-gpl --enable-version3 --enable-bzlib --enable-libgsm --enable-libfaad<br/> --enable-pthreads --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libmp3lame --enable-libopenjpeg --enable-libxvid --enable-libschroedinger --<br/>enable-libx264 --extra-libs='-lx264 -lpthread' --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-librtmp --extra-libs='-lrtmp -lssl -lcrypto -lws2_<br/>32 -lgdi32 -lwinmm -lcrypt32 -lz' --arch=x86 --cross-prefix=i686-mingw32- --cc='ccache i686-mingw32-gcc' --enable-memalign-hack<br/> libavutil 50.16. 0 / 50.16. 0<br/> libavcodec 52.72. 1 / 52.72. 1<br/> libavformat 52.67. 0 / 52.67. 0<br/> libavdevice 52. 2. 0 / 52. 2. 0<br/> libavfilter 1.20. 0 / 1.20. 0<br/> libswscale 0.11. 0 / 0.11. 0<br/><br/>Seems stream 1 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 29.97 (30000/1001)<br/>Input #0, asf, from 'wildlife.wmv':<br/> Metadata:<br/> SfOriginalFPS : 299<br/> WMFSDKVersion : 11.0.6001.7000<br/> WMFSDKNeeded : 0.0.0.0000<br/> IsVBR : 0<br/> title : Wildlife in <a href="https://interviewquestions.tuteehub.com/tag/hd-1016349" style="font-weight:bold;" target="_blank" title="Click to know more about HD">HD</a><br/> author :<br/> copyright : ┬® 2008 Microsoft Corporation<br/> comment : Footage: Small World Productions, Inc; Tourism New Zealand | Producer: Gary F. Spradling | Music: Steve Ball<br/> Duration: 00:00:30.09, start: 8.000000, bitrate: 6977 kb/s<br/> Stream #0.0: Audio: wmav2, 44100 Hz, 2 channels, s16, 192 kb/s<br/> Stream #0.1: Video: vc1, yuv420p, 1280x720, 29.97 tbr, 1k tbn, 1k tbc<br/>At least one output file must be specified<br/>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<br/><br/> Code: <a>[Select]</a>C:\Users\Public\Videos\Sample Videos>ffmpeg -i wildlife.wmv 2>&1 | find "Duration"<br/> Duration: 00:00:30.09, start: 8.000000, bitrate: 6977 kb/s<br/>You can redirect the information to a file, and use standard batch or vbscript methods to process the information.<br/><br/><br/><br/><br/><br/><br/><br/><br/>vbscript<br/> Code: <a>[Select]</a>Set objFS = CreateObject("Scripting.FileSystemObject")<br/>Set objPlayer = createobject("wmplayer.ocx.7")<br/>strFolder="c:\videos"<br/>Set objFolder = objFS.GetFolder(strFolder)<br/>For Each strFile In objFolder.Files<br/> If objFS.GetExtensionName(strFile) = "mp3" Then <br/> strFileName = strFile.Path<br/> WScript.Echo objPlayer.mediaCollection.add(strFileName).duration<br/> End If <br/><a href="https://interviewquestions.tuteehub.com/tag/next-578185" style="font-weight:bold;" target="_blank" title="Click to know more about NEXT">NEXT</a> <br/>objPlayer.close<br/><br/> Code: <a>[Select]</a>c:\test> cscript //nologo myscript.vbs<br/>Does that work for .wmv's or just .mp3's?why don't you try it out? Quote from: Helpmeh on September 15, 2010, 08:55:13 PM</p><blockquote>Does that work for .wmv's or just .mp3's?<br/></blockquote> <br/>Yes. One would need to change the "if" test but that's not difficult at all. Quote from: ghostdog74 on September 15, 2010, 07:22:26 PM<blockquote>vbscript<br/> Code: <a>[Select]</a>Set objFS = CreateObject("Scripting.FileSystemObject")<br/>Set objPlayer = createobject("wmplayer.ocx.7")<br/>strFolder="c:\videos"<br/>Set objFolder = objFS.GetFolder(strFolder)<br/>For Each strFile In objFolder.Files<br/> If objFS.GetExtensionName(strFile) = "mp3" Then <br/> strFileName = strFile.Path<br/> WScript.Echo objPlayer.mediaCollection.add(strFileName).duration<br/> End If <br/>Next <br/>objPlayer.close<br/><br/> Code: <a>[Select]</a>c:\test> cscript //nologo myscript.vbs<br/></blockquote> <br/><br/>is it possible in your opinion to use that code in an asp vbscript <a href="https://interviewquestions.tuteehub.com/tag/page-25452" style="font-weight:bold;" target="_blank" title="Click to know more about PAGE">PAGE</a>?<br/><br/>I try it changing the "WScript.Echo objPlayer.mediaCollection.add(strFileName).duration" line<br/>in Response.write(objPlayer.mediaCollection.add(strFileName).duration), but doesn't work...<br/><br/><br/></body></html> | |