Skip to content

Commit

Permalink
add new mime types to check
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Oct 27, 2023
1 parent 00220cc commit 1cca73e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions roboflow/models/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

MAXIMUM_VIDEO_SIZE = 1024 * 1024 * 1024 * 5 # 5GB

SUPPORTED_ROBOFLOW_MODELS = ["object-detection", "classification", "instance-segmentation"]

SUPPORTED_ADDITIONAL_MODELS = {
"clip": {
"model_id": "clip",
Expand All @@ -26,10 +28,10 @@
}


def is_mp4(filename):
def is_valid_mime(filename):
mime = magic.Magic(mime=True)
file_type = mime.from_file(filename)
return file_type == "video/mp4"
return file_type in ["video/mp4", "video/avi", "video/webm"]


def is_valid_video(filename):
Expand All @@ -38,7 +40,7 @@ def is_valid_video(filename):
return False

# check file type
if not is_mp4(filename):
if not is_valid_mime(filename):
return False

return True
Expand All @@ -63,15 +65,16 @@ def __init__(
def predict(
self,
video_path: str,
inference_type: str,
fps: int = 5,
additional_models: list = None,
) -> List[str, str]:
"""
Infers detections based on image from specified model and image path.
Args:
image_path (str): path to the image you'd like to perform prediction on
video_path (str): path to the video you'd like to perform prediction on
inference_type (str): type of the model to run
fps (int): frames per second to run inference
Returns:
Expand All @@ -97,6 +100,9 @@ def predict(
for model in additional_models:
if model not in SUPPORTED_ADDITIONAL_MODELS:
raise Exception(f"Model {model} is not supported for video inference.")

if inference_type not in SUPPORTED_ROBOFLOW_MODELS:
raise Exception(f"Model {inference_type} is not supported for video inference.")

if not is_valid_video(video_path):
raise Exception("Video path is not valid")
Expand All @@ -121,7 +127,7 @@ def predict(
{
"model_id": self.dataset_id,
"model_version": self.version,
"inference_type": "object-detection",
"inference_type": self.inference_type,
}
]

Expand Down

0 comments on commit 1cca73e

Please sign in to comment.