#!/usr/bin/env bash
FILENAME="$1"
OUTDIR="${2:-output}"
FFMPEG_BIN="${FFMPEG_BIN:-ffmpeg}"

if [[ -n "$FILENAME" ]]; then
  echo -n ""
else
  echo "$FILENAME not found"
  exit 1
fi

mkdir -p "$OUTDIR"

"$FFMPEG_BIN" \
  -i "$FILENAME" \
  -map 0:v \
  -map 0:a \
  -c copy \
  -f hls \
  -hls_time 30 \
  -hls_playlist_type vod \
  -hls_segment_type fmp4 \
  -hls_flags independent_segments \
  -hls_segment_filename "$OUTDIR/segment_%05d.m4s" \
  "$OUTDIR/playlist.m3u8"
