-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecordsrc-gui.tcl
executable file
·145 lines (111 loc) · 4.2 KB
/
recordsrc-gui.tcl
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
#!/usr/bin/env wish
#TODO Small Gui, one button, 24x24
#TODO Set name of file and date format.
#TODO Documentation
#TODO Set values from GUI
package require Tk
package require platform
proc idPlatform { } {
switch -glob -- [platform::identify] {
macosx* {
set dictData [dict create platform 0 format "avfoundation" idevice "1"]
}
default { set dictData [dict create platform 1 format "x11grab" idevice ":0.0"]}
}
return $dictData
}
# We only take one argument, if is a folder and writable
# return folder path
proc parseArgs {} {
set home [file normalize ~]
foreach argument $::argv {
if { [file isdirectory $argument] && [file writable $argument]} {
return [file normalize $argument]
}
}
return $home
}
# Select folder to save recordings
proc chooseFolder { args } {
set file [tk_chooseDirectory -initialdir $::tclRecord(record_dir) -title "Choose a directory"]
# If user press Cancel check if not empty
if { [file isdirectory $file] } {
set ::tclRecord(record_dir) $file
}
return 0
}
# With all values arrange them into a nice commandline
proc buildCommands { } {
set ::tclRecord(cmd_real) [list ffmpeg -f [dict get $::tclRecord(platform_special) format] -s 1680x1050 -r 15 -i [dict get $::tclRecord(platform_special) idevice] \
-c:v libx264 -preset ultrafast -pix_fmt yuv420p -vf scale=1280:-1 \
-an [getName scr_real_] &]
set ::tclRecord(cmd_timelapse) [list ffmpeg -f [dict get $::tclRecord(platform_special) format] -s 1680x1050 -r 16 -i [dict get $::tclRecord(platform_special) idevice] \
-c:v libx264 -preset ultrafast -pix_fmt yuv420p -vf "scale=1280:-1,setpts=0.25*PTS,framerate=30" \
-an [getName scr_tmlps_] &]
# OLD using yuvfps
# set ::tclRecord(cmd_timelapse) [list ffmpeg -f dict get $::tclRecord(platform_special) format] -s 1680x1050 -r 8 -i :0.0 \
# -f yuv4mpegpipe -pix_fmt yuv420p - | yuvfps -s 30:1 -r 30:1 \
# - | ffmpeg -f yuv4mpegpipe -i - -c:v libx264 -preset ultrafast -pix_fmt yuv420p \
# -vf scale=1280:-1 -an [getName scr_tmlps_] &]
}
proc getName { name } {
cd $::tclRecord(record_dir)
append outName $name $::tclRecord(date)
set tmpname $outName
set s 0
while {[file exists ${outName}.mp4]} {
set outName $tmpname
incr s
set outName [join [list $outName "_$s"] {} ]
}
append outName ".mp4"
return [file join $::tclRecord(record_dir) $outName]
}
proc startCmd { mode } {
buildCommands
catch { set ::tclRecord(cmd_id) [exec {*}$::tclRecord($mode) ]}
puts "=============== $::tclRecord(cmd_id)"
pack forget $::tclRecord(g_ops) $::tclRecord(g_actions).sttime $::tclRecord(g_actions).streal
pack $::tclRecord(g_actions) $::tclRecord(g_actions).stop -expand 1 -fill both -side top
lower .
}
proc stopCmd {} {
catch {exec kill {*}$::tclRecord(cmd_id)}
exit
}
proc startGui {} {
set ::tclRecord(g_main) .main
ttk::frame $::tclRecord(g_main) -borderwidth 5
pack $::tclRecord(g_main)
set ::tclRecord(g_actions) [makeActions $::tclRecord(g_main)]
set ::tclRecord(g_ops) [makeOptions $::tclRecord(g_main)]
# Do not show .dot files by default. (this does not work for OSX)
catch { tk_getOpenFile foo bar }
if {[dict get $::tclRecord(platform_special) platform]} {
set ::tk::dialog::file::showHiddenVar 0
set ::tk::dialog::file::showHiddenBtn 1
}
}
proc makeActions { w {child ".a"} } {
append w $child
ttk::frame $w
ttk::button $w.streal -text "Realtime" -command { startCmd "cmd_real" }
ttk::button $w.sttime -text "Timelapse" -command { startCmd "cmd_timelapse" }
ttk::button $w.stop -text "Stop" -command { stopCmd }
pack $w
pack $w.streal $w.sttime -side left
return $w
}
proc makeOptions { w {child ".o"} } {
append w $child
ttk::frame $w
ttk::button $w.cho_folder -text "Record Dir" -command { chooseFolder }
pack $w -fill both -expand 1
pack $w.cho_folder -side top -fill x
return $w
}
wm title . "Record ffmpeg"
set ::tclRecord(platform_special) [idPlatform]
set ::tclRecord(record_dir) [ parseArgs ]
set ::tclRecord(date) [clock format [clock seconds] -format %m%d]
startGui