Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(upload): accept multi-picture camera JPEG materials

Rudy Celeklie426d696bb3e
diff --git a/app/services/material_upload.py b/app/services/material_upload.py
index b36085a1..1c200488 100644
--- a/app/services/material_upload.py
+++ b/app/services/material_upload.py
@@ -62,9 +62,11 @@ _UNSAFE_FILENAME_CHARACTERS = frozenset(
*range(0x2066, 0x206A),
)
)
+# Pillow reports camera JPEGs carrying a Multi-Picture Format index (common for
+# phone and dual-lens photos) as MPO; the primary image is still a plain JPEG.
_IMAGE_FORMATS_BY_EXTENSION = {
- ".jpg": frozenset({"JPEG"}),
- ".jpeg": frozenset({"JPEG"}),
+ ".jpg": frozenset({"JPEG", "MPO"}),
+ ".jpeg": frozenset({"JPEG", "MPO"}),
".png": frozenset({"PNG"}),
".bmp": frozenset({"BMP"}),
}
diff --git a/test/services/test_material_upload.py b/test/services/test_material_upload.py
index 43b952f1..99a55042 100644
--- a/test/services/test_material_upload.py
+++ b/test/services/test_material_upload.py
@@ -216,6 +216,35 @@ class TestMaterialUploadService(unittest.TestCase):
)
self.assertEqual(os.listdir(temp_dir), [])
+ def test_multi_picture_camera_jpeg_is_accepted(self):
+ # Phones and dual-lens cameras embed an MPF index in ordinary .jpg
+ # photos; Pillow reports those files as MPO rather than JPEG.
+ output = io.BytesIO()
+ Image.new("RGB", (4, 4), color="red").save(
+ output,
+ format="MPO",
+ save_all=True,
+ append_images=[Image.new("RGB", (2, 2), color="blue")],
+ )
+ with tempfile.TemporaryDirectory() as temp_dir:
+ with patch.object(
+ material_upload, "uploaded_material_dir", return_value=temp_dir
+ ):
+ stored_name = material_upload.save_material_upload(
+ "IMG_0001.JPG", io.BytesIO(output.getvalue())
+ )
+ with self.assertRaisesRegex(
+ material_upload.MaterialUploadError, "does not match"
+ ):
+ material_upload.save_material_upload(
+ "renamed.png", io.BytesIO(output.getvalue())
+ )
+
+ self.assertTrue(stored_name.endswith(".jpg"))
+ with Image.open(os.path.join(temp_dir, stored_name)) as image:
+ self.assertEqual(image.format, "MPO")
+ self.assertEqual(image.size, (4, 4))
+
def test_webm_and_bmp_materials_are_accepted(self):
with tempfile.TemporaryDirectory() as temp_dir:
with (