hls2mp4
TypeScript icon, indicating that this package has built-in type declarations

1.2.8 • Public • Published

A tool for download hls/m3u8 to mp4

  • This package depends on @ffmpeg/ffmpeg, you need install it first
# install ffmpeg
npm install @ffmpeg/ffmpeg

online demo

online demo

install

# npm
npm install hls2mp4

# yarn
yarn add hls2mp4

usage

import Hls2Mp4 from "hls2mp4";

const hls2mp4 = new Hls2Mp4({
  /**
   * @type {number}
   * max retry times while request data failed
   */
  maxRetry = 3,
  /**
   * @type {number}
   * the concurrency for download ts
   */
  tsDownloadConcurrency = 10,
  /**
   * the base url of ffmpeg
   */
  ffmpegBaseUrl = 'https://unpkg.com/@ffmpeg/core@0.12.2/dist/umd',
  /**
   * progress callback
  */
  onProgress?: (type, progress) => {
    // type = 0  => load FFmpeg
    // type = 1  => parse m3u8
    // type = 2  => downloading ts
    // type = 3  => merge ts
  };
  /**
   * error callback
  */
  onError?: (error) => {};
});

const buffer = await hls2mp4.download('your m3u8 url')
if (buffer) {
  hls2mp4.saveToFile(buffer, 'test.mp4')
}
else {
  // download failed
}

as script

<script src="static/js/ffmpeg.min.js"></script>
<script src="dist/hls2mp4.js"></script>
<script>
  const hls2mp4 = new Hls2Mp4({...})
</script>

Readme

Keywords

Package Sidebar

Install

npm i hls2mp4

Weekly Downloads

5

Version

1.2.8

License

MIT

Unpacked Size

382 kB

Total Files

7

Last publish

Collaborators

  • icefee