Why does this code detects images as video and how can I fix it?

Question:

This method is detecting .jpg pictures as video. Why is that? How can I fix it?

def is_video(self) -> bool:
    try:
        res = self.video_metadata['codec_type'] == 'video'
        logger.info(f"Video.is_video() -> {res}")
        return res
    except:
        return False

I’m getting the metadata with

ffmpeg.probe(self.path, select_streams = stream)['streams'][0]

I’m using the metadata for more things, that’s why I’ve used ffmpeg in this method.

Asked By: Arturo

||

Answers:

Check for number of frames greater than 1 to distinguish between image and video.

def is_video(self) -> bool:
    try:
        res = (self.video_metadata['codec_type'] == 'video'
               and int(self.video_metadata['nb_frames']) > 1)
        logger.info(f"Video.is_video() -> {res}")
        return res
    except:
        return False
Answered By: Arturo
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.