Skip to content
Discussion options

You must be logged in to vote

Packet implements Python’s buffer protocol, so you can get its encoded payload with bytes(packet):

for packet in codec.parse(chunk):
    encoded_data = bytes(packet)
    print(len(encoded_data))

This makes a copy. If you only need to inspect the data without copying it, use:

encoded_data = memoryview(packet)

There’s no need to access buffer_ptr or call memcpy directly. In the parse.py example, bytes(packet) contains the parsed H.264 Annex B packet before codec.decode(packet) is called.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by sweeneyal
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants