Log in

View Full Version : mediainfo from batch


smok3
22nd July 2008, 18:11
if i run mediainfo.exe (winxp) from cli:
mediainfo --Inform=General;%Duration/String3% del01.wav

it will nicely return:
00:03:25.160

---

how to use that as batch?, example:
test.bat
mediainfo --Inform=General;%Duration/String3% %1

so i would run as:
test del01.wav

(nothing is working, escaping with carrots, escaping with %, nothing...)

RunningSkittle
22nd July 2008, 18:25
its because command prompt thinks

%Duration/String3% is an environment variable.

try this

%%Duration/String3%%

mediainfo really should have used a different deliminator...

smok3
22nd July 2008, 18:28
like i said, i tried every escape trick allready...., any other tricks? (i really don't want to play with findstr and stuff like that)

RunningSkittle
22nd July 2008, 18:34
I just made this script, it works exactly as it should

set file="E:\Movies\BeerFest.mkv"
set mediainfo="C:\Program Files (x86)\StaxRip\Applications\MediaInfo\mediainfo\mediainfo.exe"

%mediainfo% --Inform=General;%%Duration/String3%% %file%
pause

output:

01:56:26.146

Its not an "escape trick", its just a workaround for the way command prompt handles variables. kind of like how "::" is frequently used to comment instead of "rem"... when actually its calling a label ":" Likewise !var! would not work unless you enabled delayed environment variable expansion.

You can also parse the output using "for /f"

Can you post your script?

smok3
22nd July 2008, 21:07
tnx, will post tommorow what i did.

cdanddvdpublisher
23rd July 2008, 04:00
I just made this script, it works exactly as it should

set file="E:\Movies\BeerFest.mkv"
set mediainfo="C:\Program Files (x86)\StaxRip\Applications\MediaInfo\mediainfo\mediainfo.exe"

%mediainfo% --Inform=General;%%Duration/String3%% %file%
pause

output:

01:56:26.146




looks good - hope it helps the guy/gal out

smok3
23rd July 2008, 08:12
i still don't get it how %% didn't work for me, it is working now, shrug, here is what i did now:

main, audiodur.bat
@echo off

t:\path\mediainfo --Inform=General;%%Duration/String3%% %1 > t:\tmp\tmpdur.txt
set /P somestring=<t:\tmp\tmpdur.txt
del t:\tmp\tmpdur.txt
:: drop ms part of the string
::set somestring=%somestring:~0,-4%

echo %somestring% %~n1%~x1

and 2nd one, that serves as a loop, audiodur_tcm.bat
@ECHO OFF

for /f "delims=+++++" %%i in (%1) DO t:\path\audiodur.bat "%%i" >>durlist.txt

the 2nd one is applied to tcm start menu with %L option, and thats it.

RunningSkittle
23rd July 2008, 13:04
To avoid creating a temporary file, use the "usebackq" option

@echo off
set file="D:\Movies\BeerFest.mkv"
set mediainfo="C:\mediainfo\mediainfo.exe"

for /f "usebackq" %%a in (`"%mediainfo% --Inform=General;%%Duration/String3%% %file%"`) do set duration=%%a
echo %duration%
pause

were you trying to loop this for all files in a directory (and or subdirectories?) This is very easy to do with for /r

smok3
23rd July 2008, 13:42
total commander with option %L provides ascii file-list (one file per line) and then i loop thought those (this list is the list of files selected in active pane of the total commander gui).

for /f "usebackq" %%a in (`"%mediainfo% --Inform=General;%%Duration/String3%% %file%"`) do set duration=%%a

this looks totally greek to me today, and in one month i won't have a clue what it means, so i'll let the tmp files to be made :)

RunningSkittle
23rd July 2008, 14:08
"usebackq", use-back-quotes lets "for /f" parse the output of a command in a "back quoted" string. for example
for /f "usebackq" %%a in `"command"` do echo %%a

(back quote is the button under tilde)

in this case, it parses the output of "%mediainfo% --Inform=General;%%Duration/String3%% %file%"

This is useful because you cant do:
set duration="%mediainfo% --Inform=General;%%Duration/String3%% %file%"

Rather you could... but it wouldn't have the desired effect ;)

smok3
23rd July 2008, 16:35
i got what it does, syntax is greek.

ricardo.santos
25th October 2009, 10:45
hi everyone

can anyone tell me how to parse/retrieve the framerate from a video file?

i have a semi automatic script that at the end uses mp4box to mux 264+aac into mp4 container but it needs to know the fps.

is this possible?

dr.schanker
25th October 2009, 12:16
The following example works for me:


set mediainfo_exe=c:\Programme\MediaInfo_CLI_0.7.11\MediaInfo.exe
set mp4box_exe=C:\Programme\mp4box\MP4Box.exe

set inputvideo=C:\tmp\fps_test.264
set outputvideo=C:\tmp\fps_test_muxed.mp4

"%mediainfo_exe%" --Inform=Video;%%FrameRate%% "%inputvideo%" > "analyze.txt"
set /p video_fps=<"analyze.txt"
del "analyze.txt"

"%mp4box_exe%" -add "%inputvideo%" -fps %video_fps% -new "%outputvideo%"

ricardo.santos
25th October 2009, 12:33
hi dr.schanker, thanks for your advice, thsi is kind of of what im looking for, i will PM you for some specific help.

dvdboy
21st August 2012, 14:17
Apologies in bumping such a really old post, but I am trying to achieve something similar but don't understand enough about the syntax.

I want to create a csv file which contains a breakdown of a folder's filenames, durations and filesizes.

I can get as far as:

mediainfo.exe "--Inform=General;%FileName%,%Duration/String%,%FileSize%" <PATH TO A FILE> >e:\output.csv

But I don't know how to repeat the command for every file in a directory.

Many Thanks for any pointers!

dr.schanker
21st August 2012, 22:45
Hi dvdboy,

This (http://commandwindows.com/batchfiles-iterating.htm) is a really helpful site. And here a two working examples from a .bat file:

Example 1 - analyzes all files in a directory

set mi_exe=C:\tmp\MediaInfo_CLI_0.7.59_Windows_i386\MediaInfo.exe
set input_folder=C:\test_videos

For %%x in ("%input_folder%\*.*") Do (
"%mi_exe%" --Inform=General;%%FileName%%,%%Duration/String%%,%%FileSize%% "%%~x">>"E:\output.csv"
)


Example 2 - analyzes all files in a directory recursively (existing subfolders will also be searched)

set mi_exe=C:\tmp\MediaInfo_CLI_0.7.59_Windows_i386\MediaInfo.exe
set input_folder=C:\test_videos

For /R "%input_folder%" %%x in ("*.*") Do (
"%mi_exe%" --Inform=General;%%FileName%%,%%Duration/String%%,%%FileSize%% "%%~x">>"E:\output.csv"
)


Just adapt the variables %mi_exe% and %input_folder%.
Please note that in a .bat file you have to add another "%" to the MediaInfo-Informstring, so "%Duration/String%" becomes "%%Duration/String%%".
With the redirect symbol ">>" the Info from MediaInfo for a single file will be appended to the file "E:\output.csv".

dvdboy
22nd August 2012, 14:47
Many Thanks Dr. Schanker. I will give those a go, and check out that site.

Shezed
26th December 2014, 14:25
To avoid creating a temporary file, use the "usebackq" option

@echo off
set file="D:\Movies\BeerFest.mkv"
set mediainfo="C:\mediainfo\mediainfo.exe"

for /f "usebackq" %%a in (`"%mediainfo% --Inform=General;%%Duration/String3%% %file%"`) do set duration=%%a
echo %duration%
pause

were you trying to loop this for all files in a directory (and or subdirectories?) This is very easy to do with for /r

I'm trying to achieve this yes, but your code doesn't work for me
%%a doesn't seem to contain anything for me
%mediainfo% --Inform=General;%%Duration/String3%% %file% does work ( i know it's old but i thought better than duplicating it

stax76
30th January 2017, 00:58
with powershell it looks like so:


PS D:\Video> get-mediainfo D:\Temp\Video\Eli.mp4 | select -ExpandProperty Duration_String3
00:00:43.420
PS D:\Video> $duration = get-mediainfo D:\Temp\Video\Eli.mp4 | select -ExpandProperty Duration_String3
PS D:\Video> $duration
00:00:43.420