Whisper doesn't work with mp4

I have an AI I can ask…


It’s possible to demux an MP4 file and extract the first audio stream using Node.js. You can use the mp4box module to achieve this. Here’s a step-by-step guide on how to do it:

  1. Install the mp4box module:
npm install mp4box
  1. Create a script to demux the MP4 file and extract the first audio stream:
const fs = require('fs');
const MP4Box = require('mp4box');

function demuxMP4(inputFile, outputFile) {
  const mp4box = new MP4Box.MP4Box();

  mp4box.onReady = (info) => {
    const audioTrack = info.tracks.find((track) => track.type === 'audio');
    if (!audioTrack) {
      console.error('No audio track found');
      return;
    }

    const output = fs.createWriteStream(outputFile);
    mp4box.setSegmentOptions(audioTrack.id, output, { nbSamples: Infinity });
    mp4box.start();
  };

  const inputStream = fs.createReadStream(inputFile);
  inputStream.pipe(mp4box.createStream());
}

const inputFile = 'input.mp4';
const outputFile = 'output.m4a';

demuxMP4(inputFile, outputFile);

Replace 'input.mp4' and 'output.m4a' with the paths to your input MP4 file and the desired output M4A file, respectively.

This script will demux the input MP4 file, extract the first audio stream, and save it as an M4A file. Note that this script does not remove metadata from the audio stream. If you want to remove metadata, you can use the ffmpeg library with the fluent-ffmpeg wrapper for Node.js.