hls-maker
v1.2.6
Published
HLSMaker is a library that helps create HLS (HTTP Live Streaming) video segments from a source file. HLS is a protocol for distributing video over the internet.
Downloads
29
Maintainers
Readme
HLSMaker
HLSMaker is a library that helps create HLS (HTTP Live Streaming) video segments from a source file. HLS is a protocol for distributing video over the internet.
Installation
Install the library from npm:
npm install hls-maker
Usage
Using Promises
import { HLSMaker, HLSMakerConfig } from 'hls-maker';
const options: HLSMakerConfig = {
sourceFilePath: 'path/to/source/video.mp4',
// Other options as per your requirements
};
const hlsMaker = new HLSMaker(options);
// Start the conversion process
hlsMaker.conversion(progress => {
console.log(`Progress: ${progress.percent}%`);
}).then(() => {
console.log('Conversion completed');
}).catch(error => {
console.error('Error:', error);
});
Using async/await
import { HLSMaker, HLSMakerConfig } from 'hls-maker';
const options: HLSMakerConfig = {
sourceFilePath: 'path/to/source/video.mp4',
// Other options as per your requirements
};
async function convertVideo() {
const hlsMaker = new HLSMaker(options);
try {
await hlsMaker.conversion();
console.log('Conversion completed');
} catch (error) {
console.error('Error:', error);
}
}
convertVideo();
Concatenating HLS Streams
You can concatenate HLS streams using the concat method. This method combines multiple HLS streams into a single stream.
Using callback function
import { HLSMaker, ConcatConfig } from 'hls-maker';
const options: ConcatConfig = {
sourceFilePath: 'path/to/first/video.mp4',
hlsManifestPath: 'path/to/concatenated/output.m3u8',
isLast: true // Set to true if this is the last stream in the sequence
};
HLSMaker.concat(options, function (process) {
console.log("Processing", process);
});
Using async/await
import { HLSMaker, ConcatConfig } from 'hls-maker';
const options: ConcatConfig = {
sourceFilePath: 'path/to/first/video.m3u8',
hlsManifestPath: 'path/to/concatenated/output.m3u8',
isLast: true // Set to true if this is the last stream in the sequence
};
async function concatVideos() {
try {
await HLSMaker.concat(options);
console.log('Concatenation completed');
} catch (error) {
console.error('Error:', error);
}
}
concatVideos();
Insert HLS Streams
You can insert HLS streams using the insert method. This method combines multiple HLS streams into a single stream.
await HLSMaker.insert({
hlsManifestPath: 'path/to/first/output.m3u8',
sourceHlsManifestPath: 'path/to/source/input.m3u8',
spliceIndex: 10 // insert from segment index
splicePercent: 30// insert from segment percent
});
Options
HLSMakerConfig
sourceFilePath
(required): Path to the source file.hlsStartTime
: Start time for segmenting in HLS.hlsDuration
: Duration of the segment for HLS.hlsManifestPath
: Path to the HLS manifest file after segmenting.hlsSegmentDuration
: Duration of each segment (in seconds).hlsListSize
: Manifest list size.appendMode
(required): Append mode for segments.endlessMode
(required): Endless mode (no termination).
ConcatConfig
sourceFilePath
(required): Path to the source file of the first segment.hlsManifestPath
(required): Path to the output manifest file after concatenation.isLast
(required): Set to true if this is the last stream in the sequence.
Support
Contact the author: [email protected]
License
This library is released under the MIT License.