title: Parsing hevc bitstream
body: <p>Is there a way to parse an HEVC bitstream file?</p>
  
  <p>I want to be able to create a new bitstream file having selected nal unit packets selected from the original bitstream file.</p>
  
  <p>Edit: I inserted my code. Please find my bitstream file <a href="https://drive.google.com/file/d/0B-CFx75Ro7vGX2RhN2RLYzBDMlU/edit?usp=sharing" rel="noreferrer">here</a>.</p>
  
  <pre><code>#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
  </code></pre>