Skip to content

Instantly share code, notes, and snippets.

@scateu
Forked from nvloff/nalus.py
Created October 10, 2013 02:16
Show Gist options
  • Save scateu/6911977 to your computer and use it in GitHub Desktop.
Save scateu/6911977 to your computer and use it in GitHub Desktop.
import base64
import sys
def get_nalus(file_name, count):
bitstream = open(file_name, "rb")
data = bitstream.read(count*3000)
data = base64.b16encode(data)
nalus = data.split('00000001')
for nalu in nalus[1:count+1]:
nalu_t = int(nalu[0:2],16) & int('1f',16)
print "Nalu Type: %s" %(nalu_t)
print nalu
print base64.b64encode(base64.b16decode(nalu))
bitstream.close()
if __name__ == '__main__':
if len(sys.argv) < 3:
print "Usage: python nalus.py filename nalu_count"
exit()
get_nalus(sys.argv[1],int(sys.argv[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment