从特定位置开始HLS记录/从hls.js获取当前片段数据

问题描述 投票:0回答:1

我正在使用hls.js项目查看hls内容我需要实现“录制”功能-一旦用户单击“开始记录”按钮,所有从该位置开始的片段都将被汇总到一个临时缓冲区中,一旦用户单击“停止记录”,这些片段将与前置的init片段一起保存到mp4文件中。

到目前为止,我已经能够监听BUFFER_APPENDING事件并将新的段推入临时数组中>]

hls.on(Hls.Events.BUFFER_APPENDING,  (event, data) => {
        if (this.state.recording) {
            this.dataStream[data.type].push(data.data);
            console.log("recording " + data.type + " data, " + data.data.length + " bytes  ...")
        }
    });

但是这些是要添加到高速缓存缓冲区中的较新的段,并且实际记录的数据从实际的“开始记录”时间开始向前偏移了30s-60s。]

我检查了FRAG_CHANGED事件,看来这是当前播放的片段-hls.js events

hls.on(Hls.Events.FRAG_CHANGED, (event, data) => {
        console.log("HLS Player Frag Changed")
        console.log("Data = " + inspect(data))
    })

我该如何实际获取当前播放的视频片段数组以对其进行聚合,然后将其用于构建mp4文件?

我正在使用hls.js项目查看hls内容,我需要实现“录制”功能-用户单击“开始录制”按钮后,从该位置开始的所有片段都会汇总到...

]] >
this.dataStream = [];
this.fragments = []
...
hls.on(Hls.Events.FRAG_CHANGED, (event, data) => {
           console.log("HLS Player Frag Changed")
           //console.log("Data = " + inspect(data))
           if (this.state.recording) {
               let recdata = this.fragments[data.frag.sn]
               let dataToRecord = [...recdata.data1,...recdata.data2]
               this.dataStream.push(dataToRecord);
               console.log("recording video data sn(" + data.frag.sn+ ") " + dataToRecord.length + " bytes  ...")
           }
       })
hls.on(Hls.Events.FRAG_PARSING_DATA, (event, data) => {
            console.log("HLS Player Frag Parsing Data")
            //console.log("Data = " + inspect(data))
            this.fragments[data.frag.sn]=data
            console.log("saved sn(" + data.frag.sn + ") - fragment")
        })

但是可能存在内存问题,因为我存储了FRAG_PARSING_DATA事件中收到的所有片段

mp4 http-live-streaming hls.js
1个回答
0
投票
this.dataStream = [];
this.fragments = []
...
hls.on(Hls.Events.FRAG_CHANGED, (event, data) => {
           console.log("HLS Player Frag Changed")
           //console.log("Data = " + inspect(data))
           if (this.state.recording) {
               let recdata = this.fragments[data.frag.sn]
               let dataToRecord = [...recdata.data1,...recdata.data2]
               this.dataStream.push(dataToRecord);
               console.log("recording video data sn(" + data.frag.sn+ ") " + dataToRecord.length + " bytes  ...")
           }
       })
hls.on(Hls.Events.FRAG_PARSING_DATA, (event, data) => {
            console.log("HLS Player Frag Parsing Data")
            //console.log("Data = " + inspect(data))
            this.fragments[data.frag.sn]=data
            console.log("saved sn(" + data.frag.sn + ") - fragment")
        })
© www.soinside.com 2019 - 2024. All rights reserved.