Answer the question
In order to leave comments, you need to log in
How to catch the desired ffmpeg-python exception?
ffmpeg connects via rtsp to get a picture from the camera.
Sometimes it happens that rtsp crashes and I need to catch exactly except about " Connection to tcp:// " and print it to the terminal, without any additional information that I get. (See screenshot.)
The piece of code itself:
def main():
nowMSK = datetime.now(timezone('Europe/Moscow'))
cap = datetime.now().strftime('%H:%M:%S')
nowOut = nowMSK.strftime("media/snap-%d-%m-%Y-%H-%M-%S.jpg")
try:
process = (
ffmpeg
.input(cam1, rtsp_transport="tcp", vsync="2")
.output(nowOut, vframes="1")
.run(capture_stdout=True, capture_stderr=True)
)
except ffmpeg.Error as e:
print ("---------------" * 10)
print('stderr:', e.stderr.decode('utf8'))
sys.exit(0)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question