Comments (5)
I think you need to check every segment file size and duration to know the peak bitrate.
Here's an example of single-variant master playlist generation.
const fs = require('fs');
const path = require('path');
const HLS = require('hls-parser');
const {MasterPlaylist, Variant} = HLS.types;
const BASE_DIR = path.join(__dirname, 'video_chunks');
const MEDIA_PLAYLIST = path.join(BASE_DIR, 'index0.m3u8');
const mediaPlaylistString = fs.readFileSync(MEDIA_PLAYLIST, {encoding: 'utf8'});
const {segments} = HLS.parse(mediaPlaylistString);
const maxBitrate = segments.reduce((max, segment) => {
const SEGMENT = path.join(BASE_DIR, segment.uri);
const {size} = fs.statSync(SEGMENT);
const bitrate = size * 8 / segment.duration;
return Math.max(max, bitrate);
}, 0);
const low = new Variant({uri: './index0.m3u8', bandwidth: Math.ceil(maxBitrate)});
const masterPlaylist = new MasterPlaylist({variants: [low]});
console.log(HLS.stringify(masterPlaylist));
from hls-parser.
It's possible to create a simple master playlist if you already have media playlists and segment files.
You can define EXT-X-STREAM-INF (Variant) by calculating bandwidth based on the duration and the byte size of the segment files.
Here's a pseudo code:
const mediaPlayList = HLS.parse(fs.readFileSync('low.m3u8'));
const low = new Variant({uri: './low.m3u8', bandwidth: segmentsByteSizeLow * 8 / mediaPlayList.targetDuration}); // BANDWIDTH must be the peak bits/seconds though...
const mid = new Variant(....
const high = new Variant(....
const masterPlaylist = new MasterPlaylist({variants: [low, mid, high]});
return HLS.stringify(masterPlaylist);
from hls-parser.
Awesome. I had something like this in mind after looking at the tests altough I still have one question probably unralated to this tool so I am sorry if I am overstepping but do you know how to get this segment byte size from my segments? Should I use ffmpeg or something like this?
To create the playlists and segments I am using something like the following code:
ffmpeg -i 20170718_203132.mp4 -c 24 -vcodec libx264 -acodec aac -ac 1 -strict -2 -b:v 400k -profile:v baseline -maxrate 400k -bufsize 1835k -hls_time 10 -hls_playlist_type vod -vsync 1 -vf scale=-2:240 video_chunks/index0.m3u8
I would bet that it is probably related to the bitrate argument but I am not sure. If you could help it would be awesome.
from hls-parser.
I can't thank you enough man. This will be a huge help.
from hls-parser.
This helped me too. Thanks a lot!
from hls-parser.
Related Issues (20)
- Encryption with no IV (missing default behaviour)
- Issue with hls.stringify for cloned hls object
- support buffered input for hls.parse & buffered output for hls.stringify
- Release the last version HOT 2
- Stringify : Manifest malformation with multiple rendition (group-id) HOT 6
- Error when using `noImplicitAny` in a typescript project HOT 6
- Not working in the browser? HOT 1
- When specifying several EXT-X-KEY one after another(multi drm playlist), only the last EXT-X-KEY is assigned to the segments HOT 4
- Types are not matching the documentation
- If you try to output a playlist in HLS-V4 format, an error will occur. HOT 7
- Handling ad markers SCTE-35 HOT 2
- Correctly stringify bytrange of EXT-X-MAP
- Multiple markers is unsupported HOT 1
- The library doesn't parse EXT-X-PART tag HOT 1
- EXT-X-DATERANGE tags with no START-DATE attribute are not ignored with strictMode disabled HOT 1
- Issue in maintaining segment key when splicing the segment HOT 7
- License HOT 4
- support for EXT-X-PREFETCH HOT 5
- Support HLS versions 8 and above HOT 4
- EXT-X-BYTERANGE should come after other segment information HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hls-parser.