3

I am building a video editor whose process looks like this:

Demuxing -> Decoding -> Editing -> Encoding -> Muxing.

The demuxing and muxing process is currently done with mp4box.js. I would like to replace mp4box.js with ffmpeg.wasm. Unfortunately, I can't get along with the process.

What should FFmpeg.wasm do in the demuxing process?

  • load a .mp4 file
  • extract the encodedVideoChunks and store them as EncodedVideoChunk objects in an array
  • extract the encodedAudioChunks and store them as EncodedAudioChunk objects in an array
  • get some metadata like: duration, timescale, fps, track_width, track_height, codec, audio_channel_count, sample_rate ....
public async loadFile(file: File) {
    let data = await fetchFile(file)
    let blob = new Blob();
    await this.ffmpeg.setProgress(({ratio }) => console.log(`Extracting frames: ${Math.round(ratio * 100)}%`));
    this.ffmpeg.FS('writeFile', 'videoTest.mp4', data);
    //Here is where I am struggling
    //Should look like this: 
    //const command = '-i videoTest.mp4 -c:v copy .... '
    //await this.ffmpeg.run(command);
    //....
}

Lets get deeper into my problem:

Because FFmpeg.wasm is still a cli tool, I have no idea what the best way to safe the encodedChunks into a file is (and what kind of filetype I should use). Further I would like to know how to read that file propertly so that i can safe the input of the file into seperate EncodedVideo- and AudioChunks.

VC.One
  • 14,790
  • 4
  • 25
  • 57
  • Hello, I'm in a similar position. Were you able to replace mp4box with ffmpeg? – KarelPrdel Jul 01 '23 at 13:45
  • 2
    @KarelPrdel I found out that this is not the right way to replace mp4box.js with ffmpeg. I found this demo and implemented it. https://github.com/w3c/webcodecs/pull/549 . I had to make some changes in the building process and the source code because I wanted to demux video streams as well. I still have a problem that I get an "partial file" warning and can't demux a file if I don't put the whole file in the SharedArrayBuffer. I currently don't work on this project anymore but will continue soon. If you get the same problem and find a way to solve it - let me know:) – Kevin Baving Jul 03 '23 at 16:31

0 Answers0