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

Request for appendFile method #797

Open
StephDam opened this issue Nov 25, 2024 · 4 comments
Open

Request for appendFile method #797

StephDam opened this issue Nov 25, 2024 · 4 comments

Comments

@StephDam
Copy link

Hi,

I try to optimize the time to load big files. For the moment, I follow a 2 step approach 👍

  • First I read the input file in a memory buffer (UINT8Array)
  • Then I write the contents of the buffer to FFMPEG fs using ffmpeg.FS.writeFile method.

However I think it would be faster reading the source file into chunks with File Stream Reader and then writes directly these chunks in append mode to the FS object.

Unfortunately ffmpeg.FS does not expose the appendFile method, or even better it would be great to have a File Stream Writer.

Thanks,
Stéphane

@lucasgelfond
Copy link
Collaborator

slammed for time now but - if you get a patch up i'm happy to review / build / include!

@pavloshargan
Copy link

Use ffmpeg.mount('WORKERFS' ...

It will work with the file directly on your machine without copying it to memory

Check my example app: https://github.com/pavloshargan/quicksplit

@dahmadjid
Copy link

I would love to have this as well. emscripten supports appendFile correctly, it will be great if the ffmpeg api supports it directly

@LostBeard
Copy link
Contributor

@pavloshargan 👍

WORKERFS is the best way right now to use large files for input. The file is not read into memory all at once and is not copied before use.

Example

const transcodePicker = async () => {
    let fileHandle;
    const pickerOpts = {
        types: [
            {
                description: "Videos",
                accept: {
                    "video/*": [".mp4", ".m4v", ".webm", ".avi", ".mkv", ".mov", ".wmv"],
                },
            },
        ],
        excludeAcceptAllOption: true,
        multiple: false,
    };
    [fileHandle] = await window.showOpenFilePicker(pickerOpts);
    let file = await fileHandle.getFile();
    const inputDir = '/input';
    const inputFile = `${inputDir}/${file.name}`;
    await ffmpeg.createDir(inputDir);
    await ffmpeg.mount('WORKERFS', {
        files: [ file ],
    }, inputDir);
    await ffmpeg.exec(['-i', inputFile, 'output.mp4']);
    const output = await ffmpeg.readFile('output.mp4');
    videoEl.src = URL.createObjectURL(new Blob([output.buffer], { type: 'video/mp4' }));
    await ffmpeg.unmount(inputDir);
    await ffmpeg.deleteDir(inputDir);
};

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

5 participants