Potential Bug RSTP Feed, Trying to Split Recording Over Multiple MP4 Fails Playback on Second Recording #1734
Unanswered
UltimateCodeWarrior
asked this question in
1. Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi All,
Writing out 10 second chunks of .mp4 files from a rstp feed. First Video Plays Back Fine, Second Video is written but contains 'no playable streams' even though it's roughly the same size as first video. Can anyone spot anything wrong with this code? I don't wish for any dropped frames so I am not trying to reconnect to the source each time, I'm just switching the output. Does this work or is there a better way?
`import av
import time
Open the RTSP feed
try:
source = av.open('rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0', metadata_encoding='utf-8')
except OSError as e:
print(f"Error opening RTSP feed: {e}")
exit(1)
def create_output_file():
try:
output = av.open('output-%s.mp4' % time.time(), mode='w')
in_to_out = {}
for stream in source.streams:
if stream.type in ('audio', 'video'):
try:
in_to_out[stream] = output.add_stream_from_template(stream)
except OSError as e:
print(f"Error adding stream: {e}")
source.close()
output.close()
exit(1)
return output, in_to_out
except OSError as e:
print(f"Error creating output file: {e}")
source.close()
exit(1)
Create the initial output file
output, in_to_out = create_output_file()
Process packets and save 10 seconds of data
start_time = time.time()
timeout = 5 # Timeout in seconds
last_packet_time = time.time()
try:
for packet in source.demux():
current_time = time.time()
if current_time - last_packet_time > timeout:
print("Timeout: No packets received for {} seconds".format(timeout))
break
except OSError as e:
print(f"An error occurred during demuxing/muxing: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
finally:
try:
output.close()
except Exception as e:
print(f"Error closing output file: {e}")
Beta Was this translation helpful? Give feedback.
All reactions