如何从Mediainfo中获取特定信息

时间:2014-10-21 14:12:38

标签: powershell command-line mediainfo

我发现mediainfo是一个非常好的工具,用于从视频文件中获取元数据。但有时它对我来说太过于压倒性。首先我要提到的是我使用的是Windows Powershell,而在Windows Powershell中我使用Mediainfo作为命令行工具。工作非常简洁,但是当我使用普通的XML输出时,就像你在Mediainfo的GUI版本中看到的那样,我从你的视频文件中得不到足够的信息。使用--Full命令时,我可以更好地了解元数据。不幸的是,我只需要第五个“持续时间”信息:

时长:00:04:42.520

但是每当我尝试使用--Inform="Video;%Duration%"来询问持续时间时,我总是会得到第一个“持续时间”信息:

持续时间:282520

现在我的问题是:是否可以以我只获得时间码持续时间的方式使用Mediainfo命令?因为我无法弄清楚哪个命令最好能解决这个问题。

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

3 个答案:

答案 0 :(得分:14)

隐藏的功能;-)
使用

MediaInfo --Language=raw --Full  

您将看到用于模板的字段名称

这里:

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

PS:如果您在MediaInfo论坛上发布问题,我(MediaInfo的主要开发者)会看到更快的问题。

答案 1 :(得分:3)

您可以使用您已经使用过的命令来使用持续时间,如下所示:

(假设$ tmil持有该值)

# $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")

您获得的持续时间以毫秒为单位,可以轻松地重新格式化以满足您的需求

答案 2 :(得分:0)

如果您正在获取该文本,而您想要的只是持续时间,您可以通过正则表达式来运行它:

$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]}

应根据需要将$Duration设置为00:04:42.520

相关问题