Skip to content

Commit f1977fc

Browse files
committed
wip
1 parent 0f662f4 commit f1977fc

30 files changed

Lines changed: 4212 additions & 1763 deletions

cat.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"babel": "inherit"
3333
},
34-
"preferGlobal": "true",
34+
"preferGlobal": true,
3535
"repository": {
3636
"type": "git",
3737
"url": "git+https://github.com/ewnd9/record-desktop.git"
@@ -49,55 +49,54 @@
4949
"author": "ewnd9 <ewndnine@gmail.com>",
5050
"license": "MIT",
5151
"dependencies": {
52-
"configstore": "^1.4.0",
53-
"electron": "^1.6.11",
54-
"electron-contextmenu-middleware": "^1.0.1",
52+
"configstore": "^3.1.2",
53+
"electron": "^1.8.4",
54+
"electron-contextmenu-middleware": "^1.0.3",
5555
"electron-image-menu": "^2.0.0",
5656
"electron-input-menu": "^2.1.0",
57-
"electron-localshortcut": "^1.1.1",
57+
"electron-localshortcut": "^3.1.0",
5858
"electron-save-file": "^1.0.2",
59-
"globby": "^4.0.0",
60-
"imgur": "^0.1.7",
61-
"lodash": "^4.5.0",
59+
"globby": "^8.0.1",
60+
"imgur": "^0.2.1",
61+
"lodash": "^4.17.5",
6262
"mkdirp": "^0.5.1",
63-
"node-notifier": "^4.5.0",
64-
"pify": "^2.3.0",
65-
"pretty-bytes": "^3.0.1",
66-
"whereis": "^0.4.0",
67-
"winston": "^2.1.1"
63+
"node-notifier": "^5.2.1",
64+
"pify": "^3.0.0",
65+
"pretty-bytes": "^4.0.2",
66+
"whereis": "^1.0.0",
67+
"winston": "^2.4.1"
6868
},
6969
"devDependencies": {
70-
"ava": "^0.20.0",
71-
"babel-cli": "^6.4.0",
72-
"babel-core": "^6.4.0",
73-
"babel-eslint": "^5.0.0",
74-
"babel-loader": "^6.2.1",
75-
"babel-plugin-lodash": "^1.1.0",
76-
"babel-preset-es2015": "^6.3.13",
77-
"babel-preset-react": "^6.3.13",
78-
"babel-preset-stage-0": "^6.3.13",
79-
"bootstrap": "^3.3.6",
80-
"css-loader": "^0.23.1",
81-
"electron-installer-debian": "0.4.0",
82-
"electron-packager": "8.5.1",
83-
"eslint": "^1.10.3",
84-
"eslint-plugin-react": "^3.16.1",
85-
"file-loader": "^0.8.5",
86-
"husky": "^0.13.1",
87-
"json-loader": "^0.5.4",
88-
"nodemon": "^1.8.1",
89-
"npm-run-all": "^1.4.0",
90-
"proxyquire": "^1.7.11",
91-
"react": "^0.14.6",
92-
"react-component-gallery": "^1.2.1",
93-
"react-dom": "^0.14.6",
94-
"react-router": "^2.0.0",
95-
"style-loader": "^0.13.0",
96-
"url-loader": "^0.5.7",
97-
"webpack": "^1.12.11",
98-
"webpack-dev-server": "^1.14.1",
99-
"webpack-target-electron-renderer": "^0.4.0",
100-
"x11": "^2.0.5"
70+
"ava": "^0.25.0",
71+
"babel-cli": "^6.26.0",
72+
"babel-core": "^6.26.0",
73+
"babel-eslint": "^8.2.2",
74+
"babel-loader": "^7.1.4",
75+
"babel-plugin-lodash": "^3.3.2",
76+
"babel-preset-es2015": "^6.24.1",
77+
"babel-preset-react": "^6.24.1",
78+
"babel-preset-stage-0": "^6.24.1",
79+
"bootstrap": "3.x",
80+
"css-loader": "^0.28.11",
81+
"electron-installer-debian": "0.8.1",
82+
"electron-packager": "12.0.1",
83+
"eslint": "^4.19.1",
84+
"eslint-plugin-react": "^7.7.0",
85+
"file-loader": "^1.1.11",
86+
"husky": "^0.14.3",
87+
"json-loader": "^0.5.7",
88+
"nodemon": "^1.17.3",
89+
"npm-run-all": "^4.1.2",
90+
"proxyquire": "^2.0.1",
91+
"react": "^16.3.1",
92+
"react-dom": "^16.3.1",
93+
"react-router": "3.x",
94+
"style-loader": "^0.20.3",
95+
"uglifyjs-webpack-plugin": "^1.2.4",
96+
"url-loader": "^1.0.1",
97+
"webpack": "^3.11.0",
98+
"webpack-dev-server": "^2.11.1",
99+
"x11": "^2.3.0"
101100
},
102101
"resolutions": {
103102
"electron/**/sumchecker": "2.0.2"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const { ffmpeg } = require('../src/unix-utils/ffmpeg');
4+
5+
const outputFile = '/tmp/1.mkv';
6+
const { promise, finish } = ffmpeg({ outputFile, width: 200, height: 200, x: 0, y: 0 });
7+
8+
promise
9+
.catch(err => console.log(err.stack || err));
10+
11+
setTimeout(() => {
12+
finish();
13+
console.log(outputFile);
14+
}, 5000)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const delay = require('delay');
5+
const execa = require('execa');
6+
const globby = require('globby');
7+
const prettyBytes = require('pretty-bytes');
8+
9+
const { ffmpeg } = require('../src/unix-utils/ffmpeg');
10+
const { xdotool } = require('../src/unix-utils/xdotool');
11+
const { xwininfo } = require('../src/unix-utils/xwininfo');
12+
const { openTag } = require('../src/unix-utils/wmctrl');
13+
const { xdgOpen } = require('../src/unix-utils/xdg-open');
14+
15+
const devConsole = console;
16+
17+
main()
18+
.catch(err => {
19+
devConsole.error(err);
20+
process.exit(1);
21+
});
22+
23+
async function main() {
24+
const sentence = 'very tired but very cool';
25+
const typeDelay = 200;
26+
const outputFile = '/tmp/1.mkv';
27+
28+
await delay(100);
29+
await openTag(3);
30+
31+
await xdotool(['key', 'super+e']);
32+
await delay(100);
33+
34+
const { x, y, width, height } = await xwininfo();
35+
36+
const imgProc = execa('pqiv', ['-c', '-c', '-i', '/home/ewnd9/github/gtk-node/record-desktop/snoop.gif']);
37+
await delay(400);
38+
39+
const { stdout } = await execa('xdotool', ['search', '--pid', imgProc.pid]);
40+
const imgWindowId = stdout.split('\n')[1];
41+
console.log(stdout, imgWindowId);
42+
43+
for (let i = 0 ; i < 5 ; i++) {
44+
await execa('wmctrl', ['-i', '-r', imgWindowId, '-e', `0,${x + i * 50},${y + i * 10},250,250`]);
45+
await delay(200);
46+
}
47+
48+
49+
50+
// const { promise, finish } = ffmpeg({ outputFile, x, y, width, height, offset: 50 });
51+
52+
// await delay(100);
53+
// await xdotool(['type', '--delay', typeDelay, sentence]);
54+
// await delay(100);
55+
56+
// finish();
57+
// await promise;
58+
59+
// const dir = `/tmp/${new Date().toISOString()}`;
60+
// const outputGif = `${dir}/anim.gif`;
61+
62+
// await execa('mkdir', [dir]);
63+
// await execa('ffmpeg', ['-i', outputFile, `${dir}/frame%04d.png`]);
64+
// const frameFiles = await globby(['*.png'], { absolute: true, cwd: dir });
65+
// const args = ['-o', outputGif].concat(frameFiles);
66+
// await execa('gifski', args);
67+
68+
69+
// const stat = fs.statSync(outputGif);
70+
// console.log(outputGif, prettyBytes(stat.size));
71+
72+
// xdgOpen(outputGif);
73+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { byzanzRecord } from './unix-utils/byzanz-record';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import execa from 'execa';
2+
import { exec, execFile } from 'child_process';
3+
4+
export function byzanzRecord({ outputFile, width, height, x, y }) {
5+
const coords = typeof width === 'undefined' ? [] : [
6+
`--x=${x}`,
7+
`--y=${y}`,
8+
`--width=${width}`,
9+
`--height=${height}`
10+
];
11+
12+
const args = coords.concat(outputFile);
13+
14+
// can't use execFile because otherwise byzanz's subprocess is killed prematurelly
15+
const proc = exec(`byzanz-record ${args.join(' ')}`);
16+
// const proc = execFile('byzanz-record', args);
17+
18+
const finish = () => {
19+
console.log(proc.pid);
20+
proc.kill('SIGINT');
21+
console.log('after kill')
22+
};
23+
24+
return {
25+
proc,
26+
finish
27+
};
28+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
inspiration: https://github.com/wulkano/aperture
3+
https://github.com/wulkano/aperture/pull/5/files
4+
https://github.com/wulkano/aperture/pull/32
5+
*/
6+
import execa from 'execa';
7+
8+
export function ffmpeg({ outputFile, fps = 30, x, y, width, height, offset = 0, showCursor }) {
9+
const args = ['-f', 'x11grab'];
10+
11+
if (typeof width !== 'undefined') {
12+
if (offset > 0) {
13+
console.log(x, y, width, height);
14+
console.log(offset);
15+
x = x - offset;
16+
y = y - offset;
17+
width = width + offset * 2;
18+
height = height + offset * 2;
19+
console.log(x, y, width, height);
20+
}
21+
22+
args.push('-video_size', `${width}x${height}`);
23+
args.push('-i', `:0+${x},${y}`)
24+
} else {
25+
args.push('-i', ':0');
26+
}
27+
28+
args.push('-y') // force overwrite existing file
29+
args.push('-framerate', fps, '-draw_mouse', +(showCursor === true), outputFile);
30+
31+
const proc = execa('ffmpeg', args);
32+
33+
// proc.stderr.setEncoding('utf8');
34+
// proc.stderr.on('data', str => {
35+
// console.log(str)
36+
// })
37+
38+
const finish = () => new Promise(resolve => {
39+
proc.stdin.setEncoding('utf8');
40+
proc.stdin.write('q');
41+
})
42+
43+
return {
44+
proc,
45+
finish
46+
};
47+
}

packages/record-desktop/src/unix-utils/gifski.js

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { exec } from '../utils';
2+
import { log } from '../../logger';
3+
4+
export function slop() {
5+
return exec('slop -f "%g"').then(res => {
6+
log(`slop: ${res}`);
7+
8+
if (/^\d+x\d+\+\d+\+\d+/.test(res)) {
9+
const [dim, x, y] = res.split('+');
10+
const [width, height] = dim.split('x');
11+
12+
return { width, height, x, y };
13+
} else {
14+
const [x, y, width, height] = res.split('\n').map(_ => _.split('=')[1]);
15+
return { width, height, x, y };
16+
}
17+
});
18+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import test from 'ava';
2+
import proxyquire from 'proxyquire';
3+
4+
test('slop old format', async t => {
5+
t.deepEqual(await getSlop('X=525\nY=705\nW=296\nH=168'), {
6+
height: '168',
7+
width: '296',
8+
x: '525',
9+
y: '705'
10+
});
11+
});
12+
13+
test('slop new format', async t => {
14+
t.deepEqual(await getSlop('323x162+1316+247'), {
15+
height: '162',
16+
width: '323',
17+
x: '1316',
18+
y: '247'
19+
});
20+
});
21+
22+
function getSlop(mock) {
23+
const { slop } = proxyquire.noCallThru().load('./slop', {
24+
'../utils': {
25+
exec: () => Promise.resolve(mock)
26+
},
27+
'../../utils': {
28+
log: () => {}
29+
}
30+
});
31+
32+
return slop();
33+
}

0 commit comments

Comments
 (0)