Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleBlock encoding support #32

Open
umstek opened this issue Mar 11, 2021 · 1 comment
Open

SimpleBlock encoding support #32

umstek opened this issue Mar 11, 2021 · 1 comment

Comments

@umstek
Copy link

umstek commented Mar 11, 2021

I'm trying to parse a webm file, drop some SimpleBlocks, and adjust the Timecodes on each block so that I can effectively trim the video. I can create Clusters and Cluster Timecodes without an issue but encoding a SimpleBlocks is a problem. Although there is an Encoder() present, there seems to be no way to create/edit a SimpleBlock. I'm looking a function that can do the inverse of tools.readBlock.

(Currently I'm using ffmpeg (wasm) but it's a bit expensive on data.)

@alx696
Copy link

alx696 commented Apr 17, 2021

@umstek Have you found a solution?

I'm trying to play webm chunks with MediaSource. I want to skip the chunks before open stream. So i can play the stream anytime. WebM was recorded by MediaRecorder.

Some of them have been deleted, but times not right:

new Blob(
                [
                    webmChunkBufferArray.shift(),
                    webmChunkBufferArray.shift(),
                    webmChunkBufferArray.shift()
                ],
                {
                    type: mimeType
                }
            ).arrayBuffer()
            .then(buffer => {
                const decoder = new Decoder();
                const elms = decoder.decode(buffer);
                console.debug(elms);

                const recodeArray = [];
                let count = 0;
                for(const elm of elms) {
                    if (elm.name === "SimpleBlock" && count < 100) {
                        count ++;
                        continue;
                    }

                    recodeArray.push(elm);
                }
                console.debug(recodeArray);

                const encoder = new Encoder();
                const recodeBuffer = encoder.encode(recodeArray);
                console.debug(recodeBuffer);

                sourceBuffer.mode = 'sequence'; // must set!
                sourceBuffer.appendBuffer(recodeBuffer);
            });

But i do not know how to get SimpleBlock from mediaRecorder.ondataavailable() stream?

new Decoder().decode(buffer): buffer must start from the begin of the webm. If not, decode failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants