savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.4k stars 128 forks source link

Add MPEG-DASH support #887

Open smimram opened 5 years ago

smimram commented 5 years ago

It would be nice to add MPEG-DASH support (both for reading and decoding).

dhannyz commented 5 years ago

Also worth noting is that its possible to re-use chunks for both HLS and DASH, depending on the format. I currently do this with ffmpeg https://ffmpeg.org/ffmpeg-formats.html#dash-2 With the hls_playlist option

*EDIT this is for ENcoding

autonarcosis commented 5 years ago

I think you meant encoding and decoding? As reading and decoding seem to mean the same thing?

There are a lot of issues with DASH and HLS that I've found during testing. Correct time on both the server and client are imperative. It's also important to have the source files being all the same frame rate in both video and audio tracks or you will get desynchronized audio. I still haven't completely cracked this nut yet. It doesn't help that setting the audio frame rate (sample rate) in Liquidsoap has no effect in the AVI output stream. So far I can get about 2-3 hours or about 3-4 tracks before audio desync occurs.

Here is what I have for a 640x480 WebM VP8 / Vorbis DASH stream currently; Caveats all your source files must all be the same frame rates in video and audio. In this example 25fps video and 48khz audio. The -keyin_min, -g, -seg_duration settings and frame rate are interconnected. It's frame rate seg_duration. In this example 256 = 150. So the GOP is 150. 6 seconds is 150 frames. The -utc_timing_url and -use_timeline will need to be set instead of the -use_template option. I believe this is due to Liquidsoap being several seconds ahead of the actual video stream that ffmpeg is outputting. The date.php needs to output something like this;

<?php
header("Cache-Control: no-cache");
$isoDate = date('Y-m-d\TH:i:s') . 'Z';
echo $isoDate
?>

This is the Liquidsoap output setting;

output.external(%avi,"ffmpeg -loglevel info -f avi -r 25 -vsync 1 -ac 2 -i pipe:0 -map 0:0 -c:v libvpx -b:v 500K -deadline realtime 
-quality realtime -cpu-used 5 -keyint_min 150 -g 150 -map 0:1 -c:a libvorbis -b:a 128k -af 'aresample=48000:async=1' -f dash -adapta
tion_sets 'id=0,streams=v id=1,streams=a' -dash_segment_type webm -window_size 6 -use_timeline 1 -use_template 0 -extra_window_size 
1 -seg_duration 6 -remove_at_exit 1 -utc_timing_url https://www.yoursite.com/date.php -init_seg_name 'init-stream$RepresentationI
D$.webm' -media_seg_name 'chunk-stream$RepresentationID$-$Number%05d$.webm' -streaming 1 /home/geoff/public_html/test_live_manifest.
mpd",mksafe(videoplaylist))