FFMPEG creating mp3 with "Junk" at the end

150 Views Asked by At

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.

0

There are 0 best solutions below