Skip to content

Instantly share code, notes, and snippets.

@sarjsheff
Last active November 18, 2022 11:38
Show Gist options
  • Save sarjsheff/74a8b43cd199c61c9ed1efc2302c06e5 to your computer and use it in GitHub Desktop.
Save sarjsheff/74a8b43cd199c61c9ed1efc2302c06e5 to your computer and use it in GitHub Desktop.
FFMPEG

UDP streaming

ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0:none" -codec:v libx264 -bsf:v h264_mp4toannexb -f h264 udp://localhost:1234

DASH 3-5 seconds

ffmpeg -y \
    -probesize 42M \
    -rtsp_transport tcp \
    -use_wallclock_as_timestamps 1 \
    -i rtsp://url \
    -c:v libx264 -x264opts keyint=1:min-keyint=1:scenecut=-1 \
    -preset veryfast \
    -tune zerolatency \
    -ldash 1 \
    -seg_duration 0.1 \
    -frag_duration 0.1 \
    -streaming 1 \
    -frag_type every_frame \
    -format_options 'movflags=cmaf' \
    -timeout 0.5 \
    -window_size 30 -remove_at_exit 1 \
    -strict experimental -lhls 1 \
    -hls_playlist 1 -hls_master_name live.m3u8 \
    -utc_timing_url https://time.akamai.com/?iso \
    -write_prft 1 \
    -target_latency 1 \
    /dev/shm/dash/live.mpd

dash.js

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>MPEG-DASH Live Stream</title>
  </head>
  <body>
    <h1>MPEG-DASH Live Stream</h1>
    <script src="/dash.js/dist/dash.all.debug.js"></script>
    <video id="videoPlayer" muted="" style="width: 90%"></video>
    <script>
      (function () {
        var url = "dash/live.mpd";
        var player = dashjs.MediaPlayer().create();
        player.initialize(document.querySelector("#videoPlayer"), url, true);
        player.updateSettings({
          streaming: {
            delay: {
                liveDelayFragmentCount:0,
                liveDelay: 0,
            },
          },
        });
      })();
    </script>
  </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment