You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I'm having problems playing video files from a readable stream. I did a simple test using the Fetch API and it works fine, but in my case I'm dealing with large encrypted files that are decrypted on the fly using rcloneInstance.File.createReadStream(fetchStreamFactory(vid_URL)) from rclone-js , which returns a readable stream. I think the issue might be how I'm handling the appending of the arrayBuffer. Looking at the logs I can see that the file info is successfully extracted and the MIMECodec is also correctly identified, but the video does not play.
My code:
asyncfunctionplayFile(vid_URL){constmp4boxfile=MP4Box.createFile();constmediaSource=newMediaSource();letmimeCodec;letsourceBuffer;mp4boxfile.onReady=function(info){console.log(info)letvidepCoded=info.videoTracks[0].codeclettrackCodec=info.audioTracks[0].codecmimeCodec=`video/mp4; codecs="${trackCodec} , ${videpCoded}"`constvideoTracks=info.tracks.filter(track=>track.type==="video");console.log('Video tracks filtered',{ videoTracks });vartrackIndex=0if(videoTracks[trackIndex]){consttrack=videoTracks[trackIndex];// start segmentationconsole.log('Segment options set',{trackId: track.id,nbSamples: 1000});constoptions={nbSamples: 1000}mp4boxfile.setSegmentOptions(track.id,options)constinitSegs=mp4boxfile.initializeSegmentation()sourceBuffer=mediaSource.addSourceBuffer(mimeCodec);sourceBuffer.addEventListener("updateend",onInitAppended);initSegs.forEach((initSeg)=>{console.log('Appended initialization segment',{ initSeg },initSeg);sourceBuffer.appendBuffer(initSeg.buffer);});mp4boxfile.start();};}mp4boxfile.onSegment=function(id,user,buffer){console.log("Received segment on track "+id+" for object "+user+" with a length of "+buffer.byteLength);console.log('Received segment',{trackId: id,bufferByteLength: buffer.byteLength});if(sourceBuffer){if(!sourceBuffer.updating){sourceBuffer.appendBuffer(buffer);console.log('Appended media segment to SourceBuffer',{ buffer });}}};functiononSourceClose(e){console.log("MediaSource closed!","MSE closed");}functiononInitAppended(e){console.log('updateend event after appending init segment',{ sourceBuffer });console.log(mediaSource.readyState,"open","MSE opened after init append")}asyncfunctiononSourceOpen(e){constopts={start: 0,end: undefined,chunkSize: 1024*1024*4,}// returns a readable streamconstdecryptedStream=awaitrcloneInstance.File.createReadStream(fetchStreamFactory(vid_URL),opts)constCHUNK_SIZE_THRESHOLD=1024*1024*10;letoffset=0;letaccumulatedBuffers=[];// process chunksforawait(constchunkofdecryptedStream){constarrayBuffer=chunk;accumulatedBuffers.push(arrayBuffer);// Check if accumulated buffers size exceeds the thresholdconstaccumulatedSize=accumulatedBuffers.reduce((acc,buf)=>acc+buf.byteLength,0);if(accumulatedSize>=CHUNK_SIZE_THRESHOLD){// Concatenate accumulated buffersconstconcatenatedBuffer=concatenateArrayBuffers(accumulatedBuffers);console.log("concatenatedBuffer : "+concatenatedBuffer.byteLength)concatenatedBuffer.fileStart=offset;offset+=concatenatedBuffer.byteLength;// update offsetmp4boxfile.appendBuffer(concatenatedBuffer);console.log('Appended ArrayBuffer to MP4Box file',{offset: offset});// Reset accumulated buffers and offsetaccumulatedBuffers=[];}}// Append any remaining buffersif(accumulatedBuffers.length>0){constconcatenatedBuffer=concatenateArrayBuffers(accumulatedBuffers);concatenatedBuffer.fileStart=offset;offset+=concatenatedBuffer.byteLength;mp4boxfile.appendBuffer(concatenatedBuffer);}}mediaSource.addEventListener("sourceopen",onSourceOpen);mediaSource.addEventListener("sourceclose",onSourceClose);constblobUrl=URL.createObjectURL(mediaSource);setSrc(blobUrl);// sets URL for <video src={src} controls />};functionconcatenateArrayBuffers(chunks){consttotalLength=chunks.reduce((acc,chunk)=>acc+chunk.length,0);constconcatenatedBuffer=newUint8Array(totalLength);letoffset=0;for(constchunkofchunks){concatenatedBuffer.set(chunk,offset);offset+=chunk.length;}returnconcatenatedBuffer.buffer;}
The text was updated successfully, but these errors were encountered:
Hello,
I'm having problems playing video files from a readable stream. I did a simple test using the Fetch API and it works fine, but in my case I'm dealing with large encrypted files that are decrypted on the fly using
rcloneInstance.File.createReadStream(fetchStreamFactory(vid_URL))
from rclone-js , which returns a readable stream. I think the issue might be how I'm handling the appending of the arrayBuffer. Looking at the logs I can see that the file info is successfully extracted and the MIMECodec is also correctly identified, but the video does not play.My code:
The text was updated successfully, but these errors were encountered: