How do I get specific information out of Mediainfo

11,498

Solution 1

You can work with the Duration you get with the command you allready used like this:

(assuming $tmil holds the value)

# $tmil = 282520
$durationObject = [timespan]::FromMilliseconds($tmil)

#Minutes:
$durationObject.Minutes
#Seconds:
$durationObject.Seconds

#Duration in HH:MM:SS
$durationObject.ToString("hh\:mm\:ss")

#Duration in HH:MM:SS,MS
$durationObject.ToString("hh\:mm\:ss\,fff")

The duration you get is in milliseconds and can easily be reformatted to fit your needs

Solution 2

Hidden features ;-)
Use

MediaInfo --Language=raw --Full  

and you'll see the field name to use for the template

Here:

MediaInfo --Language=raw --Full --Inform="Video;%Duration/String4%"

PS: I (the main developer of MediaInfo) would see quicker questions if you post questions on the MediaInfo forum.

Solution 3

If you're getting that text dumped and all that you want is the duration you can run it through a regex to get that:

$Duration = 'C:\Mediainfo\mediainfo.exe' 'C:\Users\Administrator\Desktop\input_luebeck\TheFascist.mov' | Where{$_ -match "Duration\s+?: (\d{2}:\d{2}:\d{2}.\d{3})"}|ForEach{$Matches[1]}

That should set $Duration to 00:04:42.520 as you wanted.

Share:
11,498
sebastian
Author by

sebastian

Updated on July 27, 2022

Comments

  • sebastian
    sebastian almost 2 years

    I found out that mediainfo is a really good tool for getting metadata out of videofiles. But sometimes its way too overwhelming for me. First thing I should mention I am using Windows Powershell and in Windows Powershell I use Mediainfo as command line tool. Works pretty neat, but when I use the normal XML output, like the one you can see with the GUI version of Mediainfo, I don't get enough informations out of my videofiles. When using the --Full command I get a better overview of metadata. Unfortunately I just need the fifth "Duration" information:

    Duration: 00:04:42.520

    but everytime I try to ask for the Duration by using --Inform="Video;%Duration%" I always get the first "Duration" information:

    Duration: 282520

    And now here is my question: Is it possible to use the Mediainfo commands in a way that I only get the timecode duration? Because I can't figure out which command would be the best to get this problem solved.

    C:\Mediainfo>mediainfo.exe C:\Users\Administrator\Desktop\input_luebeck\TheFascist.mov 
    General
    Count                                    : 292
    Count of stream of this kind             : 1
    Kind of stream                           : General
    Kind of stream                           : General
    Stream identifier                        : 0
    Count of video streams                   : 1
    Count of audio streams                   : 1
    OtherCount                               : 1
    Video_Format_List                        : ProRes
    Video_Format_WithHint_List               : ProRes
    Codecs Video                             : apch
    Video_Language_List                      : English
    Audio_Format_List                        : PCM
    Audio_Format_WithHint_List               : PCM
    Audio codecs                             : PCM
    Audio_Language_List                      : English
    Other_Format_List                        : QuickTime TC
    Other_Format_WithHint_List               : QuickTime TC
    Other_Language_List                      : English
    Complete name                            : C:\Users\Administrator\Desktop\input_luebeck\TheFascist.mov
    Folder name                              : C:\Users\Administrator\Desktop\input_luebeck
    File name                                : TheFascist
    File extension                           : mov
    Format                                   : MPEG-4
    Format                                   : MPEG-4
    Format/Extensions usually used           : mp4 m4v m4a m4b m4p 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma f4v
    Commercial name                          : MPEG-4
    Format profile                           : QuickTime
    Internet media type                      : video/mp4
    Codec ID                                 : qt
    Codec ID/Url                             : http://www.apple.com/quicktime/download/standalone.html
    Codec                                    : MPEG-4
    Codec                                    : MPEG-4
    Codec/Extensions usually used            : mp4 m4v m4a m4b m4p 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma f4v
    File size                                : 5983768576
    File size                                : 5.57 GiB
    File size                                : 6 GiB
    File size                                : 5.6 GiB
    File size                                : 5.57 GiB
    File size                                : 5.573 GiB
    Duration                                 : 282520
    Duration                                 : 4mn 42s
    Duration                                 : 4mn 42s 520ms
    Duration                                 : 4mn 42s
    Duration                                 : 00:04:42.520
    Overall bit rate mode                    : VBR
    Overall bit rate mode                    : Variable
    Overall bit rate                         : 169439858
    Overall bit rate                         : 169 Mbps
    Stream size                              : 1062720
    Stream size                              : 1.01 MiB (0%)
    Stream size                              : 1 MiB
    Stream size                              : 1.0 MiB
    Stream size                              : 1.01 MiB
    Stream size                              : 1.013 MiB
    Stream size                              : 1.01 MiB (0%)
    Proportion of this stream                : 0.00018
    HeaderSize                               : 32
    DataSize                                 : 5983559488
    FooterSize                               : 209056
    IsStreamable                             : No
    Encoded date                             : UTC 2013-10-21 09:01:39
    Tagged date                              : UTC 2013-10-21 09:15:35
    File creation date                       : UTC 2014-09-29 14:30:28.168
    File creation date (local)               : 2014-09-29 16:30:28.168
    File last modification date              : UTC 2014-09-29 14:37:20.793
    File last modification date (local)      : 2014-09-29 16:37:20.793
    Writing library                          : Apple QuickTime
    Writing library                          : Apple QuickTime
    Writing library/Name                     : Apple QuickTime
    Media/UUID                               : EF3223FC-064A-45E6-9F5D-E59BD682C489
    Media/History/UUID                       : 2783B850-08F4-43DE-AEA5-3D8E7DD78570