-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.js
99 lines (86 loc) · 2.47 KB
/
main.js
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
const CDP = require('chrome-remote-interface')
const { promisify } = require('util')
const exec = promisify(require('child_process').exec)
const waitOn = require('wait-on')
var opts = {
resources: [
'tcp:localhost:9222'
],
interval: 100,
tcpTimeout: 100
}
// List of Chromium Command Line Switches
// https://peter.sh/experiments/chromium-command-line-switches/
function getStartChromeCommand () {
return 'DISPLAY=:1.0 /bin/sh -c ' +
'"/opt/google/chrome/google-chrome ' +
'--window-position=0,0 ' +
`--window-size=${+process.env.OUTPUT_VIDEO_WIDTH + 1},${+process.env.OUTPUT_VIDEO_HEIGHT + 1} ` +
'--remote-debugging-port=9222 ' +
'--no-first-run ' +
'--no-default-browser-check ' +
'--start-fullscreen ' +
'--kiosk ' +
'--disable-gpu ' +
'--no-sandbox ' +
'--disable-extensions ' +
'--autoplay-policy=no-user-gesture-required ' +
'--allow-running-insecure-content ' +
'--disable-features=TranslateUI"' +
'--disable-dev-shm-usage'
}
function getStartRecordingCommand () {
return 'ffmpeg -y ' +
'-f x11grab ' +
'-draw_mouse 0 ' +
`-s ${process.env.OUTPUT_VIDEO_WIDTH}x${process.env.OUTPUT_VIDEO_HEIGHT} ` +
'-thread_queue_size 4096 ' +
'-i :1 ' +
'-f alsa ' +
'-i default ' +
'-c:v libx264 ' +
'-tune zerolatency ' +
'-preset ultrafast ' +
'-v info ' +
'-bufsize 5952k ' +
'-acodec aac ' +
'-pix_fmt yuv420p ' +
'-r 30 ' +
'-crf 17 ' +
'-g 60 ' +
'-strict -2 ' +
'-ar 44100 ' +
`-t ${process.env.DURATION} ` +
`/recordings/${process.env.OUTPUT_FILENAME}`
}
async function fireChrome () {
exec(getStartChromeCommand())
await waitOn(opts)
const client = await CDP()
const { Network, Page } = client
Network.requestWillBeSent((params) => {
console.log(`Requested URL: ${params.request.url}`)
})
await Network.enable()
await Page.enable()
await Page.navigate({ url: process.env.URL })
await Page.loadEventFired()
console.log('All assets are loaded')
}
async function fireRecorder () {
console.log('Firing recorder')
await exec(getStartRecordingCommand())
console.log('Recording completed')
}
async function init () {
try {
await fireChrome()
await fireRecorder()
} catch (err) {
console.error(err)
process.exit(1)
} finally {
process.exit()
}
}
init()