gpt4 book ai didi

express - 客户端收到所有 .ts 文件后自动删除 .ts 和 .m3u8 文件

转载 作者:行者123 更新时间:2023-12-04 22:48:06 30 4
gpt4 key购买 nike

所以我创建了一个快速服务器,它获取一个 mp3 文件(现在存储在本地,但稍后将从 mongo db 中获取)并使用 ffmpeg 制作 .m3u8 和 .ts 文件。文件成功发送到客户端,在客户端播放时没有错误。我用了hls.js在 Chrome 中播放这些文件。但是服务器仍然将这些文件存储在本地。服务器有什么方法可以知道何时删除它存储在本地的这些文件? ffmpeg 生成了很多文件,所以我不能让它们永远留在那里。
我使用了 hls-server github repo 中的 ffmpeg 部分代码.
我的服务器文件
index.js

// just used to run ffmpeg for conversion
var command = ffmpeg('inp.mp3')
.on('start', function (commandLine) {
console.log('command', commandLine);
}).addOptions([
'-c:a aac',
'-b:a 64k',
'-vn',
'-hls_list_size 0',
'-segment_time 10',
]).output('files\\output.m3u8');

var express = require('express');
var app = express();
// express middleware to serve individual .ts and .m3u8 files when requested
app.use(express.static('./files/'));

app.get('/', function (req, res) {
command.on('end', function () {
console.log('done');
res.write(`
<script src="https://cdn.jsdelivr.net/hls.js/latest/hls.min.js"></script>
<script>
function onLevelLoaded (event, data) {
var level_duration = data.details.totalduration;
console.log(level_duration, data);
}
if(Hls.isSupported()) {
var audio = new Audio();
var hls = new Hls();
// requesting files from here
hls.loadSource('http://localhost:8000/output.m3u8');
hls.attachMedia(audio);
hls.on(Hls.Events.LEVEL_LOADED, onLevelLoaded);
hls.on(Hls.Events.FRAG_BUFFERED, (e, d) => {
console.log(e, d);
});
}
</script>
`);
res.end();
}).run();
});

app.listen(8000);

最佳答案

您可以使用 hls_delete_threshold

"-hls_time 10",
"-hls_list_size 3",
"-hls_delete_threshold 3",
"-hls_flags delete_segments"

hls_delete_threshold size

Set the number of unreferenced segments to keep on disk before hls_flags delete_segments deletes them. Increase this to allow continue clients to download segments which were recently referenced in the playlist. Default value is 1, meaning segments older than hls_list_size+1 will be deleted.

关于express - 客户端收到所有 .ts 文件后自动删除 .ts 和 .m3u8 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53638341/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com