Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

VIDEO IS BIG !

Slide 3

Slide 3 text

ONLINE VIDEO IS DOMINATING

Slide 4

Slide 4 text

OVERTTHETOP

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

PACKAGING

Slide 7

Slide 7 text

HTTP VIDEO PACKAGING FORMATS ✓ HLS ✓ MPEG-DASH ✓ CMAF

Slide 8

Slide 8 text

HTTP LIVE STREAMING (HLS)

Slide 9

Slide 9 text

VIDEO.MP4 STREAM.M3U8 STREAM_01.TS STREAM_02.TS STREAM_03.TS ENCODING & PACKAGING VIDEO: H264 AUDIO: AAC

Slide 10

Slide 10 text

#EXTM3U #EXT-X-VERSION:3 #EXT-X-TARGETDURATION:6 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD #EXTINF:6.000000, stream_00.ts #EXTINF:6.000000, stream_01.ts #EXTINF:6.000000, stream_02.ts #EXTINF:6.000000, stream_03.ts #EXTINF:6.000000, stream_04.ts #EXTINF:6.000000, stream_05.ts #EXTINF:6.000000, stream_06.ts #EXTINF:6.000000, stream_07.ts #EXTINF:6.000000, stream_08.ts #EXTINF:6.000000, stream_09.ts #EXTINF:5.280000, stream_010.ts #EXT-X-ENDLIST STREAM.M3U8

Slide 11

Slide 11 text

PLAYER NEEDS TO SUPPORT HLS

Slide 12

Slide 12 text

Slide 13

Slide 13 text

WHAT TOOL DO WE USE TO ENCODE & PACKAGE?

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

ffmpeg -i video.mp4 \ -c:v libx264 -crf 21 \ -preset veryfast -g 25 -sc_threshold 0 \ -c:a aac -b:a 128k -ac 2 \ -f hls -hls_time 4 -hls_playlist_type vod stream.m3u8

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

HI, I'M THIJS

Slide 18

Slide 18 text

I'M AN EVANGELIST AT

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

+-5,000,000 WEBSITES 20% OF THE TOP 10K WEBSITES

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

I'M @THIJSFERYN

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

CONTENT DELIVERY CHALLENGES

Slide 26

Slide 26 text

HEAVY COMPUTING

Slide 27

Slide 27 text

NETWORK CAPACITY

Slide 28

Slide 28 text

SERVER CAPACITY

Slide 29

Slide 29 text

THROWING SERVERS AT THE PROBLEM

Slide 30

Slide 30 text

MO' MONEY MO' SERVERS MO' PROBLEMS

Slide 31

Slide 31 text

CACHE

Slide 32

Slide 32 text

DON’T RECOMPUTE IF THE DATA HASN’T CHANGED

Slide 33

Slide 33 text

REVERSE CACHING PROXY

Slide 34

Slide 34 text

NORMALLY USER SERVER

Slide 35

Slide 35 text

WITH REVERSE CACHING PROXY USER PROXY SERVER

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

WHY NOT USE A CDN?

Slide 38

Slide 38 text

VARNISH IS CDN SOFTWARE!

Slide 39

Slide 39 text

CDNS WITH MANY POINTS OF PRESENCE WILL DDOS YOUR ORIGIN

Slide 40

Slide 40 text

VARNISH VARNISH VARNISH ORIGIN

Slide 41

Slide 41 text

CDN CDN CDN ORIGIN VARNISH

Slide 42

Slide 42 text

WHY IS VARNISH SO POWERFUL?

Slide 43

Slide 43 text

WHY IS VARNISH SO POWERFUL? ✓ EXTREMELY LOW RESOURCE ✓ EXTREMELY STABLE ✓ 100 GBIT PER SERVER ✓ NO DISK ACCESS AT RUNTIME ✓ REQUEST COALESCING ✓ VARNISH CONFIGURATION LANGUAGE ✓ VMODS ✓ COMPLIES TO HTTP BEST PRACTICES ✓ ENTERPRISE FEATURES*

Slide 44

Slide 44 text

ORIGIN VARNISH REQUEST COALESCING

Slide 45

Slide 45 text

LIVE STREAMING VS VIDEO ON DEMAND

Slide 46

Slide 46 text

LIVE ✓ LOW LATENCY ✓ CONSTANT PLAYLIST UPDATES ✓ LOW TTL ON PLAYLISTS ✓ ONLY THE LAST X SEGMENTS ARE REQUIRED ✓ SEGMENT SIZE TRADEOFF

Slide 47

Slide 47 text

VOD ✓ NO PLAYLIST UPDATES ✓ HIGH TTL ON PLAYLISTS ✓ ALL SEGMENTS ARE REQUIRED ✓ STORAGE REQUIREMENTS ✓ PRE-FETCHING POSSIBLE

Slide 48

Slide 48 text

HEAD VS LONG TAIL HEAD LONG TAIL

Slide 49

Slide 49 text

STORAGE

Slide 50

Slide 50 text

WHERE VARNISH STORES ITS OBJECTS ✓ MEMORY ✓ DISK ✓ MASSIVE STORAGE ENGINE (ENTERPRISE ONLY)

Slide 51

Slide 51 text

MEMORY MEMORY ORIGIN ORIGIN MEMORY MEMORY MEMORY MEMORY MEMORY

Slide 52

Slide 52 text

MEMORY MEMORY ORIGIN ORIGIN DISK DISK DISK

Slide 53

Slide 53 text

ADAPTIVE BITRATE STREAMS

Slide 54

Slide 54 text

STREAM_0.M3U8 STREAM_01.TS STREAM_02.TS STREAM_03.TS STREAM_1.M3U8 STREAM_11.TS STREAM_12.TS STREAM_13.TS MASTER.M3U8 LOW BITRATE HIGH BITRATE ADAPTIVE BITRATE STREAMS

Slide 55

Slide 55 text

#EXTM3U #EXT-X-VERSION:3 #EXT-X-STREAM- INF:BANDWIDTH=1020800,RESOLUTION=1080x1920,CODECS="avc1.640028,mp4a.40.2" stream_0.m3u8 #EXT-X-STREAM- INF:BANDWIDTH=2890800,RESOLUTION=1080x1920,CODECS="avc1.640028,mp4a.40.2" stream_1.m3u8 MASTER.M3U8

Slide 56

Slide 56 text

ffmpeg -i video.mp4 -g 25 -sc_threshold 0 \ -map v:0 -c:v:0 libx264 -b:v:0 800k \ -map v:0 -c:v:1 libx264-b:v:1 2500k \ -map a:0 -c:a aac -b:a 128k -ac 2 \ -f hls -hls_time 6 hls_playlist_type vod \ -master_pl_name master.m3u8 \ -var_stream_map "v:0,a:0 v:1,a:0" stream_%v.m3u8

Slide 57

Slide 57 text

LIVE STREAMING

Slide 58

Slide 58 text

ffmpeg -listen 1 -i rtmp://0.0.0.0/live/stream \ -threads 0 -preset veryfast -g 25 -sc_threshold 0 \ -map v:0 -c:v:0 libx264 -b:v:0 800k \ -map v:0 -c:v:1 libx264 -b:v:1 2500k \ -map a:0 -c:a aac -b:a 128k -ac 2 \ -f hls -hls_time 6 -hls_flags delete_segments \ -hls_list_size 5 -hls_delete_threshold 1 \ -master_pl_name master.m3u8 \ -var_stream_map "v:0,a:0 v:1,a:1" /storage/hls/live/ stream_%v.m3u8

Slide 59

Slide 59 text

FFMPEG WEBSERVER VARNISH RTMP STREAM HLS FILES HTTP HTTP GOPRO

Slide 60

Slide 60 text

DIGITAL RIGHTS MANAGEMENT

Slide 61

Slide 61 text

$ openssl rand 16 > enc.key $ openssl rand -hex 16 230f26620bfafa3cd420cb68c0647415 ENC.KEYINFO /live/enc.key /storage/hls/live/enc.key 230f26620bfafa3cd420cb68c0647415

Slide 62

Slide 62 text

ffmpeg -listen 1 -i rtmp://0.0.0.0/live/stream \ -threads 0 -preset veryfast -g 25 -sc_threshold 0 \ -map v:0 -c:v:0 libx264 -b:v:0 800k \ -map v:0 -c:v:1 libx264 -b:v:1 2500k \ -map a:0 -c:a aac -b:a 128k -ac 2 \ -f hls -hls_time 6 -hls_flags delete_segments \ -hls_list_size 5 -hls_delete_threshold 1 \ -master_pl_name master.m3u8 \ -hls_key_info_file /storage/hls/live/enc.keyinfo \ -var_stream_map "v:0,a:0 v:1,a:1" /storage/hls/live/ stream_%v.m3u8

Slide 63

Slide 63 text

#EXTM3U #EXT-X-VERSION:3 #EXT-X-TARGETDURATION:5 #EXT-X-MEDIA-SEQUENCE:15 #EXT-X-KEY:METHOD=AES-128,URI="/live/ enc.key",IV=0x230f26620bfafa3cd420cb68c0647415 #EXTINF:3.200000, stream_015.ts #EXTINF:4.800000, stream_016.ts #EXTINF:3.200000, stream_017.ts #EXTINF:4.800000, stream_018.ts #EXTINF:1.088000, stream_019.ts #EXT-X-ENDLIST STREAM_0.M3U8 PLAYER SUPPORTS DRM

Slide 64

Slide 64 text

.TS FILES ARE ENCODED AND CAN ONLY BE DECODED BY THE PLAYER

Slide 65

Slide 65 text

ENC.KEY SHOULD BE PROTECTED

Slide 66

Slide 66 text

vcl 4.1; import http; backend default { .host = "1.2.3.4"; .port = "80"; } sub vcl_recv { if(req.url ~ "^/live") { if (req.http.Authorization != "Basic YWRtaW46YWRtaW4=") { return (synth(401, "Restricted")); } } unset req.http.Authorization; } sub vcl_backend_response { if(bereq.url ~ "^/live/stream_[0-9]+\.m3u8$" || bereq.url == "/live/master.m3u8") { set beresp.grace = 0s; set beresp.ttl = 1s; } } sub vcl_synth { if (resp.status == 401) { set resp.http.WWW-Authenticate = {"Basic realm="Restricted area""}; } }

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

VARNISH ENTERPRISE ✓ CLIENT SSL TERMINATION ✓ BACKEND SSL CONNECTIONS ✓ PARALLEL ESI ✓ MASSIVE STORAGE ENGINE ✓ ENCRYPTION ✓ THROTTLING ✓ RATE LIMITING ✓ PREFETCHING ✓ GEOLOCATION ✓ AUTHENTICATION ✓ EDGESTASH ✓ CUSTOM STATISTICS ✓ ADMIN MODULE ✓ SUPPORT ✓ HIGH AVAILABILITY

Slide 69

Slide 69 text

HTTPS://AWS.AMAZON.COM/QUICKSTART/ARCHITECTURE/VARNISH/

Slide 70

Slide 70 text

MASSIVE STORAGE ENGINE

Slide 71

Slide 71 text

MSE ✓ MIX OF MEMORY AND DISK ✓ SMARTER LRU ✓ LESS DISK FRAGMENTATION ✓ INTELLIGENT STORAGE ROUTING ✓ MODULAR

Slide 72

Slide 72 text

MEMORY MEMORY ORIGIN ORIGIN DISK DISK DISK

Slide 73

Slide 73 text

env: { id = "myenv"; memcache_size = "100G"; }; ENVIRONMENT CONFIGURATION

Slide 74

Slide 74 text

env: { id = "myenv"; memcache_size = "100G"; books = ( { id = "book1"; directory = "/var/lib/mse/book1"; database_size = "1G"; stores = ( { id = "store-1-1"; filename = "/var/lib/mse/stores/disk1/store-1-1.dat"; size = "1T"; }, { id = "store-1-2"; filename = "/var/lib/mse/stores/disk2/store-1-2.dat"; size = "1T"; } ); } };

Slide 75

Slide 75 text

HIGH PERFORMANCE HTTP LOGIC BOX

Slide 76

Slide 76 text

NO MORE ORIGIN

Slide 77

Slide 77 text

vcl 4.1; import file; backend default { .host = "origin"; .port = "80"; } sub vcl_init { new root = file.init("/var/www/html/"); } sub vcl_backend_fetch { set bereq.backend = root.backend(); } sub vcl_backend_response { if(bereq.url ~ "^/live/stream_[0-9]+\.m3u8$" || bereq.url == "/live/master.m3u8") { set beresp.grace = 0s; set beresp.ttl = 1s; } }

Slide 78

Slide 78 text

DEVICE DETECTION & BITRATE LIMITATION

Slide 79

Slide 79 text

vcl 4.1; import xbody; include "devicedetect.vcl"; backend default { .host = "origin"; .port = "80"; } sub vcl_recv { call devicedetect; set req.http.X-UA-Device-Prefix = regsub(req.http.X-UA-Device,"(\w+)\-.*","\1"); } sub vcl_backend_response { if(bereq.url == "/live/master.m3u8" ){ set beresp.http.vary = "X-UA-Device-Prefix"; if(bereq.http.X-UA-Device-Prefix == "mobile") { xbody.regsub("\#EXT-X-STREAM-INF:BANDWIDTH=2890800.*\nstream_.*", ""); } } }

Slide 80

Slide 80 text

VIDEO SEGMENT PREFETCHING

Slide 81

Slide 81 text

vcl 4.1; import http; import std; backend default { .host = "origin"; .port = "80"; } sub vcl_recv { if (req.url ~ "^/(live|vod)/.+\.ts$") { http.init(0); http.req_set_max_loops(0,1); http.req_copy_headers(0); http.req_set_method(0, "HEAD"); set req.http.x-next-url = http.prefetch_next_url(); std.log("Prefetching " + req.http.x-next-url); http.req_set_url(0, req.http.x-next-url); http.req_send_and_finish(0); } }

Slide 82

Slide 82 text

THE VMOD ECOSYSTEM HTTPS://VARNISH-CACHE.ORG/VMODS/ HTTPS://DOCS.VARNISH-SOFTWARE.COM/VARNISH-CACHE-PLUS/VMODS/

Slide 83

Slide 83 text

DEMO TIME?

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

HTTPS://FERYN.EU HTTPS://TWITTER.COM/THIJSFERYN HTTPS://INSTAGRAM.COM/THIJSFERYN