【发布时间】:2021-12-28 18:09:45
【问题描述】:
我有一个 XML 文件,我尝试在其中找到一个特定的标签。但是标签在hirechcal顺序上是不同的。我尝试找到标签“MotionVectore”,然后计算特定帧类型(P、B 或 I 帧)的平均运动矢量值。在下面我放了这个 XML 文件的一部分:
<Picture id="1" poc="1">
<GOPNr>0</GOPNr>
<SubPicture structure="0">
<Slice num="0">
<Type>0</Type>
<TypeString>SLICE_TYPE_P</TypeString>
<NAL>
<Num>5</Num>
<Type>1</Type>
<TypeString>NALU_TYPE_SLICE</TypeString>
<Length>47048</Length>
</NAL>
<MacroBlock num="0">
<MotionVector list="0">
<RefIdx>0</RefIdx>
<Difference>
<X>184</X>
<Y>149</Y>
</Difference>
<Absolute>
<X>184</X>
<Y>149</Y>
</Absolute>
</MotionVector>
<MotionVector list="0">
<RefIdx>0</RefIdx>
<Difference>
<X>10</X>
<Y>0</Y>
</Difference>
<Absolute>
<X>194</X>
<Y>149</Y>
</Absolute>
</MotionVector>
<Position>
<X>0</X>
<Y>0</Y>
</Position>
<QP_Y>21</QP_Y>
<Type>1</Type>
<TypeString>P_L0_L0_16x8</TypeString>
<PredModeString>BLOCK_TYPE_P</PredModeString>
<SkipFlag>0</SkipFlag>
</MacroBlock>
<MacroBlock num="1">
<SubMacroBlock num="0">
<Type>0</Type>
<TypeString>P_L0_8x8</TypeString>
<MotionVector list="0">
<RefIdx>0</RefIdx>
<Difference>
<X>8</X>
<Y>-1</Y>
</Difference>
<Absolute>
<X>192</X>
<Y>148</Y>
</Absolute>
</MotionVector>
</SubMacroBlock>
</MacroBlock>
</Slice>
</SubPicture>
</Picture>
如您所见,实现X 和Y 值的标签顺序为Picture/SubPicture/Slice/MacroBlock/MotionVector/Absolute/X,但有时此顺序为Picture/SubPicture/Slice/MacroBlock/SubMacroBlock/MotionVector/Absolute/X所以当我使用此代码时
abs_x_tag=list(qpy_node.text for qpy_node in root.findall('Picture/SubPicture/Slice/MacroBlock/SubMacroBlock/MotionVector/Absolute/X'))
要提取所有X 值,它不能提取所有X 值,而且我必须根据此标签计算不同帧类型的运动向量
<TypeString>SLICE_TYPE_P</TypeString>
基于这些限制,我不知道如何分别提取每种帧类型的 X 和 Y 值。我可以使用上述代码提取所有 X 和 Y 值,但我不知道如何根据框架类型找到这些值。你能帮我解决这个问题吗?谢谢。
【问题讨论】:
-
能否附上完整的 XML 节点和所需输出的示例。
-
很遗憾,我无法附加我的文件。这个 XML 文件大约 26 Mb,当我想使用图像附加添加它时,我无法附加它。如何附加我的 XML 文件?
-
提取文件的 VALID 子集并发布。
标签: python python-3.x xml xml-parsing