Encode and decode FourCC codes, in Python

Convert the string “H264” to an integer code:

sum([ord(c) << (i * 8) for i, c in enumerate(“H264″)])

Convert the integer code (0x34363248) back to a string:

”.join([chr((0x34363248 >> (i * 8)) & 0xff) for i in range(4)])

Se…


This content originally appeared on DEV Community and was authored by Mansour Moufid

Convert the string "H264" to an integer code:

sum([ord(c) << (i * 8) for i, c in enumerate("H264")])

Convert the integer code (0x34363248) back to a string:

''.join([chr((0x34363248 >> (i * 8)) & 0xff) for i in range(4)])

See this gist: https://gist.github.com/eliteraspberries/b017f998c97c395881f0d2f05a08ec60


This content originally appeared on DEV Community and was authored by Mansour Moufid


Print Share Comment Cite Upload Translate Updates
APA

Mansour Moufid | Sciencx (2022-03-28T23:37:33+00:00) Encode and decode FourCC codes, in Python. Retrieved from https://www.scien.cx/2022/03/28/encode-and-decode-fourcc-codes-in-python/

MLA
" » Encode and decode FourCC codes, in Python." Mansour Moufid | Sciencx - Monday March 28, 2022, https://www.scien.cx/2022/03/28/encode-and-decode-fourcc-codes-in-python/
HARVARD
Mansour Moufid | Sciencx Monday March 28, 2022 » Encode and decode FourCC codes, in Python., viewed ,<https://www.scien.cx/2022/03/28/encode-and-decode-fourcc-codes-in-python/>
VANCOUVER
Mansour Moufid | Sciencx - » Encode and decode FourCC codes, in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/28/encode-and-decode-fourcc-codes-in-python/
CHICAGO
" » Encode and decode FourCC codes, in Python." Mansour Moufid | Sciencx - Accessed . https://www.scien.cx/2022/03/28/encode-and-decode-fourcc-codes-in-python/
IEEE
" » Encode and decode FourCC codes, in Python." Mansour Moufid | Sciencx [Online]. Available: https://www.scien.cx/2022/03/28/encode-and-decode-fourcc-codes-in-python/. [Accessed: ]
rf:citation
» Encode and decode FourCC codes, in Python | Mansour Moufid | Sciencx | https://www.scien.cx/2022/03/28/encode-and-decode-fourcc-codes-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.