2

So I'm trying to setup an easy way of starting videos with a bat file, and having that run Mediainfo first to get the length of the video so it can then stop vlc or whatever else when it's done playing.

Complete name                            : C:\Users\Tyler\Desktop\Psych s05e11.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 116 MiB
Duration                                 : 42 min 36 s
Overall bit rate                         : 382 kb/s
Writing application                      : Lavf55.13.102

That's the output from mediainfo I got in a txt file, I'm trying to just pull the 42 and the 36 from the duration bit and use it in another command. I should also add that these numbers have to be used separately. Thanks!

Edit: Thanks for replying everyone love the help; Here's what I'm trying to run now:

mediainfo.lnk --Language=raw --Output=General;%Duration% "C:\Users\Tyler\Desktop\Psych s05e11.mp4"

and the output is:

2556249

Now I need a way to take the first four digits and use them in a another command, somehow make 2556 a variable?

2
  • 1
    Can you post what you have tried? You can use FOR /F and FIND to solve this problem. Commented Oct 6, 2016 at 16:05
  • Kind of need to see how you are executing mediainfo before we can provide a solution. Commented Oct 6, 2016 at 16:23

3 Answers 3

1

If you need the duration, use e.g. this command:

mediainfo "--Output=General;%Duration%" YourFileName.ext

In a general way, when you think to some automation, prefer to use e.g.:

mediainfo -f --Language=raw  YourFileName.ext

and select the lines which better fits your need, avoid fields with "/String" because they are intended only for display (not for automation).

Jérôme, developer of MediaInfo.

Sign up to request clarification or add additional context in comments.

5 Comments

I'm running the command like so: mediainfo --Language=raw --Output=General;%Duration% "filename.ext" >> "outputfile.txt" and I'm only getting the duration like I want, thanks for that help!
Here's a weird problem I've run into; when I run the command out of a terminal like I've shown in the last comment I get the proper output, however using the exact same command in a batch file returns an output without any options, it runs as: mediainfo --Output=file:\\file.txt "filename.ext". Giving too much information! What could I do to get around that?
Just to tell you (As developper) you shoul never use the % as var definer in a CLI version of a soft. Better use another char like $. Anyway great soft !!
Not a problem of MediaInfo, this is a problem in your batch: % is used for variable, you forgot to escape it. mediainfo "--Output=General;%%Duration%%" %1
You're right i forgot the "string", Modified My Answer, Thanks
0

Okay here's what I did finally, thanks for all the help!

C:\mediainfo\MediaInfo.exe --Language=raw --Output=General;%%Duration%% "C:\Users\Tyler\Desktop\Psych_s05e11.mp4" >out.txt  
set /p $Duration= <out.txt
set $Duration=%$Duration:~0,4%

echo Result = %$Duration%
del out.txt
pause

and the output is:

C:\mediainfo\MediaInfo.exe --Language=raw --Output=General;%Duration%    "C:\Users\Tyler\Desktop\Psych_s05e11.mp4" >out.txt 
set /p $Duration=  <out.txt 
set $Duration=2556 
echo Result = 2556 
Result = 2556
del out.txt 
pause
Press any key to continue . . . 

took @echo off outta there so you could see it all

Comments

0

Using FOR /F

@echo off
for /f "delims=" %%a in ('mediainfo "--Output=General;%%Duration%%" "C:\Users\Tyler\Desktop\Psych\s05e11.mp4"') do set $Duration=%%a

Echo %$Duration%

Using a temporary file

@echo off
mediainfo.exe --Language=raw --Output=General;%%Duration%% "C:\Users\Tyler\Desktop\Psych s05e11.mp4" >out.txt  
set /p $Duration= <out.txt
set $Duration=%$Duration:~0,4%

echo Result = %$Duration%
del out.txt

Another way using @Jérôme Martinez [raw -output] idea. Without temporary file, using findstr :

@echo off
for /f "tokens=2 delims=:" %%a in ('mediainfo -f --Language=raw  "C:\Users\Tyler\Desktop\Psych s05e11.mp4" ^| findstr /i "duration"') do (
    set $Duration=%%a
    goto:next
)

:next
set $Duration=%$Duration:~1,4%
echo %$Duration%

9 Comments

Thanks for the help; Seems closer than anything I've got so far! However the echo output is: Result = ~0,4
Figured out the path was just set up wrong, got that situated now the output is: Result = Alte
Ok and when you just execute mediainfo.lnk --Language=raw --Output=General;^%Duration^% "C:\Users\Tyler\Desktop\Psych s05e11.mp4" What is the exact output ? In all case you'll better work directly on the .exe and not on the .lnk
If I run it in a terminal I get the expected 2556249 but if I run that in a bat file the output is the huge list of stuff mediainfo would display by default, I'll try running it using the exe file instead
I've run it again using the exe file instead of a link, same output, long list of stuff I don't need. However if I do that command by itself it prints out just the Duration
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.