Giter Club home page Giter Club logo

Comments (5)

kuu avatar kuu commented on August 26, 2024 4

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.

kuu avatar kuu commented on August 26, 2024 1

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.

murilozilli avatar murilozilli commented on August 26, 2024

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.

murilozilli avatar murilozilli commented on August 26, 2024

I can't thank you enough man. This will be a huge help.

from hls-parser.

Beloin avatar Beloin commented on August 26, 2024

This helped me too. Thanks a lot!

from hls-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.