FFMPEG Shell Bash Script to Create HLS Live Video Streaming Playlists in Terminal



This script has been forked from https://github.com/bentasker/HLS-Stream-Creator project. Renamed script from “HLS-Stream-Creator.sh” to “hls.sh”. Some issues have been fixed + new params.

hls.sh is a simple BASH Script designed to take a media file, segment it and create an M3U8 playlist for serving using HLS. There are numerous tools out there which are far better suited to the task, and offer many more options. This project only exists because I was asked to look into HTTP Live Streaming in depth, so after reading the IETF Draft I figured I’d start with the basics by creating a script to encode arbitrary video into a VOD style HLS feed.

I-FRAME Creator(iframe.sh) is used to generate I-Frame Playlist from existing HLS Playlist.


ffmeg must be installed.


Usage is incredibly simple

So to split a video file called example.avi into segments of 10 seconds, we’d run


Adaptive Streams

As of HLS-6 the script can now generate adaptive streams with a top-level variant playlist for both VoD and Linear input streams.

In order to create seperate bitrate streams, pass a comma seperated list in with the -b option

By default, transcoding for each bitrate will be forked into the background – if you wish to process the bitrates sequentially, pass the -f option

In either case, in accordance with the HLS spec, the audio bitrate will remain unchanged


As of version 1, the HLS resources will be output to the directory output. These will consist of video segments encoded in H.264 with AAC audio and an m3u8 file in the format

#EXTINF:10, no desc
#EXTINF:10, no desc
#EXTINF:10, no desc
#EXTINF:5, no desc

The alternative audio media playlists with audio segments are created. The appropriate EXT-X-MEDIA entries are added into TLM Playlist and a new attribute “AUDIO=” to each video playlist entry. like :



Using a Specific FFMPEG binary

There may be occasions where you don’t want to use the ffmpeg that appears in PATH. At the top of the script, the ffmpeg command is defined, so change this to suit your needs

Additional Environment Variables

There are few environment variables which can control the ffmpeg behaviour.

  • VIDEO_CODEC – The encoder which will be used by ffmpeg for video streams. Examples: libx264nvenc
  • AUDIO_CODEC – Encoder for the audio streams. Examples: aaclibfdk_accmp3libfaac
  • NUMTHREADS – A number which will be passed to the -threads argument of ffmpeg. Newer ffmpegs with modern libx264 encoders will use the optimal number of threads by default.
  • FFMPEG_FLAGS – Additional flags for ffmpeg. They will be passed without any modification.

Example usage:

I-FRAME Creator


Usage is incredibly simple


I-FRAME Creator shall be called by hls.sh to generate I-FRAME Playlist when encoding new HLS


Leave a Reply