-
How can I get the sidedata of type SEI_UNREGISTERED and convert it to a byte array or string object? |
Beta Was this translation helpful? Give feedback.
Answered by
david6096
Dec 12, 2024
Replies: 2 comments 1 reply
-
I'v gotten it! data = frame.side_data.get(av.sidedata.sidedata.Type.SEI_UNREGISTERED)
if data is not None:
buf = bytes(data)
s1 = buf[16:].decode("utf-8")
print(s1) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
WyattBlue
-
thank you for the info - it was helpful in figuring out how to parse the import sys
import av
import av.sidedata
import av.sidedata.sidedata
def decode_smpte_timecode(byte_data, fps=60.0):
field_multiplier = 1
if fps > 90.0:
field_multiplier = 4
elif fps > 60.0:
field_multiplier = 3
elif fps > 30.0:
field_multiplier = 2
bits_data = bin(int.from_bytes(byte_data, byteorder="big"))[27:59]
def bin_to_int(start):
return int("".join(map(str, bits_data[start : start + 4 - start % 4])), 2)
hours_tens = bin_to_int(0)
hours_ones = bin_to_int(4)
minutes_tens = bin_to_int(8)
minutes_ones = bin_to_int(12)
frames_field = int(bits_data[16])
seconds_tens = bin_to_int(17)
seconds_ones = bin_to_int(20)
frames_tens = bin_to_int(24)
frames_ones = bin_to_int(28)
hours = (hours_tens * 10) + hours_ones
minutes = (minutes_tens * 10) + minutes_ones
seconds = (seconds_tens * 10) + seconds_ones
frames = ((frames_tens * 10) + frames_ones) * field_multiplier + frames_field
return f"{hours:02}:{minutes:02}:{seconds:02}:{frames:02}"
def frame_iter(video):
streams = video.streams.video
for packet in video.demux(streams):
for frame in packet.decode():
yield frame
frames = frame_iter(av.open(sys.argv[1]))
for frame in frames:
data = frame.side_data.get(av.sidedata.sidedata.Type.S12M_TIMECODE)
if data is not None:
print(decode_smpte_timecode(bytes(data))) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'v gotten it!