Reputation: 47
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?
Upvotes: 2
Views: 3526
Reputation: 9545
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%
Upvotes: 0
Reputation: 47
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
Upvotes: 0
Reputation: 1207
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.
Upvotes: 1