V
V
Vlad Bonem2021-09-25 17:37:44
Python
Vlad Bonem, 2021-09-25 17:37:44

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.)

1632581625-2899.png

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 question

Ask a Question

731 491 924 answers to any question