From b0a430b586403f9c50e14de4a3871ee0c246ee52 Mon Sep 17 00:00:00 2001 From: "koki.murasawa" Date: Thu, 21 Sep 2023 17:52:17 +0900 Subject: [PATCH 1/4] Raise error for video codecs other than h264 and avc1 --- fastlabel/__init__.py | 8 ++++++++ fastlabel/const.py | 3 +++ fastlabel/utils.py | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index b28bc6a..d1730dc 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -1252,6 +1252,10 @@ def create_video_task( raise FastLabelInvalidException( "Supported video size is under 250 MB.", 422 ) + if not utils.is_video_supported_codec(file_path): + raise FastLabelInvalidException( + "Supported codec is H.264.", 422 + ) file = utils.base64_encode(file_path) payload = {"project": project, "name": name, "file": file} @@ -1316,6 +1320,10 @@ def create_video_classification_task( raise FastLabelInvalidException( "Supported video size is under 250 MB.", 422 ) + if not utils.is_video_supported_codec(file_path): + raise FastLabelInvalidException( + "Supported codec is H.264.", 422 + ) file = utils.base64_encode(file_path) payload = {"project": project, "name": name, "file": file} diff --git a/fastlabel/const.py b/fastlabel/const.py index b059dc8..bd4c1f3 100644 --- a/fastlabel/const.py +++ b/fastlabel/const.py @@ -222,6 +222,9 @@ # API can accept under 250 MB SUPPORTED_OBJECT_SIZE = 250 * math.pow(1024, 2) +# Only 'avc1' and 'H264' are supported for video task creation. +SUPPORTED_CODECS = ["avc1", "H264"] + SUPPORTED_INFERENCE_IMAGE_SIZE = 6 * math.pow(1024, 2) diff --git a/fastlabel/utils.py b/fastlabel/utils.py index 86a5f81..e8cbe8d 100644 --- a/fastlabel/utils.py +++ b/fastlabel/utils.py @@ -5,6 +5,7 @@ import geojson import numpy as np +import cv2 from fastlabel import const @@ -18,6 +19,10 @@ def is_image_supported_ext(file_path: str) -> bool: return file_path.lower().endswith((".png", ".jpg", ".jpeg")) +def is_video_supported_codec(file_path: str) -> bool: + return get_video_codec(file_path) in const.SUPPORTED_CODECS + + def is_video_supported_ext(file_path: str) -> bool: return file_path.lower().endswith(".mp4") @@ -164,3 +169,11 @@ def is_clockwise(points: list) -> bool: def get_json_length(value) -> int: json_str = json.dumps(value) return len(json_str) + + +def get_video_codec(video_path: str) -> str: + cap = cv2.VideoCapture(video_path) + fourcc_code = int(cap.get(cv2.CAP_PROP_FOURCC)) + fourcc_str = "".join([chr((fourcc_code >> 8 * i) & 0xFF) for i in range(4)]) + cap.release() + return fourcc_str From 8621db49e772512ddcf10f5917a646e797cdb333 Mon Sep 17 00:00:00 2001 From: "koki.murasawa" Date: Fri, 22 Sep 2023 11:35:59 +0900 Subject: [PATCH 2/4] Fix SUPPORTED_CODECS --- fastlabel/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlabel/const.py b/fastlabel/const.py index bd4c1f3..caed36c 100644 --- a/fastlabel/const.py +++ b/fastlabel/const.py @@ -223,7 +223,7 @@ SUPPORTED_OBJECT_SIZE = 250 * math.pow(1024, 2) # Only 'avc1' and 'H264' are supported for video task creation. -SUPPORTED_CODECS = ["avc1", "H264"] +SUPPORTED_CODECS = ["avc1"] SUPPORTED_INFERENCE_IMAGE_SIZE = 6 * math.pow(1024, 2) From 7dc8a3ccfb53848f97635b54412ec81b0c7436b4 Mon Sep 17 00:00:00 2001 From: "koki.murasawa" Date: Fri, 22 Sep 2023 11:57:41 +0900 Subject: [PATCH 3/4] Fix variable names for clarity --- fastlabel/const.py | 2 +- fastlabel/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fastlabel/const.py b/fastlabel/const.py index caed36c..2e3074d 100644 --- a/fastlabel/const.py +++ b/fastlabel/const.py @@ -223,7 +223,7 @@ SUPPORTED_OBJECT_SIZE = 250 * math.pow(1024, 2) # Only 'avc1' and 'H264' are supported for video task creation. -SUPPORTED_CODECS = ["avc1"] +SUPPORTED_FOURCC = ["avc1"] SUPPORTED_INFERENCE_IMAGE_SIZE = 6 * math.pow(1024, 2) diff --git a/fastlabel/utils.py b/fastlabel/utils.py index e8cbe8d..d158436 100644 --- a/fastlabel/utils.py +++ b/fastlabel/utils.py @@ -20,7 +20,7 @@ def is_image_supported_ext(file_path: str) -> bool: def is_video_supported_codec(file_path: str) -> bool: - return get_video_codec(file_path) in const.SUPPORTED_CODECS + return get_video_fourcc(file_path) in const.SUPPORTED_FOURCC def is_video_supported_ext(file_path: str) -> bool: @@ -171,7 +171,7 @@ def get_json_length(value) -> int: return len(json_str) -def get_video_codec(video_path: str) -> str: +def get_video_fourcc(video_path: str) -> str: cap = cv2.VideoCapture(video_path) fourcc_code = int(cap.get(cv2.CAP_PROP_FOURCC)) fourcc_str = "".join([chr((fourcc_code >> 8 * i) & 0xFF) for i in range(4)]) From 02ab51e69acfdbc7ccc8c7bfcb867a2577d76956 Mon Sep 17 00:00:00 2001 From: "koki.murasawa" Date: Fri, 22 Sep 2023 15:11:16 +0900 Subject: [PATCH 4/4] Fixed error messages and updated README --- README.md | 2 ++ fastlabel/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 896a1d5..3f5b446 100644 --- a/README.md +++ b/README.md @@ -767,6 +767,8 @@ task_id = client.create_video_task( ##### Limitation - You can upload up to a size of 250 MB. +- You can upload only videos with H.264 encoding. +- You can upload only MP4 file format. #### Find Task diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index d1730dc..e1b99ea 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -1254,7 +1254,7 @@ def create_video_task( ) if not utils.is_video_supported_codec(file_path): raise FastLabelInvalidException( - "Supported codec is H.264.", 422 + "Supported video encoding for registration through the SDK is only H.264.", 422 ) file = utils.base64_encode(file_path) @@ -1322,7 +1322,7 @@ def create_video_classification_task( ) if not utils.is_video_supported_codec(file_path): raise FastLabelInvalidException( - "Supported codec is H.264.", 422 + "Supported video encoding for registration through the SDK is only H.264.", 422 ) file = utils.base64_encode(file_path)