Hiding log (Missing reference picture, default is 0 | decode_slice_header error)

I am using OpenCV to read the video with specific frame

cap = cv2.VideoCapture(video_path)
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_index)
ret, frame = cap.read()

I got the message

Missing reference picture, default is 0 
decode_slice_header error

I believe the problem might be because of my video file. This result is not effect anything to my reading frame and face detection.
But the problem for me is, I just want to hide this log from my Jupyter to can present a clean paper to my client.

Can someone suggest me the best way to approach this?

main problem is, like any other python noob, you’re ignoring the ret value from cap.read() (copy-paste code)

you MUST check, if reading was successful, else you run into further problems, trying to process an invalid image

Those messages come from ffmpeg and its codecs.

This message lets you know that your video stream is incomplete. You are likely to get artefacts in the following few frames.

I don’t know of a way to quiet this output. It might be possible with undocumented environment variables.

There might be a way to redirect stdout but that might also interfere with Jupyter.

You could just transcode that video file, using ffmpeg. Then you’ll have a clean file.

1 Like

@crackwitz yeah transcode with ffmpeg work for me. I just use ffmpeg generate new file and it solve my problem. Big thanks for this.

It is the sample code to explain what is happening. Anyway, what you mention is not related to what I am asking.