set_video_resolution
Adjust video resolution to a specified target (e.g., '1920x1080') while preserving the audio stream. Input and output paths are required for processing.
Instructions
Sets the resolution of a video, attempting to copy the audio stream. Args: input_video_path: Path to the source video file. output_video_path: Path to save the video with the new resolution. resolution: Target video resolution (e.g., '1920x1080', '1280x720', or '720' for height). Returns: A status message indicating success or failure.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input_video_path | Yes | ||
| output_video_path | Yes | ||
| resolution | Yes |
Implementation Reference
- server.py:364-384 (handler)The core handler function for the set_video_resolution MCP tool. It uses FFmpeg to scale the video to the target resolution via video filter (vf), attempts to copy the audio stream for efficiency, and falls back to full re-encoding if needed. Registered via @mcp.tool() decorator.@mcp.tool() def set_video_resolution(input_video_path: str, output_video_path: str, resolution: str) -> str: """Sets the resolution of a video, attempting to copy the audio stream. Args: input_video_path: Path to the source video file. output_video_path: Path to save the video with the new resolution. resolution: Target video resolution (e.g., '1920x1080', '1280x720', or '720' for height). Returns: A status message indicating success or failure. """ vf_filters = [] if 'x' in resolution: vf_filters.append(f"scale={resolution}") else: vf_filters.append(f"scale=-2:{resolution}") vf_filter_str = ",".join(vf_filters) primary_kwargs = {'vf': vf_filter_str, 'acodec': 'copy'} fallback_kwargs = {'vf': vf_filter_str} # Re-encode audio return _run_ffmpeg_with_fallback(input_video_path, output_video_path, primary_kwargs, fallback_kwargs)
- server.py:332-349 (helper)Supporting helper utility invoked by set_video_resolution (and similar tools) to execute FFmpeg operations with a primary attempt (e.g., stream copy) and fallback re-encoding on failure, providing consistent error handling and status messages.def _run_ffmpeg_with_fallback(input_path: str, output_path: str, primary_kwargs: dict, fallback_kwargs: dict) -> str: """Helper to run ffmpeg command with primary kwargs, falling back to other kwargs on ffmpeg.Error.""" try: ffmpeg.input(input_path).output(output_path, **primary_kwargs).run(capture_stdout=True, capture_stderr=True) return f"Operation successful (primary method) and saved to {output_path}" except ffmpeg.Error as e_primary: try: ffmpeg.input(input_path).output(output_path, **fallback_kwargs).run(capture_stdout=True, capture_stderr=True) return f"Operation successful (fallback method) and saved to {output_path}" except ffmpeg.Error as e_fallback: err_primary_msg = e_primary.stderr.decode('utf8') if e_primary.stderr else str(e_primary) err_fallback_msg = e_fallback.stderr.decode('utf8') if e_fallback.stderr else str(e_fallback) return f"Error. Primary method failed: {err_primary_msg}. Fallback method also failed: {err_fallback_msg}" except FileNotFoundError: return f"Error: Input file not found at {input_path}" except Exception as e: return f"An unexpected error occurred: {str(e)}"