|
Hey all, I know this is a weird question but I'd like to get the encoded packet data before the decoding process, not the decoded data. I'm following the example at PyAv/basics/parse.py and am able to get the packets just fine. I am unsure what field or function to use to get the data out of the packet; I see there's a buffer pointer with the expected buffer size, I see there's a memcpy call in buffer.py, but I'm not sure how I would flip that to get the data from the Packet type. Any suggestions would be great! |
Replies: 2 comments
|
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. |
|
Awesome, I am honestly glad I was overthinking it. Thank you for the help! |
Packet implements Python’s buffer protocol, so you can get its encoded payload with bytes(packet):
This makes a copy. If you only need to inspect the data without copying it, use:
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.