Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import io
import av
input_container = av.open("rtsp://CAMERA_IP_ADDRESS:554/Streaming/Channels/101", "r")
input_stream = input_container.streams.video[0]
output_buffer = io.BytesIO()
output_container = av.open(output_buffer, 'w', format="mp4", options={"strict":"-1", "movflags":"empty_moov+omit_tfhd_offset+frag_keyframe+default_base_moof"})
output_stream = output_container.add_stream(template=input_stream)
first_packet = True
for packet in input_container.demux(input_stream):
if first_packet:
packet.dts = 0
packet.pts = 0
first_packet = False
packet.stream = output_stream
output_container.mux_one(packet)
result = output_buffer.getvalue()
if result:
print("YES", packet.is_keyframe)
output_buffer.truncate(0)
output_buffer.seek(0)
else:
print("NO", packet.is_keyframe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment