Solved

to save video files names and length in a text file

Posted on 2012-04-02
22
617 Views
Last Modified: 2012-04-03
HI
BY USING DIR command in msdos cmd promt i am getting to store my video files names in a folder but i require to get each video file length also..
please provide the command syntax or is there any tool available which helps to do that

thanks
0
Comment
Question by:darien_software
  • 9
  • 8
  • 3
  • +1
22 Comments
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37798133
What length do you mean, just the bytes in the file, or the "time" length of the video, like 1:40.

~bp
0
 
LVL 11

Assisted Solution

by:paultomasi
paultomasi earned 50 total points
ID: 37798963
bill
I think he wants the file length...

darien_software
Suppose your video file is named filename.mp4, you can do it like this (as a command):

    for %a in ("filename.mp4") do @echo %~za

or you can do it like this as a batch file:
@echo off
for %%a in ("filename.mp4") do echo %%~za

Open in new window


For a group of .mp4 files you can do this (display size and filename):

    for %a in (*.mp4) do @echo %~za %~na

A a batch fike, it would look like this:
@echo off
for %%a in (*.mp4) do @echo %%~za %~na

Open in new window

0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37799096
@Paul,

Yeah, I'm old school I guess, and it often costs me points on EE.  I prefer to ask questions on things that aren't clear to me and wait for a response before I invest time writing scripts.  Often while I'm waiting for clarification someone else comes along and takes a shot with some assumptions and gets the points.

It's all good though, I accept the downside of my approach and live with the consequences...

~bp
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 44

Assisted Solution

by:Darr247
Darr247 earned 50 total points
ID: 37799100
MediaInfo can tell you the playing length, along with a bunch of other info, like the audio bitrate, the framerate, et al, and can export that info to a text file a folder at a time, but I haven't played with it much... I just customized the 'Custom' View so it reads

General           : %FileName%
Length            : %FileSize_String% for %Duration_String1%\r\n

and ran it on my Alanis folder and got this output.

General           : Alanis Morissette-Hand in Pocket [live on Ellen 05-25-2005]
Length            : 125 MiB for 3mn 59s 282ms
Video #0          : MPEG-2 Video at 4 000 Kbps
Aspect            : 480 x 352 (1.364) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 320 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis Morissette - You Learn (Live vh1.com) {vh1-bmt-imv}
Length            : 78.3 MiB for 3mn 57s 322ms
Video #0          : MPEG-2 Video at 2 487 Kbps
Aspect            : 480 x 480 (1.333) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 224 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis_Morissette_-_Hand_In_My_Pocket
Length            : 36.6 MiB for 3mn 40s 253ms
Video #0          : MPEG-1 Video at 1 150 Kbps
Aspect            : 352 x 240 (1.304) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 224 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis Morissette - Head Over Feet
Length            : 45.3 MiB for 4mn 33s 73ms
Video #0          : MPEG-1 Video at 1 150 Kbps
Aspect            : 352 x 240 (1.304) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 224 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis Morissette - Ironic
Length            : 42.9 MiB for 3mn 58s 681ms
Video #0          : MPEG-1 Video at 1 098 Kbps
Aspect            : 320 x 240 (1.333) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 384 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis Morissette - 2002 - 05 - Hand In My Pocket {SiG}
Length            : 146 MiB for 4mn 38s 678ms
Video #0          : MPEG-2 Video at 4 000 Kbps
Aspect            : 720 x 480 (1.333) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 320 Kbps
Infos             : 2 channels, 44.1 KHz

I think I need to play with the Custom View some more to get just what I want to be displayed.
Formatting is a little rough, too... the colons were all aligned; not sure what I did to muck that up.

Anyway... is that more like what you were asking for?
That shows the playing time down to the millisecond.
0
 

Author Comment

by:darien_software
ID: 37799654
hi
thanks everyone for the concern and response
i wanted the time length of the video file
and is it possible using a dos command??
but i think for now mediainfo software should help
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37800745
Here's a simple VBS script that will display the file name and then the duration of the video after it.
If (WScript.Arguments.Count > 0) Then
  strFile = WScript.Arguments(0)
Else
  WScript.Echo "ERROR : No input filename specified."
  WScript.Quit -1
End If

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strFile) then
  WScript.Echo "ERROR : Input filename specified does not exist."
  WScript.Quit -1
End If

Set objFile = objFSO.GetFile(strFile)
strFolder = objFile.ParentFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)

Set objFileItem = objFolder.ParseName(objFile.Name)

WScript.Echo objFile.Path & "," & objFolder.GetDetailsOf(objFileItem, 27)

Open in new window

Save that as a VBS, let's say EE27659199.VBS.  Then you can use a small BAT file if you want to process all files in a folder like this:
@echo off
for %%A in (*.wmv *.avi) do cscript //nologo EE27659199.VBS "%%~A"

Open in new window

~bp
0
 
LVL 44

Expert Comment

by:Darr247
ID: 37801803
Is there a redirect missing from the batch?

It looks like that will display, but I don't see how it writes the info to a file. (?)
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37801977
Yes, if you want to send the output to a text file you could redirect the output as in:
@echo off
for %%A in (*.wmv *.avi) do cscript //nologo EE27659199.VBS "%%~A" >>listing.txt

Open in new window

~bp
0
 

Author Comment

by:darien_software
ID: 37802128
HI THANKS FOR THE CODE
but the output am getting is this..

C:\Documents and Settings\Administrator\Desktop\demo\Algeb-33  Factorization-Using-Spl.products.avi,629 pixels
C:\Documents and Settings\Administrator\Desktop\demo\Algebra-    Problems-Based-Laws-of-Set-operations-[Part-2]  A-{BnC}={A-B}U{A-C}.avi,609 pixels
C:\Documents and Settings\Administrator\Desktop\demo\Men-26   Area-of-An-Equilateral-Triangle-with-Example.avi,623 pixels
C:\Documents and Settings\Administrator\Desktop\demo\Ns-31   Problems-Based-on-Addiiton-of-Integers-[part-1].avi,663 pixels
C:\Documents and Settings\Administrator\Desktop\demo\Ns-63    Simplification-of-Fractions-With-Minus-And-Plus-Operations-[word problem] {part-2}.avi,628 pixels


i am not getting any time duration of each video file
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37802153
What version of Windows are you running?

~bp
0
 

Author Comment

by:darien_software
ID: 37802203
windows xp
0
 

Author Comment

by:darien_software
ID: 37802219
and if possible it iwll be very useful if i also get the size of the file in mb

so finally  i require
1.full name of the file
2.Duration(length in minutes) of the video file
3.Size of the file in mb
thanks
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37802756
Okay, just for testing purposes, can you run the following VBS passing it just one of the video files?  So save as a VBS, let's save TEST.VBS, and then run from a command line like this:

cscript test.vbs "videofile.avi" >test.txt

Then paste test.txt back up here please.
If (WScript.Arguments.Count > 0) Then
  strFile = WScript.Arguments(0)
Else
  WScript.Echo "ERROR : No input filename specified."
  WScript.Quit -1
End If

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strFile) then
  WScript.Echo "ERROR : Input filename specified does not exist."
  WScript.Quit -1
End If

Set objFile = objFSO.GetFile(strFile)
strFolder = objFile.ParentFolder

Dim strAttrName(300)

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)

for N = 0 To 300
   strAttrName(N) = Replace(objFolder.GetDetailsOf(Nothing, N), " ", "_")
Next

Set objFileItem = objFolder.ParseName(objFile.Name)

For i = 0 To 300
   if objFolder.GetDetailsOf(objFileItem, i) <> "" Then
      If Instr("objFolder.GetDetailsOf(objFileItem, i)", Chr(63)) then Wscript.Echo "FOUND"
      WScript.Echo "[" & i & "] " & strAttrName(i) & "=" & Replace(objFolder.GetDetailsOf(objFileItem, i), Chr(63), "")
   End If
Next

Open in new window

~bp
0
 

Author Comment

by:darien_software
ID: 37802850
ok
i have done it
here is the out put


Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

[0] Name=Algeb-33  Factorization-Using-Spl.products
[1] Size=61,480 KB
[2] Type=Windows Movie
[3] Date_Modified=6/24/2011 4:23 PM
[4] Date_Created=3/29/2012 12:35 PM
[5] Date_Accessed=4/3/2012 11:43 PM
[6] Attributes=A
[7] Status=Online
[8] Owner=VID1\Administrator
[21] Duration=0:35:41
[22] Bit_Rate=192kbps
[26] Dimensions=629 x 447
[27] =629 pixels
[28] =447 pixels
[32] Audio_sample_size=8 bit


bill
is it possible can u give me
only name of the file
duration
and size
and not in this format but in column wise and saved in excel format instead of txt
well i have hundreds of videos files and if each one is listed like this in text again i need to copy paste onto excel both duration and size which defeats the purpose of my interaction here
thanks in advance
0
 

Author Comment

by:darien_software
ID: 37802866
well if i run the cscript and save in xls format i am getting the same conents row wise
 i just need like in tabular wise

with first column having all the video names with no other options like the prev output has [0]name..but only the file name
second having corresponding duration in mins
third having the size of corresponding video in mb (instead of KB)
of all the videos in the same folder...
well my project requires these details and its urgent and i dont know vb code to do anything myself
so thanks for the help
0
 
LVL 53

Assisted Solution

by:Bill Prew
Bill Prew earned 400 total points
ID: 37802896
Okay, try this.  The output of the BAT file will be a CSV which should open right up in Excel.
If (WScript.Arguments.Count > 0) Then
  strFile = WScript.Arguments(0)
Else
  WScript.Echo "ERROR : No input filename specified."
  WScript.Quit -1
End If

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strFile) then
  WScript.Echo "ERROR : Input filename specified does not exist."
  WScript.Quit -1
End If

Set objFile = objFSO.GetFile(strFile)
strFolder = objFile.ParentFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)

Set objFileItem = objFolder.ParseName(objFile.Name)

WScript.Echo Quote(objFile.Path) & "," & objFolder.GetDetailsOf(objFileItem, 21) & "," & objFile.Size

Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window

@echo off
echo Filename,Length,Size>listing.csv
for %%A in (*.wmv *.avi) do cscript //nologo EE27659199.VBS "%%~A" >>listing.csv

Open in new window

~bp
0
 

Author Comment

by:darien_software
ID: 37802934
hi
getting output
almost perfect with little issues
hope u can remove
getting the full file name instead of only the file name
if required only can u give hours i.e. HH option i mean none of my videos are more than 60 mins..
and size please give in mb instead of kb or bytes

listing1.csv
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 400 total points
ID: 37803038
Okay, give this a try.
If (WScript.Arguments.Count > 0) Then
  strFile = WScript.Arguments(0)
Else
  WScript.Echo "ERROR : No input filename specified."
  WScript.Quit -1
End If

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strFile) then
  WScript.Echo "ERROR : Input filename specified does not exist."
  WScript.Quit -1
End If

Set objFile = objFSO.GetFile(strFile)
strFolder = objFile.ParentFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)

Set objFileItem = objFolder.ParseName(objFile.Name)

WScript.Echo Quote(objFile.Name) & "," & Mid(objFolder.GetDetailsOf(objFileItem, 21), 3) & "," & Round(objFile.Size/1024/1024, 2)

Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window

~bp
0
 

Author Comment

by:darien_software
ID: 37803089
thank you
this is 99.99% perfect except the time in microseconds which i will correct a very minor one...
thanks a lot
u have saved a lot of time for me..

listing.csv
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37803756
99.99% eh?... Dreadful, isn't it?

With standards slipping that far down the scale, I'd seriously start thinking about repackaging some of those T-shirts - just in case!

:)
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37803795
Was just kidding...

Well done bill. Code looks nice.

Was quite surprised to bag some points. Thank you.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37804011
Glad that was helpful, thanks for the feedback.

~bp
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question