-
Notifications
You must be signed in to change notification settings - Fork 7
/
transport-stream-segmenter-cli.js
executable file
·69 lines (53 loc) · 1.79 KB
/
transport-stream-segmenter-cli.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
#!/usr/bin/env node
//Jordi Cenzano 2017
const fs = require('fs');
const path = require('path');
const chkGenerator = require('./src/chunklistGenerator.js');
"use strict";
// Check input arguments
if (process.argv.length < 4) {
console.log("Use: ./transport-stream-segmenter-cli.js INPUT_TS OUTPUT_CHUNKLIST [TARGET_DUR_S] [GENERATE_FILES]");
console.log("Example: ./transport-stream-segmenter-cli.js /tmp/input.ts /tmp/out.m3u8 4 1");
process.exit(1);
}
//Get conf filename
const input_ts_file = process.argv[2];
const out_chunklist_file = process.argv[3];
let target_dur_s = 4; //Default
if (process.argv.length > 4)
target_dur_s = Number.parseInt(process.argv[4], 10);
let is_generating_files = false; //Default
let chunk_base_filename = input_ts_file;
if ((process.argv.length > 5) && (Number.parseInt(process.argv[5], 10) > 0)) {
is_generating_files = true;
chunk_base_filename = 'chunk';
}
const base_path = path.dirname(out_chunklist_file);
//Instantiate class
let segmenter = new chkGenerator.chunklistGenerator(is_generating_files, base_path, chunk_base_filename, target_dur_s);
//Create file reader
const readStream = fs.createReadStream(input_ts_file);
readStream.on('data', function (chunk) {
segmenter.processDataChunk(chunk, function (err) {
if (err) {
readStream.destroy();
console.error(err);
return 1;
}
});
});
readStream.on('end', function () {
segmenter.processDataEnd(function (err, chunklist) {
if (err) {
console.error(err);
return 1;
}
fs.writeFileSync(out_chunklist_file, chunklist);
console.log("Finished! Created: " + out_chunklist_file);
return 0;
});
});
readStream.on('error', function (err) {
console.error(err);
return 1;
});