-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubprocess.js
183 lines (159 loc) · 5.04 KB
/
subprocess.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
var ffmpegs = require('fluent-ffmpeg')
process.on('message', (m) => {
if (m === 'server') {
convert();
}
else if(m === 'segment'){
const args = process.argv.slice(2)
const stringPath = args[0]
console.log("here: ", stringPath);
convert_segment(stringPath);
}
else{
console.log("wrong messege");
}
});
function convert_segment(tsfile) {
// https://www.ffmpeg.org/ffmpeg-formats.html#hls-2
console.log("subprocess starting to convert segment")
ffmpegs(tsfile, { timeout: 432000 })
.videoFilters({
filter: 'drawtext',
options: {
text: 'This is AmirHossein Sorouries TXT. How u like me nowww.',
fontsize: 18,
fontcolor: 'red',
x: '(main_w/2-text_w/2)',
y: '(text_h/2)+15',
shadowcolor: 'black',
shadowx: 2,
shadowy: 2
}
})
.addOptions([
// '-c:a libmp3lame',
// '-ar 48000',
// '-ab 64k',
// '-c:v libx264',
// '-b:v 128k',
// '-flags',
// '-global_header',
// // '-map 0',
// '-f segment',
// // '-segment_list test_WWW.m3u8',
// '-segment_time 10',
// '-segment_format mpegts',
// '-segment_list_type m3u8',
'-profile:v baseline', // baseline profile (level 3.0) for H264 video codec
'-level 4.0',
'-start_number 0', // start the first .ts segment at index 0
'-hls_time 1', // 10 second segment duration
'-hls_list_size 0', // Maxmimum number of playlist entries (0 means all entries/infinite)
'-hls_playlist_type event',
// '-hls_segment_filename "files/fileSequence%d.ts"',
'-preset veryfast',
// '-flags',
// '-global_header',
'-f segment' , // HLS format
// '-hls_flags single_file'
// '-g 60'
])
.output(tsfile)
.on('end', function(stdout, stderr) {
console.log('ffmpeg done. !');
})
.on('error', function(stdout, stderr) {
console.log(stdout);
})
.run()
}
// Haminjooodi for test
function convert(ffmpeg) {
// https://www.ffmpeg.org/ffmpeg-formats.html#hls-2
// callback = callback
// function after() {
// callback(null, true);
// }
// var name = path.replace('.ts','').concat(["stream.ts"]) //"x".concat([req.filePath]) //
const fileDirs = '/home/amirsorouri00/Desktop/opt/nodejs/node-ffmpeg/files'; // Directory that input files are stored
console.log("subprocess starting to convert....")
ffmpegs('files/velelesh/stream0.m3u8', { timeout: 432000 })
.videoFilters({
filter: 'drawtext',
options: {
text: 'This is AmirHossein Sorouries TXT. How u like me nowww.',
fontsize: 18,
fontcolor: 'red',
x: '(main_w/2-text_w/2)',
y: '(text_h/2)+15',
shadowcolor: 'black',
shadowx: 2,
shadowy: 2
}
})
.addOptions([
'-profile:v baseline', // baseline profile (level 3.0) for H264 video codec
'-level 4.0',
'-start_number 0', // start the first .ts segment at index 0
'-hls_time 1', // 10 second segment duration
'-hls_list_size 0', // Maxmimum number of playlist entries (0 means all entries/infinite)
'-hls_playlist_type event',
// '-hls_segment_filename "files/fileSequence%d.ts"',
'-preset veryfast',
'-f hls' , // HLS format
'-hls_flags single_file'
// '-g 60'
])
.output('files/velelesh/stream.m3u8')
.on('end', function(stdout, stderr) {
console.log('ffmpeg done. !');
})
.on('error', function(stdout, stderr) {
console.log(stdout);
})
.run()
}
// Live Version
// function convert(ffmpeg) {
// // https://www.ffmpeg.org/ffmpeg-formats.html#hls-2
// // callback = callback
// // function after() {
// // callback(null, true);
// // }
// // var name = path.replace('.ts','').concat(["stream.ts"]) //"x".concat([req.filePath]) //
// const fileDirs = '/home/amirsorouri00/Desktop/opt/nodejs/node-ffmpeg/files'; // Directory that input files are stored
// console.log("subprocess starting to convert....")
// ffmpegs('gio.mp4', { timeout: 432000 })
// .videoFilters({
// filter: 'drawtext',
// options: {
// text: 'This is AmirHossein Sorouries TXT. How u like me nowww.',
// fontsize: 18,
// fontcolor: 'red',
// x: '(main_w/2-text_w/2)',
// y: '(text_h/2)+15',
// shadowcolor: 'black',
// shadowx: 2,
// shadowy: 2
// }
// })
// .addOptions([
// '-profile:v baseline', // baseline profile (level 3.0) for H264 video codec
// '-level 3.0',
// '-start_number 0', // start the first .ts segment at index 0
// '-hls_time 1', // 10 second segment duration
// '-hls_list_size 0', // Maxmimum number of playlist entries (0 means all entries/infinite)
// '-hls_playlist_type event',
// // '-hls_segment_filename "files/fileSequence%d.ts"',
// '-preset veryfast',
// '-f hls' // HLS format
// ])
// .output('files/stream.m3u8')
// .on('end', function(stdout, stderr) {
// console.log('ffmpeg done. !');
// })
// .on('error', function(stdout, stderr) {
// console.log(stdout);
// })
// .run()
// }