Giter VIP home page Giter VIP logo

hls-segmenter's Introduction

HLS-segmenter

HLS Segmenter is a configurable python script to achieve Http Live Streaming segmentation, playlist and variants playlist from a given movie file.

HLS Segmenter use ffmpeg, and works great on Linux.

Segmenter

DEPENDENCIES: FFmpeg

CONFIGURE:

You can create "Profiles" in presets.py (see existing ones to get an idea).

USE:

./segmenter -i video_path [-u url_prefix] [-p]

  • -i video_path indicate the path to the input video file
    • it can be either relative (to the script execution path) or absolute.
  • -u url_prefix allow to prepend an url to the playlists path, i.e. : http://yourserver/videofolder/
    • This base url should reach the input video folder location.
  • -p only regenerate the variant playlist but do not re-encode the chunks (dryrun)

Let say your input media is /var/www/video/mymovie.mp4: And that you have a webserver with http://localhost/ linked to /var/www/

The command will be

./segmenter -i /var/www/video/mymovie.mp4 -u http://localhost/video/

It will create a new directory /var/www/video/mymovie/ next to the input video location, with

  • a re-encoded version of the intput movie, using the first profile (can be use as a fallback for players without HLS support) also named /var/www/video/mymovie/mymovie.mp4
  • the main variant playlist file .m3u8, which link to the profile's playlists named /var/www/video/mymovie/mymovie.m3u8
  • subdirectories for each quality profile, hosting the chunks and the associated playlist.

To play the HLS stream you only need to provide the movie.m3u8 url, like this http://localhost/video/**mymovie**/**mymovie.m3u8**

And if your client doesn't support HLS you can fallback to http://localhost/video/**mymovie**/**mymovie.mp4** which is a re-encode of your original movie with the first preset in the list.

Your original movie should still be available from there: http://localhost/video/**mymovie.mp4**

TODO

Segmenter

HLS Dealer

  • Create a small HTTP file server to distribute the M3U8 playlists and chunks
  • Proper MIME Type

RESSOURCES

EXEMPLE MAIN VARIANT M3U8 PLAYLIST

command: ./segmenter -i /var/www/myvideo.mp4 -u http://localhost/ playlist url: http://localhost/myvideo/myvideo.m3u8

#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=244400,RESOLUTION=416x234
http://localhost/myvideo/0-ugly/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=421120,RESOLUTION=416x234
http://localhost/myvideo/1-bad/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=733200,RESOLUTION=480x270
http://localhost/myvideo/2-tiny/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1182145,RESOLUTION=640x360
http://localhost/myvideo/3-low/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2192834,RESOLUTION=640x360
http://localhost/myvideo/4-medium/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5888165,RESOLUTION=960x540
http://localhost/myvideo/5-high/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=8663048,RESOLUTION=1280x720
http://localhost/myvideo/6-hd/stream.m3u8

BITRATE EVALUATION

FFmpeg can report the bitrate of the ts stream. Use the ffprobe tool and you'll get output like this:

ffprobe ./myvideo/3-low/3-low3.ts (the third chunk for the "low" profile)

Input #0, mpegts, from '3-low3.ts':
  Duration: 00:00:02.00, start: 7.423222, bitrate: 851 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 90k tbn, 48 tbc
    Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 93 kb/s

The bitrate is being given in kilobits per second, so multiply it by 1024 and you'll have the value you need for the BANDWIDTH tag.

hls-segmenter's People

Contributors

henryfentanes avatar maigre avatar

Watchers

 avatar

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.