Video Folder Organizer
Intelligently organize a video folder: clean up non-video files, remove bad footage, analyze content with AI, and sort into categorized subfolders.
Usage
User wants to organize a video folder: $ARGUMENTS
If the user has not provided a folder path, ask them to provide one.
Language note: Detect the language the user is writing in and respond in that language throughout the entire session. Category folder names should also be in the user's language.
Step 1: Scan the Folder
Scan the folder for all files (non-recursive at root level first):
CODEBLOCK0
Report to user:
- - Total files found
- Number of video files
- Number of non-video files (list them)
Step 2: Handle Non-Video Files
Use AskUserQuestion to ask what to do with non-video files (only if any exist):
Question: "Found N non-video file(s). How would you like to handle them?"
Options:
- - "Move to _misc subfolder (Recommended)" — move non-video files into INLINECODE0
- "Delete all non-video files" — permanently delete them
- "Leave them as-is" — do nothing
If user chooses to move:
CODEBLOCK1
If user chooses to delete:
rm [non-video files]
Step 3: Remove Short Videos
Use AskUserQuestion to ask about short video threshold:
Question: "Would you like to remove very short videos?"
Options:
- - "Yes, remove videos shorter than 1 second (default)"
- "Yes, let me specify a duration"
- "No, keep all videos"
If user wants to specify duration, ask them to type the threshold in seconds.
Use ffprobe to check each video's duration:
CODEBLOCK3
List all videos shorter than the threshold, show their filenames and durations, then confirm deletion:
CODEBLOCK4
Step 4: Extract Frames and Analyze Videos with AI Vision
For each remaining video file, extract representative frames using ffmpeg:
CODEBLOCK5
Also detect bad footage quality:
CODEBLOCK6
Use the Read tool to load the extracted frame images, then analyze ALL videos together in one AI analysis pass:
Analyze each video's frames and produce for each video:
- 1. Category: A short label in the user's language describing the content (e.g., highway driving, city street, nature scenery, indoor footage, interview, sports, aerial, food, live event)
- Quality issues:
-
all_black: frames are mostly black (>80% black pixels)
-
shaky: excessive camera movement/shake visible
-
blurry: extremely out of focus
-
none: no issues
After analyzing all videos, present a summary table to the user:
Filename Duration Category Quality
video001.mp4 00:32 highway driving none
video002.mp4 01:15 city street shaky
video003.mp4 00:08 nature scenery all black
...
Step 5: Handle Bad Quality Videos
If any videos were flagged with quality issues (all_black, shaky, blurry):
Use AskUserQuestion:
Question: "The following videos have quality issues: [list filenames and issue types]. How would you like to handle them?"
Options:
- - "Delete all problematic videos"
- "Move to _rejected subfolder"
- "Keep them, do nothing"
- "Decide one by one"
If "Decide one by one", for each bad video use AskUserQuestion with options: Delete / Move to _rejected / Keep
Execute the chosen action for each video.
Step 6: Classify Videos into Numbered Subfolders
Based on the AI analysis categories, propose a folder structure:
- 1. Collect all unique categories from the analysis
- Sort categories by number of videos (most videos first)
- Assign two-digit numbers:
01_, 02_, etc.
Show the proposed structure to the user (folder names in the user's language):
CODEBLOCK8
Use AskUserQuestion:
Question: "Does the proposed folder structure look good?"
Options:
- - "Looks good, proceed"
- "I need to rename some categories"
- "I need to merge some categories"
If user wants adjustments, ask them to specify changes (use Other input), then update the plan.
Execute the file moves:
CODEBLOCK9
After moving all files, confirm completion and show the final structure:
find "$FOLDER" -type d | sort
Step 7: Refine a Category (Optional)
Use AskUserQuestion:
Question: "Would you like to further organize any category folder?"
Options:
- - "No, all done"
- "Yes, let me choose a category"
If user wants to refine, ask which category folder they want to work on (list the created folders as options).
Then ask:
Question: "How would you like to organize this folder?"
Options:
- - "Group by time of day (morning / afternoon / evening)"
- "Group by quality (picks / normal)"
- "Group by length (short / long)"
- "Let me describe how"
Execute the requested sub-organization using the same AI analysis data already collected, or re-analyze if needed.
After completing, loop back to Step 7 to ask if any other category needs refinement.
Technical Notes
Prerequisites
- -
ffmpeg and ffprobe must be installed (brew install ffmpeg) - Use
which ffmpeg to verify before starting
Performance Tips
- - Process frames extraction in batches to avoid overwhelming the system
- For large folders (>50 videos), inform the user this may take a few minutes
- Clean up temp frames after analysis: INLINECODE12
Error Handling
- - If a video file is corrupted and ffprobe fails, mark it as "unreadable" and ask user separately
- If ffmpeg frame extraction fails, skip that video's frames and note in analysis
Folder Safety
- - Never delete files without explicit user confirmation
- Always show what will be deleted/moved before executing
- If unsure, prefer moving to a subfolder over permanent deletion
视频文件夹整理工具
智能整理视频文件夹:清理非视频文件、移除低质量素材、通过AI分析内容,并分类归档到子文件夹中。
使用方法
用户想要整理一个视频文件夹:$ARGUMENTS
如果用户未提供文件夹路径,请要求其提供。
语言提示:检测用户使用的语言,并在整个会话过程中使用该语言回复。分类文件夹名称也应使用用户的语言。
步骤1:扫描文件夹
扫描文件夹中的所有文件(首先在根层级进行非递归扫描):
bash
列出所有文件及其大小
ls -la $FOLDER
查找视频文件(常见扩展名)
find $FOLDER -maxdepth 1 -type f \( \
-iname
.mp4 -o -iname .mov -o -iname
.avi -o -iname .mkv \
-o -iname
.m4v -o -iname .wmv -o -iname
.flv -o -iname .webm \
-o -iname
.mts -o -iname .m2ts -o -iname
.mpg -o -iname .mpeg \
-o -iname
.3gp -o -iname .hevc -o -iname *.ts \
\)
查找非视频文件
find $FOLDER -maxdepth 1 -type f ! \( \
-iname
.mp4 -o -iname .mov -o -iname
.avi -o -iname .mkv \
-o -iname
.m4v -o -iname .wmv -o -iname
.flv -o -iname .webm \
-o -iname
.mts -o -iname .m2ts -o -iname
.mpg -o -iname .mpeg \
-o -iname
.3gp -o -iname .hevc -o -iname *.ts \
\)
向用户报告:
- - 找到的文件总数
- 视频文件数量
- 非视频文件数量(列出它们)
步骤2:处理非视频文件
使用AskUserQuestion询问如何处理非视频文件(仅当存在时):
问题:找到N个非视频文件。您希望如何处理它们?
选项:
- - 移动到misc子文件夹(推荐) — 将非视频文件移动到$FOLDER/misc/
- 删除所有非视频文件 — 永久删除它们
- 保持原样 — 不做任何操作
如果用户选择移动:
bash
mkdir -p $FOLDER/_misc
mv [非视频文件] $FOLDER/_misc/
如果用户选择删除:
bash
rm [非视频文件]
步骤3:移除短视频
使用AskUserQuestion询问短视频阈值:
问题:您是否希望移除非常短的视频?
选项:
- - 是,移除短于1秒的视频(默认)
- 是,让我指定时长
- 否,保留所有视频
如果用户想要指定时长,请要求他们以秒为单位输入阈值。
使用ffprobe检查每个视频的时长:
bash
ffprobe -v quiet -showentries format=duration -of csv=p=0 $VIDEOFILE
列出所有短于阈值的视频,显示其文件名和时长,然后确认删除:
bash
rm $SHORT_VIDEO
步骤4:使用AI视觉提取帧并分析视频
对于每个剩余的视频文件,使用ffmpeg提取代表性帧:
bash
为帧创建临时目录
mkdir -p /tmp/video_frames
从每个视频中提取4个均匀分布的帧
(在时长的10%、30%、60%、90%处)
DURATION=$(ffprobe -v quiet -show_entries format=duration -of csv=p=0 $VIDEO)
ffmpeg -ss $(echo $DURATION * 0.10 | bc) -i $VIDEO -frames:v 1 /tmp/video
frames/${BASENAME}01.jpg -y -loglevel quiet
ffmpeg -ss $(echo $DURATION * 0.30 | bc) -i $VIDEO -frames:v 1 /tmp/video
frames/${BASENAME}02.jpg -y -loglevel quiet
ffmpeg -ss $(echo $DURATION * 0.60 | bc) -i $VIDEO -frames:v 1 /tmp/video
frames/${BASENAME}03.jpg -y -loglevel quiet
ffmpeg -ss $(echo $DURATION * 0.90 | bc) -i $VIDEO -frames:v 1 /tmp/video
frames/${BASENAME}04.jpg -y -loglevel quiet
同时检测低质量素材:
bash
检查全黑帧:计算帧的平均亮度
ffmpeg -i $VIDEO -ss $(echo $DURATION * 0.5 | bc) -frames:v 1 -vf blackdetect=d=0.1:pix_th=0.10 -f null - 2>&1
使用场景检测/运动向量检查过度抖动
ffmpeg -i $VIDEO -vf select=gt(scene,0.4),setpts=N/TB -frames:v 5 /tmp/video
frames/${BASENAME}shake_%02d.jpg -y -loglevel quiet 2>&1
使用读取工具加载提取的帧图像,然后一次性对所有视频进行AI分析:
分析每个视频的帧,并为每个视频生成:
- 1. 类别:使用用户语言描述内容的简短标签(例如,高速公路驾驶、城市街道、自然风景、室内录像、采访、体育、航拍、美食、现场活动)
- 质量问题:
- 全黑:帧大部分为黑色(>80%黑色像素)
- 抖动:可见过度相机移动/抖动
- 模糊:极度失焦
- 无:没有问题
分析完所有视频后,向用户呈现摘要表格:
文件名 时长 类别 质量
video001.mp4 00:32 高速公路驾驶 无
video002.mp4 01:15 城市街道 抖动
video003.mp4 00:08 自然风景 全黑
...
步骤5:处理低质量视频
如果任何视频被标记为质量问题(全黑、抖动、模糊):
使用AskUserQuestion:
问题:以下视频存在质量问题:[列出文件名和问题类型]。您希望如何处理它们?
选项:
- - 删除所有有问题的视频
- 移动到_rejected子文件夹
- 保留它们,不做任何操作
- 逐个决定
如果选择逐个决定,对于每个问题视频,使用AskUserQuestion提供选项:删除 / 移动到_rejected / 保留
对每个视频执行所选操作。
步骤6:将视频分类到编号子文件夹
基于AI分析类别,建议文件夹结构:
- 1. 收集分析中所有唯一的类别
- 按视频数量对类别排序(视频最多的优先)
- 分配两位数字:01、02等
向用户显示建议的结构(文件夹名称使用用户的语言):
建议的文件夹结构:
01_高速公路驾驶 (12个视频)
02_城市街道 (8个视频)
03_自然风景 (5个视频)
04_室内 (3个视频)
使用AskUserQuestion:
问题:建议的文件夹结构看起来合适吗?
选项:
- - 看起来不错,继续
- 我需要重命名一些类别
- 我需要合并一些类别
如果用户想要调整,请要求他们指定更改(使用其他输入),然后更新计划。
执行文件移动:
bash
mkdir -p $FOLDER/01_高速公路驾驶
mv $VIDEO $FOLDER/01_高速公路驾驶/
移动所有文件后,确认完成并显示最终结构:
bash
find $FOLDER -type d | sort
步骤7:细化类别(可选)
使用AskUserQuestion:
问题:您是否希望进一步整理某个类别文件夹?
选项:
如果用户想要细化,询问他们想要处理哪个类别文件夹(将创建的文件夹列为选项)。
然后询问:
问题:您希望如何整理这个文件夹?
选项:
- - 按时间段分组(上午/下午/晚上)
- 按质量分组(精选/普通)
- 按长度分组(短/长)
- 让我描述如何分组
使用已收集的相同AI分析数据执行请求的子整理,或根据需要重新分析。
完成后,循环回到步骤7,询问是否需要细化其他类别。
技术说明