wangzhibo
2024-12-04 d87753061d40595bfb1d5b296cc777e1094f3ccf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@echo off
rem 输出支持中文
chcp 65001 >nul
echo 支持中文
 
rem 检查输入参数是否存在
if "%~1"=="" (
    echo 请提供一个文件或文件夹路径作为参数。
    exit /b
)
 
rem 初始化计数器
set /a count=0
 
rem 检查输入是文件还是文件夹
if exist "%~1\" (
    call :process_folder "%~1"
) else if exist "%~1" (
    call :process_file "%~1"
) else (
    echo 参数无效,文件或文件夹不存在。
    exit /b
)
 
rem 输出处理结果
echo 总计处理了 %count% 个 MP4 视频。
exit /b
 
:process_file
rem 处理单个文件
set "file=%~1"
set "ext=%~x1"
 
if /i not "%ext%"==".mp4" (
    echo 文件 %file% 不是 MP4 文件。
    exit /b
)
 
call :process_mp4 "%file%"
exit /b
 
:process_folder
rem 递归处理文件夹
set "folder=%~1"
 
for /r "%folder%" %%i in (*.mp4) do (
    call :process_mp4 "%%i"
)
 
exit /b
 
:process_mp4
rem 处理单个 MP4 文件
set "mp4_file=%~1"
echo 正在处理文件 %mp4_file%
 
rem 获取目标目录
set "base_dir=%~dp1"
set "file_name=%~n1"
set "target_dir=%base_dir%%file_name%"
 
rem 创建目标目录
if not exist "%target_dir%" (
    mkdir "%target_dir%"
)
 
rem 生成缩略图(需依赖 ffmpeg,确保 FFmpeg 在路径中)
rem ffmpeg -i "%mp4_file%" -vf scale=%new_width%:%new_height% -vframes 1 "%target_dir%\%file_name%.jpg"
ffmpeg -i "%mp4_file%" -vf "scale='if(gt(iw,ih),144,-1)':'if(gt(ih,iw),144,-1)'" "%target_dir%\frame_%%05d.jpg"
 
if %errorlevel% equ 0 (
    echo 文件 %mp4_file% 的缩略图已生成。
    set /a count+=1
) else (
    echo 生成文件 %mp4_file% 的缩略图失败。
)
 
exit /b