0

I have a web application which converts WebM files to mp3 using FFMPEG.js in the Client-Side. Once the mp3 conversion finishes, users are prompted to download their file.

Lately, I realized that a lot of mp3 files which I tried to converted have a different duration value than the original WebM file. The duration is usually longer. For instance, a WebM file with duration of 2:16 gets converted to an mp3 file with a duration of 2:29. Once the player reaches at 2:16 it just goes back to the start.

I have tried to open the file in Audacity but it keeps saying that this MP3 file seems to be "Malformed".

I also tried to use MP3val and it says the file has junk at the end.

Code Snippets:

const worker = new Worker("/ffmpeg-worker-mp4.js");
import { fetchFile } from "@ffmpeg/ffmpeg"; // https://www.npmjs.com/package/@ffmpeg/ffmpeg

const convertSong = async (title, id, bitrate) => {
    setProgress("Initializing...")
    ffmpegVars = [title]
    
    worker.postMessage({
      type: "run",
      arguments: ["-i", `input.webm`, "-c:a", "libmp3lame",  "-vn", "-ab", `${bitrate ? bitrate : 256}k`, "-ar", "44100", "-f", "mp3", `output.mp3`],
      MEMFS: [{ name: "input.webm", data: await fetchFile(`/api/download/stream?video=${id}`) }]
    });
}

convertSong(data.title, data.id, data.bitrate)

I'm literally willing to pay anyone who helps me fix this.

  • Your ffmpeg invocation is very vanilla, which makes me wonder if the input webm audio stream is corrupted/malformed. Have you tried the same command with a latest desktop FFmpeg build? Also, what happens if you output .wav file instead? Finally, what happens if you copy extract audio stream to an .ogg file? – kesh Jul 13 '22 at 15:08
  • @kesh thank you very much for the answer, I'll try all of these out and let you know. Also, what do you mean by " the ffmpeg invocation is very vanilla"? –  Jul 13 '22 at 15:53
  • I meant that your command is very simple without a complex filtergraph or unusual encoding options. This makes me question the validity of the input data first. – kesh Jul 13 '22 at 16:38
  • I've been doing this conversion server side and it was working properly. Since Since moved this process client side it started having that issue. –  Jul 13 '22 at 17:02
  • I see. It could be the build issue then (the repo seems to be pretty quiet for over a year). Have you tried alternatives like [ffmpeg.wasm](https://github.com/ffmpegwasm/ffmpeg.wasm)? (Can't comment much beyond this as I don't dev in JS.) – kesh Jul 13 '22 at 17:09
  • I've tried ffmpeg wasm but it isn't supported to all the browser and I also got to enable cross origin isolation which I really don't want to do –  Jul 13 '22 at 19:00
  • OK. One last thing I can throw out to you is maybe build FFmpeg.js yourself (the version on npm is 2 years old) using the current FFmpeg source. Good luck. – kesh Jul 13 '22 at 19:07

0 Answers0