-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.js
95 lines (77 loc) · 2.17 KB
/
video.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
var fs = require('fs');
//var ms = require('ms');
var net = require('net');
var path = require('path');
var arDrone = require('ar-drone');
var spawn = require('child_process').spawn;
var debug = require('debug')('drone-video');
var PaVEParser = require('./node_modules/ar-drone/lib/video/PaVEParser.js');
function record(client, options) {
var videoFolder = options.videoFolder;
var finalVideo = options.name;
try {
fs.accessSync(`${videoFolder}/video.h264`, fs.F_OK);
fs.unlink(`${videoFolder}/video.h264`);
fs.accessSync(`${videoFolder}/video.PaVE`, fs.F_OK);
fs.unlink(`${videoFolder}/video.PaVE`);
fs.accessSync(`${videoFolder}/${finalVideo}`, fs.F_OK);
fs.unlink(`${videoFolder}/${finalVideo}`);
} catch(err) {}
var videoStream = client.getVideoStream();
var parser = new PaVEParser();
videoStream.on('data', function(rawData) {
parser.write(rawData);
});
parser.on('data', function (frame) {
// set the "width" and "height"
width = frame.display_width;
height = frame.display_height;
// write to the h264 video file and the mp4 encoder
videoH264.write(frame.payload);
//ffplay.stdin.write(frame.payload);
videoEncoder.stdin.write(frame.payload);
});
var videoRaw = fs.createWriteStream(`${videoFolder}/video.PaVE`);
//socket.pipe(videoRaw);
/**
* Save the parsed h264 stream as "video.h264".
* See the `parser` "data" event.
*/
var videoH264File = `${videoFolder}/video.h264`;
var videoH264 = fs.createWriteStream(`${videoFolder}/video.h264`);
/**
* Spawn "ffplay" to play the h264 stream.
*/
/*
var ffplay = spawn('ffplay', [
'-f', 'h264',
'-analyzeduration', '0',
'-autoexit',
'-'
]
);
ffplay.on('exit', function (code, signal) {
if (0 == code) shutdown();
});
*/
/**
* Encode the "video.m4v" file.
* See the `parser` "data" event.
*
* See: https://gist.github.com/4403443
*/
var videoEncoderStderr = -1;
var videoEncoder = spawn('ffmpeg', [
'-f', 'h264',
'-analyzeduration', '0',
'-r', '29.97', // force 30fps?
'-i', '-',
'-an',
`${videoFolder}/${finalVideo}`
],
{ stdio: [ -1, -1, videoEncoderStderr ] }
);
}
module.exports = {
record: record
};