mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 11:33:25 +00:00
fix: Update conversion service to support WebM files and improve documentation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Conversion service for AVI to MKV remux with metadata preservation.
|
||||
"""Conversion service for video to MKV remux with metadata preservation.
|
||||
|
||||
This service manages the process of converting AVI files to MKV container:
|
||||
This service manages the process of converting AVI/MPG/MPEG/WebM files to MKV container:
|
||||
- Fast stream copy (no re-encoding)
|
||||
- Audio language detection and mapping from filename
|
||||
- Subtitle file detection and inclusion
|
||||
@@ -21,13 +21,13 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ConversionService:
|
||||
"""Service for converting AVI files to MKV with metadata preservation.
|
||||
"""Service for converting video files to MKV with metadata preservation.
|
||||
|
||||
This service handles:
|
||||
- Validating AVI files for conversion
|
||||
- Validating video files for conversion (AVI, MPG, MPEG, WebM)
|
||||
- Detecting nearby subtitle files
|
||||
- Mapping audio languages from filename to tracks
|
||||
- Building ffmpeg command for fast remux
|
||||
- Building ffmpeg command for fast remux or HEVC encoding
|
||||
- Executing conversion with progress
|
||||
|
||||
Example:
|
||||
@@ -168,18 +168,18 @@ class ConversionService:
|
||||
return ':'.join(base_params + cpu_params)
|
||||
|
||||
def can_convert(self, file_path: Path) -> bool:
|
||||
"""Check if a file can be converted (is AVI, MPG, or MPEG).
|
||||
"""Check if a file can be converted (is AVI, MPG, MPEG, or WebM).
|
||||
|
||||
Args:
|
||||
file_path: Path to the file to check
|
||||
|
||||
Returns:
|
||||
True if file is AVI, MPG, or MPEG and can be converted
|
||||
True if file is AVI, MPG, MPEG, or WebM and can be converted
|
||||
"""
|
||||
if not file_path.exists() or not file_path.is_file():
|
||||
return False
|
||||
|
||||
return file_path.suffix.lower() in {'.avi', '.mpg', '.mpeg'}
|
||||
return file_path.suffix.lower() in {'.avi', '.mpg', '.mpeg', '.webm'}
|
||||
|
||||
def find_subtitle_files(self, video_path: Path) -> List[Path]:
|
||||
"""Find subtitle files near the video file.
|
||||
@@ -280,12 +280,13 @@ class ConversionService:
|
||||
- Sets MKV title from filename
|
||||
|
||||
Args:
|
||||
source_path: Source video file (AVI, MPG, or MPEG)
|
||||
source_path: Source video file (AVI, MPG, MPEG, or WebM)
|
||||
mkv_path: Destination MKV file
|
||||
audio_languages: Language codes for each audio track
|
||||
subtitle_files: List of subtitle files to include
|
||||
encode_hevc: If True, encode video to HEVC instead of copying
|
||||
crf: Constant Rate Factor for HEVC (18=visually lossless, 23=high quality default)
|
||||
preset: x265 preset (ultrafast, veryfast, faster, fast, medium, slow)
|
||||
|
||||
Returns:
|
||||
List of command arguments for subprocess
|
||||
@@ -357,10 +358,10 @@ class ConversionService:
|
||||
crf: int = 18,
|
||||
preset: str = 'medium'
|
||||
) -> Tuple[bool, str]:
|
||||
"""Convert AVI/MPG/MPEG file to MKV with metadata preservation.
|
||||
"""Convert video file to MKV with metadata preservation.
|
||||
|
||||
Args:
|
||||
avi_path: Source video file path (AVI, MPG, or MPEG)
|
||||
avi_path: Source video file path (AVI, MPG, MPEG, or WebM)
|
||||
extractor: Optional MediaExtractor (creates new if None)
|
||||
output_path: Optional output path (defaults to same name with .mkv)
|
||||
dry_run: If True, build command but don't execute
|
||||
@@ -381,7 +382,7 @@ class ConversionService:
|
||||
"""
|
||||
# Validate input
|
||||
if not self.can_convert(avi_path):
|
||||
error_msg = f"File is not a supported format (AVI/MPG/MPEG) or doesn't exist: {avi_path}"
|
||||
error_msg = f"File is not a supported format (AVI/MPG/MPEG/WebM) or doesn't exist: {avi_path}"
|
||||
logger.error(error_msg)
|
||||
return False, error_msg
|
||||
|
||||
|
||||
Reference in New Issue
Block a user