Guide to converting audio files to HLS format using fluent-ffmpeg in Node.js

For my project, I utilized the following code snippet:

ffmpeg.setFfprobePath(ffprobeBin.path);
ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg(audioPath, {timeout: 432000})
    .audioCodec('aac')
    .audioBitrate('128k')
    .outputOptions(['-hls_time 10', '-hls_list_size 0'])
    .format('hls')
    .output(`${folderPath}/${streamName}`).on('end', () => {
  console.log(`Finished processed ${streamName} for video Id:  ${folderName}`);

  Audio.findByIdAndUpdate(nameFile.split('.')[0], {
    streamUrl: streamName
  }

Unfortunately, this setup is not working as expected with my mp3 audio file. It seems that the issue may be related to the presence of images or copyright within the mp3 file.

I have also experimented with other audio codecs such as aac and libmp3lame, but the problem persists.

Answer №1

Choose option map 0-a to select specific sound from the audio file;

ffmpeg(audioPath, {timeout: 432000}).addOptions([
            '-map 0:a',
            '-c:a aac',
            '-b:a 128k',
            '-f hls',
            '-hls_time 10',
            '-hls_list_size 0'
          ])

Answer №2

When dealing with multiple streams, it's important to be aware that the hls encoder may not always automatically select the audio stream. To ensure the correct stream is chosen, consider using the -map option to designate the desired audio stream.

Insert the following line of code after the audioBitrate method:

.addOptions(['-map 0:a'])

Please note: There aren't any specific functions for -map and other stream-related tasks like those found in ffmpeg cli. That's why we rely on the outputOptions method.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to automatically run all node.js files within a specific folder upon startup?

Is there a way to automate the running of all node.js scripts within a specific folder on startup, perhaps using an npm script like npm run someScript for each subfolder? Is it possible to achieve this without creating a Java program? ...

Installation of npm failed due to error codes E404 or ENOENT

My current node version is 8.9.1; NPM version I am using is 5.5.1; Whenever I attempt to install modules using NPM, I encounter errors such as 'code E404' or 'code ENOENT'; I have tried installing various modules, including 'tld ...

Module 'ngx-bootstrap' not found in project

My application is encountering an issue with ngx-bootstrap where the module can no longer be detected unless the path is specified. For instance: import { BsModalService, BsModalRef } from 'ngx-bootstrap'; results in "Cannot find module ' ...

difficulty in accessing data from local Node.js server on devices connected to the network using a React frontend interface

My client application is running on localhost:3001 while my server application is on localhost:3000 The server is listening on 0.0.0.0:3000 Data loads normally on my Mac, but I encounter an issue when trying to retrieve data on mobile devices within the ...

How to pass arguments to the `find` method in MongoDB collections

I've been attempting to pass arguments from a function to the MongoDB collection find method. Here's what I have so far: async find() { try { return await db.collection('users').find.apply(null, arguments); } catch(err) { c ...

What is the best way to incorporate a condition in the registration controller to verify the uniqueness of the email address being registered

When a user attempts to register and provide their details, this API is triggered. I am exploring the possibility of adding a condition to check if the email already exists. It seems like I need something along the lines of: const user = await User ...

Need a module from the main directory

Imagine having these folders: 'C:\\src' // Main directory. 'C:\\src\\inner1' // Contains 'a.js' 'C:\\src\\inner2\\innermost' // Contains 'b.js' ...

Exploring ways to locate files within node-inspector

As a newcomer to using node-inspector on Ubuntu, I am attempting to debug an Express application for the first time. Upon running the program and accessing http://0.0.0.0:8080/debug?port=5858 in Chromium or Google Chrome, all scripts load successfully in ...

Sending FormData from one Node/Express application to another Node/Express application can be done easily by utilizing the 'request'

I'm currently running a frontend website (ejs and node/express) on localhost:8000, while the backend server (node/express) is running on localhost:8010. My database is located in the backend server. I have successfully implemented Social login (fb, go ...

Exploring the use of Node.js exclusive modules in Docker containers

I have a nodejs project that includes references to a module I developed and hosted in a private Github repository. The dependencies listed in the package.json file are as follows: "dependencies": { ... other stuff ... "my_module": "git+https://gi ...

Variables for NPM Configuration

After researching the best way to securely store sensitive information, I decided to utilize the config package and environment variables for added security. Here is how I implemented this setup: Created a config directory containing two files: default.js ...

Is it possible to run Node and Apache on the same port concurrently?

Currently, I have an application running on Node.js and PHP. I am using different ports for each. Is it possible to run both Node and Apache on the same port 8080? Is there any method to run multiple applications on port 8080 simultaneously? Thank you. ...

What are some methods to display search outcomes in mongodb?

I have created a Comment Model with specific fields including userId, contentId, repliedTo, and text. The schema for the Comment Model is defined as follows: const CommentSchema = mongoose.Schema({ userId: { type: mongoose.Schema.Types.ObjectId ...

Encountered an error while web crawling in JavaScript: Error - Connection timeout

I encountered an error while following a tutorial on web crawling using JavaScript. When I execute the script, I receive the following errors: Visiting page https://arstechnica.com/ testcrawl ...

Is there a way to ensure that all asynchronous functions have finished executing before assigning them to module.exports?

Currently, I am working on developing an app that generates routes based on data retrieved from a MongoDB database using Mongoose. Here is the current setup: var app = express(); var articleRoute = require('./article.js'); var Articles = requi ...

The aggregation pipeline in nodeJS with mongoDB is failing to return any results, returning an empty array instead

Currently, I am enrolled in Jonas Schmeddtman's Node.js course where I am working on developing a tour App. However, I have encountered an issue where sending a request via Postman on the specified route results in an empty array instead of the expect ...

Mongoose transforms the outcome of the create() function

Is there a way to exclude certain fields from the result of a Mongoose create() command for a new document in a collection? Currently, I am seeking to avoid returning all fields of an object, particularly the password field which consists of hash and salt ...

Tips for obtaining results from a Node.js callback function

Struggling to successfully retrieve the callback result and transfer it to a different page, although I've managed to establish the connection and can see the data in the console.log output. My query is: How can I access the callback result and send ...

NodeJS Express throwing error as HTML on Angular frontend

I am currently facing an issue with my nodejs server that uses the next() function to catch errors. The problem is that the thrown error is being returned to the frontend in HTML format instead of JSON. I need help in changing it to JSON. Here is a snippe ...

The attempt to access http://registry.npmjs.org/check was unsuccessful due to a connection error (ECONNREFUSED)

Upon executing the command "npm install -g check" in the cmd prompt, I encountered the following error: npm ERR! code ECONNREFUSED npm ERR! errno ECONNREFUSED npm ERR! FetchError: request to http://registry.npmjs.org/check failed, reason: connect ECONNREF ...