-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdigrab.cmd
159 lines (127 loc) · 3.1 KB
/
gdigrab.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
:: recipe: http://ss64.com/nt/syntax-getdate.html
:: found via http://stackoverflow.com/questions/1192476/format-date-and-time-in-a-windows-batch-script
@ECHO OFF
setlocal EnableExtensions EnableDelayedExpansion
:: parameters
set codec=qtrle
::set codec=libx264
set framerate=25
set keysecs=60
:: in seconds
set usewindowtitle=0
set windowtitle=
set usevideosize=0
set width=0
set height=0
set left=0
set top=0
:paramloop
if not "%1"=="" (
if "%1"=="-codec" (
set codec=%2
shift
)
if "%1"=="-framerate" (
set framerate=%2
shift
)
if "%1"=="-title" (
set windowtitle=%2
shift
set usewindowtitle=1
)
if "%1"=="-wh" (
set width=%2
set height=%3
shift
shift
set usevideosize=1
)
if "%1"=="-xy" (
set left=%2
set top=%3
shift
shift
)
shift
goto paramloop
)
:: build timestamp
:: default
set timestamp=_
:: Check WMIC is available
WMIC.EXE Alias /? >NUL 2>&1 || GOTO warn_wmi
:: Use WMIC to retrieve date and time
FOR /F "skip=1 tokens=1-6" %%G IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO (
IF "%%~L"=="" goto timeparts_done
Set _yyyy=%%L
Set _mm=00%%J
Set _dd=00%%G
Set _hour=00%%H
SET _minute=00%%I
SET _second=00%%K
)
echo what happens here?
exit /b -1
:timeparts_done
:: Pad digits with leading zeros
Set _mm=%_mm:~-2%
Set _dd=%_dd:~-2%
Set _hour=%_hour:~-2%
Set _minute=%_minute:~-2%
Set _second=%_second:~-2%
set /a "_yy=_yyyy-2000"
set timestamp=%_yy%%_mm%%_dd%-%_hour%%_minute%%_second%
goto timestamp_done
:warn_wmi
echo WMIC is not available to read current time
:timestamp_done
:main
:: file name
FOR /F "usebackq" %%i IN (`hostname`) DO SET HOSTNAME=%%i
set FILENAME=screencap-%timestamp%-%HOSTNAME%.mov
set sizeopt=
set sizereport=auto
if %usevideosize%==1 (
set sizeopt=-video_size %width%x%height%
set sizereport=%width% x %height%
)
set input=desktop
if %usewindowtitle%==1 (
set input=title=%windowtitle%
)
set /a "keyint=keysecs*framerate"
:: codec "qtrle" (default)
:setcodec
set encoptsset=0
set encopts=
if "%codec%"=="qtrle" (
set encopts=-c:v qtrle
set encoptsset=1
echo Encoder: Quicktime Animation (qtrle)
)
if "%codec%"=="x264" (
set encopts=-c:v libx264 -preset:v fast -tune:v stillimage -tune:v zerolatency -crf 0
set encoptsset=1
echo Encoder: H.264 (libx264)
)
if %encoptsset%==0 (
echo WARNING: unknown codec %codec% specified!
set codec=qtrle
goto setcodec
)
echo Frame rate: %framerate% fps
echo Image size: %sizereport%
echo Position: %left% x %top%
echo Input: %input%
echo Writing to %FILENAME%
echo CWD:
echo %cd%
if exist %FILENAME% (
echo ERROR: file already exists!
exit /b -1
)
echo.
:: -video_size 1920x1200
::ffmpeg -f gdigrab -r 10 -i desktop -pix_fmt yuv444p -c:v libx264 -preset:v baseline -preset:v ultrafast -tune:v stillimage -tune:v zerolatency -crf 0 %FILENAME%
ffmpeg -f gdigrab -framerate %framerate% %sizeopt% -offset_x %left% -offset_y %top% -i %input% %encopts% -g %keyint% %FILENAME%