Disable "moov atom not found" log

I’m currently working on a project which includes scanning video files and retrieving the length of the video using cv2. The project uses a plugin-based architecture. The main program collects json outputs from multiple sub-programs. One of these sub-programs is the video scan plugin.

The plugin is supposed to return a json including the data we retrieve from a video file, but whenever there is a corrupt video file, open cv prints out the message:

[mov,mp4,m4a,3gp,3g2,mj2 @ 00000278e63e2f40] moov atom not found

This message gets appended to the plugin’s json output. The main program then can’t convert it into valid json, since there is extra data outside of the json object.

The code for the video duration calculation:

def calculate_duration_video(video_file: str) -> int:
    cap = cv2.VideoCapture()
    cap.setExceptionMode(True)
    fps = 0
    frame_count = 0
    duration = 0
    try:
        # Öffnen der Datei
        cap.open(video_file)
        if cap.isOpened():
            # FPS und Anzahl der Frames auslesen
            fps = cap.get(cv2.CAP_PROP_FPS)
            frame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)
            cap.release()

        if fps > 0 and frame_count > 0:
            # Dauer des Videos berechnen
            duration += frame_count / fps
    except Exception:
        return 0

    return duration

Is there any way to disable opencv printing this error message?