-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathonly-one-video-compressor.bat
70 lines (56 loc) · 1.98 KB
/
only-one-video-compressor.bat
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
@echo off
setlocal enabledelayedexpansion
echo.
echo ##################################################################
echo ## ##
echo ## FFMPEG VIDEO COMPRESSOR ##
echo ## ##
echo ##################################################################
echo.
set "SCRIPT_DIR=%~dp0"
set "FFMPEG_BIN=%SCRIPT_DIR%ffmpeg.exe"
if not exist "%FFMPEG_BIN%" (
echo The FFmpeg command line tool is missing. Please download it and copy it to the same folder of this script, then try again.
pause
exit /b
)
REM Checks if there is already an instance of ffmpeg.exe running.
set "programToCheck=ffmpeg.exe"
for /f "tokens=*" %%a in ('tasklist ^| find /i "%programToCheck%"') do (
set "task=%%a"
)
if not "!task!"=="" (
ECHO An FFmpeg instance is already running. Exiting...
pause
exit /b
)
if not "%~1"=="" (
set "source_file=%~1"
) else (
REM Prompt the user for the source folder
set /p source_file=Full pathname for video file to compress:
)
REM Check if the source directory exists
if not exist "%source_file%" (
echo Source video file does not exist.
pause
exit /b
)
for %%F in ("%source_file%") do (
set "dirPath=%%~dpF"
set "fileName=%%~nF"
set "fileExt=%%~xF"
)
set "dest_file=%dirPath%%fileName%_mod.mp4"
REM Parameters that you can change to fit your needs - BEGIN
set "CPU_USED=12"
set "VIDEO_CONSTANT_RATE_FACTOR=26"
set "AUDIO_BITRATE=32k"
set "AUDIO_SAMPLING_RATE=32000"
set "AUDIO_CHANNELS=1"
REM Parameters that you can change to fit your needs - END
REM Run the ffmpeg command for each file
echo Compressing "%source_file%" ...
%FFMPEG_BIN% -n -hide_banner -loglevel error -stats -i "%source_file%" -cpu-used %CPU_USED% -c:v libx264 -preset fast -crf %VIDEO_CONSTANT_RATE_FACTOR% -c:a aac -b:a %AUDIO_BITRATE% -ar %AUDIO_SAMPLING_RATE% -ac %AUDIO_CHANNELS% "%dest_file%"
pause
endlocal