Skip to content

Instantly share code, notes, and snippets.

@ivorpad
Created September 19, 2024 22:04
Show Gist options
  • Save ivorpad/a198c19ab4a96f4c070e9e8addd66727 to your computer and use it in GitHub Desktop.
Save ivorpad/a198c19ab4a96f4c070e9e8addd66727 to your computer and use it in GitHub Desktop.
Download m3u8 files
const ffmpeg = require('fluent-ffmpeg');
const path = require('path');
const m3u8Url = 'https://stream.mux.com/playback_id.m3u8';
const outputPath = path.join(__dirname, 'output.mp4');
ffmpeg(m3u8Url)
.outputOptions([
'-c copy',
'-bsf:a aac_adtstoasc' // Bitstream filter for AAC audio
])
.on('start', (commandLine) => {
console.log('FFmpeg process started with command:', commandLine);
})
.on('progress', (progress) => {
console.log(`Downloaded ${progress.percent.toFixed(2)}%`);
})
.on('error', (err, stdout, stderr) => {
console.error('An error occurred:', err.message);
console.error('FFmpeg stderr:', stderr);
})
.on('end', () => {
console.log('Download completed successfully!');
})
.save(outputPath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment