Repository

Looks good to me!

User Tools

Site Tools


kb:intranet:services:media:jellyfin:dash

DASH

Dynamic Adaptive Streaming over HTTP, to support streaming over common HTTP ports. This article on streaming protocols by Wowza is a fantastic overview. The more common protocol in use is HLS (HTTP Live Streaming) developed by Apple, as well as RTMP (real-time messaging protocol).

nginx supports this via the RTMP module. Here's a guide for the implementation.

Implementing DASH server

Encoding videos for DASH

Followed this nice little tutorial for DASH. It's marketed towards beginners with a lot of low-level instructions, but here's a summary:

  • Throughout playback, the DASH protocol dynamically selects the highest possible video bitrate so that each individual video segment can be quickly loaded on demand without the user experiencing a lag.
  • Requests are made separately for both audio and video codecs, which are initially listed in an initial manifest.

The required video is first converted into different bitrates and resolutions. I tried my hand using got my money, because I think everyone needs to know this song. The video is first encoded, noting the flags:

  • -s specifies the resolution
  • -c:v specifies the video codec, i.e. h264
  • -b:v specifies the video bitrate
  • -g specifies the keyframe interval (GOP length)
  • -an tells FFMPEG not to encode audio
  • -vn tells FFMPEG not to encode video
ffmpeg -i ".\Got Some Money.webm" -s 160x90 -c:v libx264 -b:v 250k -g 90 -an got_some_money_160x90_250k.mp4
ffmpeg -i ".\Got Some Money.webm" -s 320x180 -c:v libx264 -b:v 500k -g 90 -an got_some_money_320x180_500k.mp4
ffmpeg -i ".\Got Some Money.webm" -s 640x360 -c:v libx264 -b:v 750k -g 90 -an got_some_money_640x360_750k.mp4
ffmpeg -i ".\Got Some Money.webm" -s 640x360 -c:v libx264 -b:v 1000k -g 90 -an got_some_money_640x360_1000k.mp4
ffmpeg -i ".\Got Some Money.webm" -s 1280x720 -c:v libx264 -b:v 1500k -g 90 -an got_some_money_1280x720_1500k.mp4
ffmpeg -i ".\Got Some Money.webm" -vn -c:a aac -b:a 128k got_some_money_audio_128k.mp4

mp4box can then be used to convert them into appropriate DASH formats - precompiled binaries are available in this link. Noting again:

  • -dash specifies the segment length in milliseconds
  • -rap forces the segments to start with random access points, to allow video seeking
  • -profile dashavc264:onDemand specifies the DASH onDemand profile (no idea what this is)
  • -mpd-title sets the manifest title
  • -out sets the manifest filename
  • -frag sets the fragment length in milliseconds
mp4box -dash 5000 -rap -profile dashavc264:onDemand -mpd-title got_some_money -out manifest.mpd -frag 2000 got_some_money_audio_128k.mp4 got_some_money_160x90_250k.mp4 got_some_money_320x180_500k.mp4 ... 

Another DASH reference is the Mozilla documentation for DASH.

CORS

CORS is a necessary pain to deal with. In short, servers hold private information which can be compromised by malicious scripts on other websites (how? what is the exact mechanism? cookies?), so servers need to whitelist sites other than its own for secure access.

Currently my attempts to get the DASH reference player to load my manifest isn't going too great, raising the following error:

ERR_FAILED

Access to XMLHttpRequest at 'http://pyuxiang.com/dash/got_some_money_640x360_750k_dashinit.mp4' from origin 'http://mediapm.edgesuite.net' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

This is despite having the nginx headers, but perhaps I'm missing the rtmp blocks as well as application content types. Not sure if DASH can be performed over HTTPS as well, but it didn't work for HTTP for now.

    location /dash/ {
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Origin' *;
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
        #return 200;
    }
kb/intranet/services/media/jellyfin/dash.txt · Last modified: 18 months ago ( 2 May 2023) by 127.0.0.1