-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaim_for_a_specific_file-size.cmd
74 lines (50 loc) · 2.01 KB
/
aim_for_a_specific_file-size.cmd
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
@echo off
chcp 65001 2>nul >nul
mkdir "%~sdp1fixed" 2>nul >nul
if ["%~1"] EQU [""] ( goto NOARG )
if not exist %~s1 ( goto NOARG )
::---------------------------cleanup
set "FILE_INPUT="
set "FILE_OUTPUT="
set "DURATION="
set "SIZE="
set "BITRATE="
::---------------------------
set "FILE_INPUT=%~s1"
::---------------------------get duration in seconds
for /f "tokens=*" %%a in ('call ffprobe -hide_banner -v "error" -i %FILE_INPUT% -select_streams "v:0" -show_entries "stream=duration" -print_format "default=noprint_wrappers=1:nokey=1" ') do (
set /a "DURATION=%%a * 1"
)
::---------------------------
::---------------------------get desired size from user-input
set /p "SIZE=Enter Desired Size (MB): " 1>&2
if ["%SIZE%"] EQU [""] ( goto END )
set /a "SIZE=%SIZE% * 1"
::to kBit
set /a "SIZE=%SIZE% * 8192"
::---------------------------
set /a "BITRATE=%SIZE% / %DURATION%"
echo duration: [%DURATION%] seconds 1>&2
echo size: [%SIZE%] kBit 1>&2
echo bitrate: [%BITRATE%] kBit/s 1>&2
::loose last-digit-precision, round up.
set /a "BITRATE=(%BITRATE% / 10) * 10"
set /a "BITRATE=%BITRATE% + 10"
echo bitrate (aim): [%BITRATE%] kBit/s 1>&2
set "FILE_OUTPUT=%~sdp1fixed\%~n1_%BITRATE%kbps.mp4"
echo. 1>&2
echo. 1>&2
echo input: %~1 1>&2
echo output: %FILE_OUTPUT% 1>&2
echo press any key to start encoding... 1>&2
pause >nul
echo. 1>&2
echo. 1>&2
ffmpeg -y -hide_banner -i "%FILE_INPUT%" -movflags "+faststart" -tune "zerolatency" -b:v "%BITRATE%k" -pass 1 -f mp4 nul
ffmpeg -y -hide_banner -i "%FILE_INPUT%" -movflags "+faststart" -tune "zerolatency" -b:v "%BITRATE%k" -pass 2 "%FILE_OUTPUT%"
goto END
:NOARG
echo ERROR: missing argument. 1>&2
goto END
:END
pause