gpt4 book ai didi

hevc - 解析hevc比特流

转载 作者:行者123 更新时间:2023-12-04 05:21:05 25 4
gpt4 key购买 nike

有没有办法解析 HEVC 比特流文件?

我希望能够创建一个新的比特流文件,其中选择了从原始比特流文件中选择的最终单位数据包。

编辑:我插入了我的代码。请找到我的比特流文件 here .

#library for searching in a string
import re

#library to keep dictionary order
import collections
import bitstring
from bitstring import BitStream, BitArray, ConstBitStream, pack
from bitstring import ByteStore, offsetcopy

#read bitstream file
s = BitStream(filename='11LTCCA_560x416_50Hz_8b_P420_GOP8_IP48_200frms_QP28.HEVC.str')

#find no of packets
pcks = list(s.findall('0x000001', bytealigned=True))

print len(pcks)

#set the current position, in the beginning of the nal unit.
s.pos =pcks[0]-8
print s.pos

#find the number of bits of first nal packet
no_p = pcks[1]-pcks[0]


forbidden_zero_bit = s.read(1)
nal_unit_type = s.read('uint:6')

# go to the beginning of the second nal unit
s.read(no_p)
# print nal unit type of the 1st packet
print nal_unit_type

no_p = pcks[2]-pcks[1]
s.pos = pcks[1]-8
print s.pos
forbidden_zero_bit = s.read(1)
nal_unit_type = s.read('uint:6')
s.read(no_p)
print nal_unit_type

最佳答案

如果你想做的只是取一些最终的单元包(例如取决于layer id和temporal id),并且不需要修改VPS、SPS、PPS、Slice Header等,那么你也可以很容易地实现这个你自己:

相应的语法在HEVC standard的附件B“字节流格式”中有说明。 .

简而言之:

  • 在比特流文件中搜索模式 0x000001,它将所有最终单元分开。此外,如果下一个 nal 单元是访问单元的第一个 nal 单元(访问单元 = 用于解码整个帧的所有 nal 单元),则在此模式之前可以有一个 0x00 字节。
  • 根据 HEVC standard 的第 7.3.1.2 节读取最终单元标题并根据您想要的任何标准保留/删除最终单位。确保保留参数集(根据 HEVC standard 的表 7-1 的最终单位类型 32、33 和 34)。
  • 将所有最终单元组装到一个新文件中,并确保中间始终有 0x000001 序列。

  • 我曾经用 Python 做过类似的事情,效果很好。如果您想更轻松地阅读最终单元标题,请使用 bitstring module .如果你想这样做并且有更详细的问题,如果你愿意,你可以pm我寻求帮助。

    编辑:
    关于您发布的代码:
    为什么在分配 BitStream 对象( s.pos =pcks[0]-8s.pos = pcks[1]-8 )中的位置时要放“-8”?这应该是 +24(24 位 = 3 个字节 = nal 单元分隔符的长度 0x000001),在分隔符之后开始读取以获得 nal 单元。但是,在读取数据时必须考虑到这一点: no_p = pcks[1]-pcks[0]应该是 no_p = pcks[1]-pcks[0]-24 ,因为您在最终单位分隔符之后开始阅读。

    如果您对第一个找到的位置( pcks[0] )是 8 而不是 0 感到困惑:根据 HEVC standard 的附件 B,在每个最终单元分隔符之前,可以有任意数量的零字节。 .通常,每个访问单元之前总是有一个零字节。

    关于hevc - 解析hevc比特流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24826963/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com