0

I need to read the POC number from the HEVC bitstream using python BitStream. Currently I read the nal unit header. Is there an easy way to get it?

I have trace enabled HM14.0 but the EncTrace.txt does not include all my packets.

Any idea?

Edit: I attach my python code. This is my bitstream file.

import re

import collections
import bitstring
from bitstring import BitStream, BitArray, ConstBitStream, pack
from bitstring import ByteStore, offsetcopy
import unicodedata


text_file = open("nal_Output.txt", "wb")

s = BitStream(filename='new.str')

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


s.pos=0
num_of_pcks = len(pcks)
num_of_POC_pcks =0
for x in range(0, num_of_pcks):
    s.pos =pcks[x]+24
    #print x
    if x < num_of_pcks-1:
        no_p = pcks[x+1]-pcks[x]-24
    else:
        no_p = 0

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

    #nal unit type 39 is for SEI messages: one byte message
    if int(nal_unit_type) >31 :
        #print 'nal=39'
        #size_of_pck = (no_p+24+8)/8
        packet = 0
    elif int(nal_unit_type) <32:
        #print int(nal_unit_type)
        num_of_POC_pcks = num_of_POC_pcks+1
        size_of_pck = (no_p+24)/8
        text_file.write("NumBytesInNALunit: {0}\n".format(str(size_of_pck)))
    s.read(no_p)

print num_of_POC_pcks 

text_file.close()
zinon
  • 4,427
  • 14
  • 70
  • 112

1 Answers1

0

Chapter 8.3.1 in the standard tells you how the PicOrderCntVal is deriverad. In python, this is non-trivial to extract...

Using the reference SW, the slice header is parsed in function TDecCavlc::parseSliceHeader in source/Lib/TLibDecoder/TDecCAVLC.cpp that is also where the POC-value is read.

enter image description here

Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
  • Thank you, yes I saw that but I want I "simplistic" python solution. Thanks anyway. – zinon Sep 17 '14 at 12:13
  • Post the python code you have so far in a gist or similar and I can take a look at it... – Fredrik Pihl Sep 17 '14 at 20:59
  • See the following [gist](https://gist.github.com/figgis/fd509a02d4b1aa89f6ef) for a rudimentary bitstream parser. It provides the correct data for the implemented structures. – Fredrik Pihl Oct 06 '14 at 20:52