Skip to content

Instantly share code, notes, and snippets.

@bpholt
Last active March 26, 2019 21:54
Show Gist options
  • Save bpholt/f73ffaf540c0153cac57f365d2859460 to your computer and use it in GitHub Desktop.
Save bpholt/f73ffaf540c0153cac57f365d2859460 to your computer and use it in GitHub Desktop.
Video encoding for self-hosted adaptive streaming
  1. Create high-quality master format (uncompressed HEVC, Apple ProRes?)

    • 60fps HEVC CRF 23 from input stills:

      ffmpeg \
        -framerate 60 \
        -pattern_type glob \
        -i "DSC_*.jpg" \
        -vcodec libx265 \
        -pix_fmt yuv420p \
        -vtag hvc1 \
        -crf 23 \
        -f mp4
        <output filename>
  2. Transcode to various resolutions and framerates, maybe something like this?

    • 4k
      • HEVC CRF 23
      • HEVC CRF 28
      • h264 CRF 23
      • h264 CRF 18
    • 1080p
      • HEVC CRF 23
      • HEVC CRF 28
      • h264 CRF 23
      • h264 CRF 18

    not sure what to do with framerates > 30fps (Apple recommends including at least one source ≤ 30fps for compatibility with older players)

  3. Fragment

    mp4fragment <input> <output>
  4. Generate Dash / HLS Playlists

    mp4dash \
      --verbose \
      --profile=on-demand \
      --hls \
      --exec-dir=$(which mp4hls) 
      <input files…>
  5. Video tag

    <video controls width="100%">
      <source src="hls.m3u8" type="application/vnd.apple.mpegurl" />
      <source src="dash.mpd" />
      <source src="raw-h264.m4v" type="video/mp4" />
    </video>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment