Last active
March 3, 2021 16:30
-
-
Save simunovic-antonio/abbf82d6a327bed92a20327c439d6d8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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