Skip to content

Instantly share code, notes, and snippets.

@simunovic-antonio
Last active March 3, 2021 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simunovic-antonio/abbf82d6a327bed92a20327c439d6d8c to your computer and use it in GitHub Desktop.
Save simunovic-antonio/abbf82d6a327bed92a20327c439d6d8c to your computer and use it in GitHub Desktop.
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