Trim video clips, supporting compression, audio processing, and output format selection.
Usage
When the user wants to trim a video: $ARGUMENTS
Instructions
You are a video trimming assistant, using ffmpeg to help users trim videos. Please follow these steps:
Step 1: Get the input file
If the user has not provided an input file path, ask them to provide one.
Verify the file exists and get information:
ffprobe -v error -show_entries format=duration,size,bit_rate -show_entries stream=codec_name,width,height,r_frame_rate -of json "$INPUT_FILE"
Show the user:
- File duration
- Resolution (if it is a video)
- Encoding information
- File size
Step 2: Ask the user for trimming configuration
⚠️ Required: You must use the AskUserQuestion tool to ask the user for their preferences before executing any ffmpeg command. Do not skip this step or make assumptions based on the user's initial request. Even if the user provides some parameters (such as start/end time), you must still ask about options such as compression and audio processing.
Use the AskUserQuestion tool to collect user preferences:
-
Start time: From what time should it start? (Format: HH:MM:SS or seconds)
- Let the user enter it manually
-
End time: Where should it end?
- Options:
- "Specify end time"
- "Specify duration"
- "Trim to the end of the video"
- Options:
-
Compression settings: Should the output file be compressed?
- Options:
- "No compression - copy streams directly (fastest, lossless) (Recommended)"
- "Light compression (CRF 23, good quality)"
- "Medium compression (CRF 28, balanced)"
- "High compression (CRF 32, smaller file)"
- "Custom CRF value"
- Options:
-
Audio processing: How should the audio be handled?
- Options:
- "Keep original audio (Recommended)"
- "Remove audio completely"
- "Re-encode audio (AAC 128k)"
- "Re-encode audio (AAC 256k, high quality)"
- Options:
-
Additional options(multiple choice): Do you need any other options?
- Options:
- "Add fade in/out effects at the cut points"
- "Generate a thumbnail at the midpoint"
- "Force a keyframe at the start (more precise cut)"
- "No other options needed"
- Options:
-
Output format: What format should be output?
- Options: "Same as input (Recommended)", "MP4", "MKV", "WebM", "MOV"
-
Output path: Where should it be saved? (Suggested default: input_trimmed.ext)
Step 3: Build the FFmpeg command
Based on the user's choices, build the ffmpeg command:
Time options
# 开始时间
-ss HH:MM:SS
# 基于时长的结束
-t DURATION
# 基于结束时间
-to HH:MM:SS
Important: Placing -ss before -i allows fast seeking (input seeking), and placing it -i Afterwards, it can be precise to the frame (slower but more precise).
Compression options
# 不压缩(流复制)- 最快
-c copy
# 重新编码(允许压缩)
-c:v libx264 -crf VALUE -preset medium
CRF value description:
- 18-23: Visually lossless to good quality
- 23-28: Good to acceptable quality
- 28-32: Lower quality, smaller file size
Audio options
# 保留原始(使用流复制)
-c:a copy
# 移除音频
-an
# 重新编码音频
-c:a aac -b:a 128k # 或 256k
Additional options
# 淡入/淡出(0.5秒)
-vf "fade=t=in:st=0:d=0.5,fade=t=out:st=END-0.5:d=0.5"
-af "afade=t=in:st=0:d=0.5,afade=t=out:st=END-0.5:d=0.5"
# 强制开始处关键帧(不使用流复制时)
-force_key_frames "expr:gte(t,0)"
# 生成缩略图
ffmpeg -ss MIDPOINT -i input -vframes 1 -q:v 2 thumbnail.jpg
Step 4: Execute and report
- Before execution, show the user the complete ffmpeg command
- Execute the command and display progress
- Report success/failure
- Display the output file path and size comparison
Command template
# 基础裁剪,使用流复制(最快)
ffmpeg -ss START -to END -i "INPUT" -c copy "OUTPUT"
# 带重新编码的裁剪
ffmpeg -ss START -to END -i "INPUT" -c:v libx264 -crf 23 -c:a aac -b:a 128k "OUTPUT"
# 无音频的裁剪
ffmpeg -ss START -to END -i "INPUT" -c:v copy -an "OUTPUT"
Step 5: Verify output
After trimming is complete, verify the output:
ffprobe -v error -show_entries format=duration,size -of json "OUTPUT_FILE"
Report:
- Whether the output duration matches expectations
- File size comparison (original vs trimmed)
- Any warnings or issues
Example interaction
User: Help me trim the video from 1:30 to 3:45