Transcript

Video Streaming with NGINX

Introduced by Andrew Alexeev

Presented by Rick Nelson

Nginx IncMay 13, 2014

About this webinar

The demand for Internet Video continues to grow at a fast pace and

from all types of devices. In this webinar, you'll learn about the different

methods for streaming video and how some of the advanced features of

NGINX and NGINX Plus can be used to meet your video streaming

needs.

Video Streaming Methods

File Download

Progressive Download

Pseudo-Streaming

Adaptive Bitrate Streaming

RTMP

The Evolution of HTTP Video Streaming

Pseudo-Streaming

Adaptive Bitrate Streaming

File Download

Progressive Download

File Download

NInternet

Video Server

Content downloaded

to disk

• Playback starts after the download completes

• Download stored on disk

Progressive Download

N

Video Server

Progressive DownloadContent is streamed and played as it is downloaded

META

• Playback starts before download completes

• Meta data at the beginning of the file

• Download stored on disk

• Trick-play and media flow control not easy

• Problematic with low bandwidth connections

Pseudo-Streaming

Video Server

Pseudo-streamingClient can abort stream and request new byte-range

META xx

N

• Adds trick-play to progressive download

• Client can request partial content

• Content can be buffered by player

Adaptive Bitrate Streaming

Video Server

Adaptive StreamingClient downloads manifest, then video chunks of appropriate bitrate

MANIFEST

N

• Data is sent as a continuous stream of small chunks

• Supports trick-play capabilities

• Supports variable bitrates supported

• Easily change bitrates while streaming

• Less buffering on the client

• Better restoration from network interruptions

Adaptive Bitrate Streaming

• HTTP Live Streaming (HLS)– From Apple– Package MP4 encoded file to:

• Playlist (.m3u8)• Segment files (.ts)

• HTTP Dynamic Streaming (HDS)– From Adobe– Package MP4 encoded file to:

• Manifest (.f4m)• Index (.f4x)• Fragment(.f4f)

HLS File Structure

Master Playlist

.mp4.m3u8

Playlist Bitrate 1

.mp4.m3u8

Segment 1 Bitrate 1

.mp4.ts

Segment 2 Bitrate 1

.mp4.ts

Playlist Bitrate 2

.mp4.m3u8

Segment 1 Bitrate 2

.mp4.ts

Segment 2 Bitrate 2

.mp4.ts

HDS File Structure

Master Manifest

.f4m

Manifest Bitrate 1

.f4m

Index Bitrate 1

.f4x

Fragment Bitrate 1

.f4f

Manifest Bitrate 2

.f4m

Index Bitrate 2

.f4x

Fragment Bitrate 2

.f4f

Real Time Messaging Protocol (RTMP)

• TCP-based streaming protocol

• Developed by MacroMedia – Now Adobe

• Live and VOD streaming

• Wide desktop browser support via Flash plugin

• Supported by a variety of software

INTRODUCING NGINX…

What is NGINX?

Internet

N

Web ServerServe content from disk

Application ServerFastCGI, uWSGI, Passenger…

ProxyCaching, Load Balancing… HTTP traffic

Application Acceleration

SSL and SPDY termination

Performance Monitoring

High Availability

Advanced Features: Bandwidth Management

Content-based Routing

Request Manipulation

Response Rewriting

Authentication

Mail Proxy

Geo Location

HLS

HDS

RTMP

MP4/FLV

MP4 Bandwidth

146,000,000Websites

NGINX Accelerates

23%Top 1 million websites

38%Top 1,000 websites

NGINX and NGINX Plus

NGINX F/OSS

nginx.org

3rd party modules

Large community of >100 modules

NGINX and NGINX Plus

NGINX F/OSS

nginx.org

3rd party modules

Large community of >100 modules

NGINX Plus

Advanced load balancing featuresEase-of-managementCommercial support

NGINX Plus

• NGINX Plus builds:

– NGINX Plus

– NGINX Plus Lua

– NGINX Plus Extras

– NGINX Plus Streaming Media Server

VIDEO STREAMING WITH NGINX PLUS

NGINX Plus and HTTP Live Streaming (HLS)

• ngx_http_hls_module

• NGINX creates playlist and segment files on-the-fly

• Allows for existing mp4 files to be served by HLS

• No need to re-package content

• Save time and storage space

location /hls {

hls;

}

Demo: NGINX HLS

NGINX Plus and HTTP Dynamic Streaming (HDS)

• ngx_http_f4f_module• Manifest, index and segment files created by Adobe tools

such as f4fpackager

location /hds {

f4f;

}

Demo: NGINX HDS

NGINX and HTTP Pseudo-Streaming

• ngx_http_mp4_module

• Bandwidth can be controlled (NGINX Plus)

location /video {

mp4;

mp4_limit_rate 1.2;

mp4_limit_rate_after 15s;

}

Demo: NGINX Pseudo-Streaming

NGINX Plus and RTMP Streaming

• nginx-rtmp-module• RTMP live and VOD streaming• Stream transcoding with external software (ffmpeg, avconv)• HTTP callbacks on streaming events• Stream relay: push and pull

All (or some) Of The Above

• Many types of clients

• Many formats (Flash=HDS/RTMP, iPhone=HLS, etc.)

• You will want to support multiple delivery methods

root /tmp/mp4;

location ~ \.mp4$ {

mp4;

}

location ~ \.mp4\.(m3u8|ts)$ {

hls;

}

Session Log Aggregation

• ngx_http_session_log_module• Normal logging: One entry per segment

request– High disk space usage– Excessive disk operations – Difficult to use for billing

• Aggregation: Aggregates multiple requests

Session Log Aggregation

Example: Log sessions based on client IP and user agent. Sessions expires after in 30 seconds.

session_log_zone /var/log/nginx/sessions.log

format=combined zone=one:1m timeout=30s

md5=$binary_remote_addr$http_user_agent;

server {

[..]

location /hds/ {

session_log one;

f4f;

}

}

Demo: NGINX Log Aggregation

Demo: Show configuration file

Review

• There are multiple ways to deliver video

– HLS, HDS, pseudo-streaming, progressive download, RTMP

• You will probably need to support multiple methods

• NGINX Plus makes it easy

Questions and Answers

Closing thoughts

• 38% of the busiest websites use NGINX

• Check out the video streaming articles on nginx.com

• Future webinars: nginx.com/webinars

Try NGINX F/OSS (nginx.org) or NGINX Plus (nginx.com)