0
votes

I want to convert videos files (like .mp4 or .avi) to .m3u8 in nodeJs. I tried to do that with ffmpeg and node-js, but that don't work : 'Output format m3u8 is not available'.

Here is my nodeJs code :

const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffmpeg = require('fluent-ffmpeg');

var cmd = ffmpeg('./flir_20191202T174341.mp4')
    .setFfmpegPath(ffmpegInstaller.path)
    .videoBitrate(1024)
    .videoCodec('divx')
    .format('m3u8')
    .on('end', () => {
        // ...
    })
    .on('error', err => {
        console.error(err);
    })
    .save('./file-out.m3u8');
console.log('Hello !');
console.log(cmd);

Do you know how can I do that correctly ?

Thank's in advance.

Jérémy.

2

2 Answers

0
votes

I found the solution :

var fs = require('fs');
var ffmpeg = require('fluent-ffmpeg');

// open input stream
var infs = new ffmpeg

infs.addInput('video.mp4').outputOptions([
    '-map 0:0',
    '-map 0:1',
    '-map 0:0',
    '-map 0:1',
    '-s:v:0 2160x3840',
    '-c:v:0 libx264',
    '-b:v:0 2000k',
    '-s:v:1 960x540',
    '-c:v:1 libx264',
    '-b:v:1 365k',
    // '-var_stream_map', '"v:0,a:0 v:1,a:1"',
    '-master_pl_name master.m3u8',
    '-f hls',
    '-max_muxing_queue_size 1024',
    '-hls_time 1',
    '-hls_list_size 0',
    '-hls_segment_filename', 'v%v/fileSequence%d.ts'
]).output('./video.m3u8')
    .on('start', function (commandLine) {
        console.log('Spawned Ffmpeg with command: ' + commandLine);
    })
    .on('error', function (err, stdout, stderr) {
        console.log('An error occurred: ' + err.message, err, stderr);
    })
    .on('progress', function (progress) {
        console.log('Processing: ' + progress.percent + '% done')
    })
    .on('end', function (err, stdout, stderr) {
        console.log('Finished processing!' /*, err, stdout, stderr*/)
    })
    .run()
0
votes

Step 1: Open up your terminal and install the package manager Homebrew for OS X. If you haven’t had it on your PC, you can run the following command to install it.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Step 2: When finishing the installment of the Homebrew, run the following command codes to install the ffmpeg.

Brew install ffmpeg

Step 3: Now you can use the ffmpeg to convert the files. What you need to do is to enter the command line shown below and click the enter button for the system to respond to your request.

ffmpeg -i input.mp4 -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls index.m3u8

Source: https://enjoy-online-audio-video-movie.blogspot.com/2021/05/3-best-tools-for-converting-mp4-to-m3u8.html