MPEG DASH (MPD) to MP4 in Node.js?

114 Views Asked by At

I am trying to convert streams to .mp4 files. I have successfully converted an HLS to MP4 using fluent-ffmpeg package on version 2.1.2. I did so with with the following code:

var ffmpegCommand = ffmpeg();
            ffmpegCommand
            .input(HLS FILE HERE)
            .inputOptions('-protocol_whitelist file,http,https,tcp,tls,crypto,data')
            .on("error", (err, stdout, stderr) => {
                console.log(err)
                let error = new Error(err.message)
                error.code = err.code || 'FILE_CONVERSION_M3U8_TO_MP3/UNKNOWN_ERROR';
                error.status = err.status || 500;

                console.log('An error occurred: ' + err.message, err, stderr);
                reject(error)
            })
            .on("end", () => {
                console.log(temporaryFilePath2)
                resolve(temporaryFilePath2);
            })
            .on('progress', function(progress) {
                console.log('progress: ' + (progress.percent || 0).toFixed(2) + '%。');
                progressGathering.push((progress.percent || 0).toFixed(2))

                if(progressGathering.length == 10 && progressGathering[9] == 0.00){
                    let error = new Error("File is a live stream.")
                    error.code = 'FILE_CONVERSION_M3U8_TO_MP3/LIVESTREAM_SUPPORT'
                    error.status = 501

                    ffmpegCommand.kill()
                    reject(error)
                }
            })
            .inputOptions('-allowed_extensions ALL')
            .outputOptions("-c copy")
            .output(temporaryFilePath2)
            .run();

            setTimeout(() => {
                ffmpegCommand.kill();
                let error = new Error("The file selected was too large or the network was hanging. Conversion timeout.")
                error.code = 'FILE_CONVERSION_M3U8_TO_MP3/TIMEOUT'
                error.status = 599;
                reject(error)
            }, 300000) // 5 minutes

However, when I attempt something similar with a mpd file url in the input, I get several errors that are all the same:

ffmpeg exited with code 1: https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd: Invalid data found when processing input

Is this something fluent-ffmpeg can't handle? If so, I would like to know another package that can accomplish this.

0

There are 0 best solutions below