-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvideoCompressDir.cmd
More file actions
78 lines (63 loc) · 2.32 KB
/
Copy pathvideoCompressDir.cmd
File metadata and controls
78 lines (63 loc) · 2.32 KB
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
setlocal enabledelayedexpansion
echo ###################################################
echo # Description: Compress videos in a directory to MP4
echo # Usage: videoCompressDir.cmd /path/to/video.mp4 [custom args]
echo # videoCompressDir.cmd /path/to/videos/ [custom args]
echo # Param 1: Video file or directory
echo # Param 2+ [Optional]: Custom args for ffmpeg
echo # Requires: ffmpeg
echo ###################################################
echo.
@REM ################################################################################
@REM # check parameters & set defaults
@REM ################################################################################
set defaultArgs=-crf 23 -preset medium
@REM Check 1st arg
IF "%~1"=="" (
echo Error: 1st arg must be a video file or directory
exit /b 1
)
set inputPath=%1
@REM Get remaining args for ffmpeg
set ffmpegArgs=
if "%2"=="" (
@REM Check optional 2nd arg and provide default value
set ffmpegArgs=%defaultArgs%
echo ### Using default args: %defaultArgs%
) else (
@REM Use all arguments after the first one
set "allArgs=%*"
for /f "tokens=1,* delims= " %%a in ("!allArgs!") do set "ffmpegArgs=%%b"
echo ### Using user-defined args: !ffmpegArgs!
)
@REM ################################################################################
@REM Check if path is a directory or a file
@REM ################################################################################
if exist "%inputPath%\" (
@REM Process directory
echo.
echo Processing all video files in directory: %inputPath%
@REM Process all video files in the directory
for %%F in ("%inputPath%\*.mp4" "%inputPath%\*.mov" "%inputPath%\*.avi" "%inputPath%\*.mkv" "%inputPath%\*.wmv") do (
echo.
echo Processing: %%F
CALL :ProcessFile "%%F" "%ffmpegArgs%"
)
echo.
echo Finished compressing all videos in directory: %inputPath%
) else (
@REM Process single file
CALL :ProcessFile "%inputPath%" "%ffmpegArgs%"
)
exit /b 0
:ProcessFile
@REM Process a single video file
set "filename=%~1"
set "args=%~2"
set "outputFile=%~dpn1_compressed%~x1"
echo Compressing: %filename%
@REM Do conversion
ffmpeg -i "%filename%" -c:v libx264 -pix_fmt yuv420p %args% -c:a aac -b:a 192k "%outputFile%"
echo Success: Compressed to: %outputFile%
exit /b 0