Skip to content

Commit 445ad52

Browse files
e965datagutt
authored andcommitted
Creating empty index.m3u8 after transmuxing end
1 parent 23b2fa6 commit 445ad52

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

app.js

-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,3 @@ nms.on('postPlay', (id, StreamPath, args) => {
7474
nms.on('donePlay', (id, StreamPath, args) => {
7575
console.log('[NodeEvent on donePlay]', `id=${id} StreamPath=${StreamPath} args=${JSON.stringify(args)}`);
7676
});
77-

node_trans_session.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class NodeTransSession extends EventEmitter {
4646
}
4747
if (this.conf.hls) {
4848
this.conf.hlsFlags = this.conf.hlsFlags ? this.conf.hlsFlags : '';
49-
let hlsFileName = this.conf.name ? `${this.conf.name}.m3u8` : 'index.m3u8';
50-
let mapHls = `[${this.conf.hlsFlags}:hls_segment_filename=\'${ouPath}/guaclive_${this.conf.name || 'index'}_${random}_%d.ts\']${ouPath}/${hlsFileName}|`;
49+
this.hlsFileName = this.conf.name ? `${this.conf.name}.m3u8` : 'index.m3u8';
50+
let mapHls = `[${this.conf.hlsFlags}:hls_segment_filename=\'${ouPath}/guaclive_${this.conf.name || 'index'}_${random}_%d.ts\']${ouPath}/${this.hlsFileName}|`;
5151
mapStr += mapHls;
52-
Logger.log('[Transmuxing HLS] ' + this.conf.streamPath + ' to ' + ouPath + '/' + hlsFileName);
52+
Logger.log('[Transmuxing HLS] ' + this.conf.streamPath + ' to ' + ouPath + '/' + this.hlsFileName);
5353
}
5454
if (this.conf.dash) {
5555
this.conf.dashFlags = this.conf.dashFlags ? this.conf.dashFlags : '';
@@ -89,7 +89,7 @@ class NodeTransSession extends EventEmitter {
8989
this.ffmpeg_exec.on('close', (code) => {
9090
Logger.log('[Transmuxing end] ' + this.conf.streamPath);
9191
this.emit('end');
92-
fs.readdir(ouPath, function (err, files) {
92+
fs.readdirSync(ouPath, function (err, files) {
9393
if (!err) {
9494
files.forEach((filename) => {
9595
if (filename.endsWith('.ts')
@@ -101,9 +101,12 @@ class NodeTransSession extends EventEmitter {
101101
|| filename.endsWith('.tmp')) {
102102
fs.unlinkSync(ouPath + '/' + filename);
103103
}
104-
})
104+
});
105105
}
106-
});
106+
});
107+
if (this.conf.hls) {
108+
fs.writeFileSync(ouPath + '/' + this.hlsFileName, '#EXTM3U\n');
109+
}
107110
});
108111
}
109112

@@ -112,4 +115,4 @@ class NodeTransSession extends EventEmitter {
112115
}
113116
}
114117

115-
module.exports = NodeTransSession;
118+
module.exports = NodeTransSession;

0 commit comments

Comments
 (0)