实现 AppleHandler 和 SamsungHandler 类,处理特定于供应商的 HEIC 特性,添加查找嵌入视频的逻辑

This commit is contained in:
Nymiro
2025-10-20 12:10:59 +13:00
parent 8ee1d7984a
commit b4d35521cf
13 changed files with 144 additions and 38 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
+14
View File
@@ -0,0 +1,14 @@
from .base_handler import VendorHandler
class AppleHandler(VendorHandler):
"""
Handles Apple-specific HEIC features.
Apple's motion photos (Live Photos) are stored in a separate MOV file,
so we won't find an embedded video here.
"""
# We override the method to make it explicit that Apple files are handled,
# even though the result is the same as the base class.
def find_motion_photo_offset(self, heic_file) -> int | None:
# We could add logic here later to find the ContentIdentifier
print("Apple HEIC detected. Motion photo video is in a separate .mov file, not embedded.")
return None
+17
View File
@@ -0,0 +1,17 @@
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from heic_file import HEICFile
class VendorHandler:
"""
Abstract base class for vendor-specific logic.
"""
def find_motion_photo_offset(self, heic_file: HEICFile) -> int | None:
"""
Tries to find the byte offset of the embedded motion photo video.
Returns the offset if found, otherwise None.
"""
# Default behavior: no motion photo found.
return None
+17
View File
@@ -0,0 +1,17 @@
from .base_handler import VendorHandler
class SamsungHandler(VendorHandler):
"""Handles Samsung-specific HEIC features, like the embedded mpvd box."""
def find_motion_photo_offset(self, heic_file) -> int | None:
"""
Searches for the 'mpvd' box which contains the video data.
"""
for box in heic_file.boxes:
if box.type == 'mpvd':
print(f"Samsung 'mpvd' box found at offset {box.offset}")
# The video data starts right after the box header.
return box.offset + 8
print("Samsung HEIC detected, but no 'mpvd' box found.")
return None