Vanilagy / mp4-muxer

MP4 multiplexer in pure TypeScript with support for WebCodecs API, video & audio.
https://vanilagy.github.io/mp4-muxer/demo
MIT License
419 stars 32 forks source link

Error when using FileSystemWritableFileStreamTarget #24

Closed Mat-thieu closed 7 months ago

Mat-thieu commented 10 months ago

The following error:

Screenshot 2023-11-30 at 15 26 27

Occurs when trying to use FileSystemWritableFileStreamTarget with fileWriter.

This write function (in the build code) is expecting a blob not an object

Screenshot 2023-11-30 at 15 27 36

For now I've worked around the issue by wrapping the fileWriter

   const wrapFileWriter = (fileWriter) => {
        const originalWrite = fileWriter.write;
        const modifiedWrite = (payload) => {
            const blob = new Blob([payload.data]);
            originalWrite.call(fileWriter, blob);
        }
        fileWriter.write = modifiedWrite;
        return fileWriter;
    };
    let muxer = new Mp4Muxer.Muxer({
    target: new Mp4Muxer.FileSystemWritableFileStreamTarget(wrapFileWriter(fileWriter)),
        ...
    }
Vanilagy commented 10 months ago

The FileSystemWritableFileStreamTarget expects a FileSystemWritableFileStream as a parameter! Its write method also accepts ArrayBuffers as input.

It seems like you are passing it something else. How are you getting your fileWriter?

Mat-thieu commented 10 months ago

@Vanilagy

Aah right, I see! Indeed I'm passing a different object. I'm passing it a FileWriter which is returned from a fileEntry.createWriter directly.

I'm obtaining this fileEntry from the following code

export default function requestTempFile(name, sizeInMb) {
    return new Promise((resolve) => {
        const fileSystem = (window.requestFileSystem || window.webkitRequestFileSystem);
        fileSystem(window.TEMPORARY, sizeInMb * 1024 * 1024, (fs) => {
            fs.root.getFile(name, { create: true }, (fileEntry) => {
                resolve(fileEntry);
            });
        });
    });
}

Which is a non-standard, chromium-specific way of creating a sandboxed file.

It's a slightly different use case, it can likely just be handled by the StreamTarget directly

Vanilagy commented 10 months ago

Yes exactly, these custom cases are supposed to be handled by StreamTarget. It'll be very easy and quick to use! In fact, FileSystemWritableFileStreamTarget is nothing but a very thin wrapper around StreamTarget.

Vanilagy commented 9 months ago

Has your issue been resolved?

Vanilagy commented 7 months ago

I'll close this issue for now as it seems stale, so I assume your issue has been resolved. If you still need help with something, feel free to reopen it :)