파일은 다음과 같습니다
<MediaInfo xmlns="https://mediaarea.net/mediainfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://mediaarea.net/mediainfo https://mediaarea.net/mediainfo/mediainfo_2_0.xsd" version="2.0">
<creatingLibrary version="19.07" url="https://mediaarea.net/MediaInfo">MediaInfoLib</creatingLibrary>
<media ref="hddvd_demo_1080p.mkv">
<track type="General">
<UniqueID>202679344279770072847249189931093807575</UniqueID>
<VideoCount>1</VideoCount>
<AudioCount>2</AudioCount>
<FileExtension>mkv</FileExtension>
<Format>Matroska</Format>
<Format_Version>1</Format_Version>
<FileSize>291843159</FileSize>
<Duration>121.897</Duration>
<OverallBitRate>19153427</OverallBitRate>
<IsStreamable>Yes</IsStreamable>
<Encoded_Date>UTC 2007-04-07 03:28:47</Encoded_Date>
<File_Modified_Date>UTC 2019-04-30 05:08:12</File_Modified_Date>
<File_Modified_Date_Local>2019-04-30 10:38:12</File_Modified_Date_Local>
<Encoded_Application>mkvmerge v2.0.2 ('You're My Flame') built on Feb 21 2007 23:40:55</Encoded_Application>
<Encoded_Library>libebml v0.7.7 + libmatroska v0.8.1</Encoded_Library>
</track>
<track type="Video">
<StreamOrder>0</StreamOrder>
<ID>1</ID>
<UniqueID>1</UniqueID>
<Format>VC-1</Format>
<Format_Profile>Advanced</Format_Profile>
<Format_Level>3</Format_Level>
<CodecID>V_MS/VFW/FOURCC / WVC1</CodecID>
<BitRate>17492274</BitRate>
<Width>1920</Width>
<Height>1080</Height>
<Sampled_Width>1920</Sampled_Width>
<Sampled_Height>1080</Sampled_Height>
<PixelAspectRatio>1.000</PixelAspectRatio>
<DisplayAspectRatio>1.778</DisplayAspectRatio>
<FrameRate_Mode>VFR</FrameRate_Mode>
<FrameRate_Original>29.970</FrameRate_Original>
<ColorSpace>YUV</ColorSpace>
<ChromaSubsampling>4:2:0</ChromaSubsampling>
<BitDepth>8</BitDepth>
<ScanType>Progressive</ScanType>
<Compression_Mode>Lossy</Compression_Mode>
<Delay>0.000</Delay>
<Title>1080p VC-1</Title>
<Language>en</Language>
<Default>Yes</Default>
<Forced>No</Forced>
<BufferSize>1843200</BufferSize>
</track>
<track type="Audio" typeorder="1">
<StreamOrder>1</StreamOrder>
<ID>2</ID>
<UniqueID>418009001</UniqueID>
<Format>AC-3</Format>
<Format_Commercial_IfAny>Dolby Digital</Format_Commercial_IfAny>
<Format_Settings_Endianness>Big</Format_Settings_Endianness>
<CodecID>A_AC3</CodecID>
<Duration>121.897</Duration>
<BitRate_Mode>CBR</BitRate_Mode>
<BitRate>640000</BitRate>
<Channels>2</Channels>
<ChannelPositions>Front: L R</ChannelPositions>
<ChannelLayout>L R</ChannelLayout>
<SamplesPerFrame>1536</SamplesPerFrame>
<SamplingRate>48000</SamplingRate>
<SamplingCount>5851056</SamplingCount>
<FrameRate>31.250</FrameRate>
<BitDepth>16</BitDepth>
<Compression_Mode>Lossy</Compression_Mode>
<Delay>0.000</Delay>
<Delay_Source>Container</Delay_Source>
<StreamSize>9751760</StreamSize>
<StreamSize_Proportion>0.03341</StreamSize_Proportion>
<Title>Dolby Digital 2.0 640kbps</Title>
<Language>en</Language>
<ServiceKind>CM</ServiceKind>
<Default>Yes</Default>
<Forced>No</Forced>
<extra>
<bsid>8</bsid>
<dialnorm>-31</dialnorm>
<dsurmod>0</dsurmod>
<acmod>2</acmod>
<lfeon>0</lfeon>
<dialnorm_Average>-31</dialnorm_Average>
<dialnorm_Minimum>-31</dialnorm_Minimum>
</extra>
</track>
<track type="Audio" typeorder="2">
<StreamOrder>2</StreamOrder>
<ID>3</ID>
<UniqueID>2</UniqueID>
<Format>E-AC-3</Format>
<Format_Commercial_IfAny>Dolby Digital Plus</Format_Commercial_IfAny>
<Format_Settings_Endianness>Big</Format_Settings_Endianness>
<CodecID>A_EAC3</CodecID>
<Duration>121.897</Duration>
<BitRate_Mode>CBR</BitRate_Mode>
<BitRate>640000</BitRate>
<Channels>6</Channels>
<ChannelPositions>Front: L C R, Side: L R, LFE</ChannelPositions>
<ChannelLayout>L R C LFE Ls Rs</ChannelLayout>
<SamplesPerFrame>768</SamplesPerFrame>
<SamplingRate>48000</SamplingRate>
<SamplingCount>5851056</SamplingCount>
<FrameRate>62.500</FrameRate>
<Compression_Mode>Lossy</Compression_Mode>
<Delay>0.033</Delay>
<Delay_Source>Container</Delay_Source>
<StreamSize>9751760</StreamSize>
<StreamSize_Proportion>0.03341</StreamSize_Proportion>
<Title>Dolby Digital Plus 5.1 640kbps</Title>
<Language>en</Language>
<ServiceKind>CM</ServiceKind>
<Default>No</Default>
<Forced>No</Forced>
<extra>
<bsid>16</bsid>
<dialnorm>-27</dialnorm>
<compr>-0.28</compr>
<acmod>7</acmod>
<lfeon>1</lfeon>
<dialnorm_Average>-27</dialnorm_Average>
<dialnorm_Minimum>-27</dialnorm_Minimum>
<compr_Average>-2.99</compr_Average>
<compr_Minimum>-6.58</compr_Minimum>
<compr_Maximum>3.15</compr_Maximum>
<compr_Count>805</compr_Count>
</extra>
</track>
</media>
</MediaInfo>
내가 얻고 싶은 가치오디오 1xmlstarlet을 사용하는 기간은 "121.897"입니다.
다음 명령을 사용해보십시오.
xmlstarlet sel -t -v 'MediaInfo/media/track/Duration' a.xml
None of the XPaths matched; to match a node in the default namespace
use '_' as the prefix (see section 5.1 in the manual).
For instance, use /_:node instead of /node
답변1
XML 파일은 네임스페이스를 사용하므로 필요한 네임스페이스를 지정하고 이에 따라 쿼리를 조정해야 합니다.
xmlstarlet sel -N 'mi=https://mediaarea.net/mediainfo' -t -v 'mi:MediaInfo/mi:media/mi:track/mi:Duration' a.xml
또는 오류 메시지에 표시된 대로 기본 네임스페이스를 사용합니다.
xmlstarlet sel -t -v '_:MediaInfo/_:media/_:track/_:Duration' a.xml
트랙 선택을 제한하려면 XPath 속성 필터를 추가하면 됩니다. 예:
xmlstarlet sel -t -v '_:MediaInfo/_:media/_:track[@type="General"]/_:Duration' a.xml
또는 첫 번째 "오디오" 트랙을 검색합니다.
xmlstarlet sel -t -v '_:MediaInfo/_:media/_:track[@type="Audio"][1]/_:Duration' a.xml
(XPath 인덱싱 사용) 또는
xmlstarlet sel -t -v '_:MediaInfo/_:media/_:track[@type="Audio" and @typeorder="1"]/_:Duration' a.xml
( typeorder
속성 사용).