forked from Czechball/discord-video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord-video.bat
51 lines (35 loc) · 1.25 KB
/
discord-video.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
@echo off
set /A MAX_VIDEO_SIZE=60000000
set /A MAX_AUDIO_SIZE=4000000
if "%~1" == "" goto nofile
rem Check if file is video, get duration if it is
for /f "delims=" %%i in ('@ffprobe ^-hide^_banner "%~1" ^-show^_entries format^=duration -v quiet -of csv^=^"p^=0^"') do (
SET var=%%i
)
if [%var%]==[] goto invalidfile
echo "%~1" is a video file and is %var% seconds long
rem Calculate bitrate
for /f "tokens=1,2 delims=." %%a in ("%var%") do (
set first_part=%%a
set second_part=%%b
)
set /a rounded=%first_part%
set /A VIDEO_BITRATE=%MAX_VIDEO_SIZE% / %rounded%
set /A AUDIO_BITRATE=%MAX_AUDIO_SIZE% / %rounded%
set /A SHOULD_BITRATE=%VIDEO_BITRATE% + %AUDIO_BITRATE%
echo video should have a bitrate of %SHOULD_BITRATE% kbps
ffmpeg -hide_banner -i "%~1" -c:v libvpx-vp9 -row-mt 1 -b:v "%VIDEO_BITRATE%" -pix_fmt yuv420p -vf scale=1280:720 -pass 1 -an -f null NUL && ffmpeg -hide_banner -i "%~1" -c:v libvpx-vp9 -cpu-used 3 -row-mt 1 -b:v "%VIDEO_BITRATE%" -pix_fmt yuv420p -vf scale=1280:720 -c:a libopus -b:a "%AUDIO_BITRATE%" -pass 2 "%~1-compressed.mp4"
goto end
:nofile
echo Error: No video file selected
echo Usage: %0 ^<video-file^>
pause
exit /B 1
:invalidfile
echo Error: "%~1" is not a video file
pause
exit /B 1
:end
echo "Done."
pause
exit /B 0