-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecord.phantom.js
executable file
·57 lines (48 loc) · 1.7 KB
/
record.phantom.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
// https://gist.github.com/phanan/e03f75082e6eb114a35c#file-runner-js
// Run this from the commandline:
// phantomjs runner.js | ffmpeg -y -c:v png -f image2pipe -r 24 -t 10 -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart output.mp4
const system = require('system')
// address#startHash#endHash#w#h
var params = system.args[1].split('#')
var address = params[0];
var startRecordHash = params[1];
var endRecordHash = params[2];
var width = parseInt(params[3]);
var height = parseInt(params[4]);
var page = require('webpage').create(),
// address = 'http://localhost:' + serverPort + '/' + pagePath,
// duration = 3, // duration of the video, in seconds
framerate = 24, // number of frames per second. 24 is a good value.
counter = 0;
page.viewportSize = { width: width, height: height };
var record = false;
var timeup = false;
window.setTimeout(function () {
timeup = true;
}, 10000);
// http://phantomjs.org/api/webpage/handler/on-url-changed.html
page.onUrlChanged = function(targetUrl) {
if (targetUrl.match('#' + startRecordHash) !== null) {
record = true;
} else if (record && targetUrl.match('#' + endRecordHash) !== null || timeup) {
record = false;
phantom.exit(0);
}
};
var cnt = 0
page.open(address, function(status) {
if (status !== 'success') {
console.error('Unable to load the address!');
phantom.exit(1);
} else {
window.setTimeout(function () {
page.clipRect = { top: 0, left: 0, width: width, height: height };
window.setInterval(function () {
if (record) {
page.render('/dev/stdout', { format: 'png' });
}
}, 1/framerate);
}, 200);
}
});
//*/