SlideShare ist ein Scribd-Unternehmen logo
1 von 97
Mobile Movies with
                     HTTP Live Streaming
                         Chris Adamson • @invalidname
                         December 1, 2012 • Raleigh, NC




                          Sides and code available on my blog:
                             http://www.subfurther.com/blog

Sunday, December 2, 12
So Many Streaming
                              Apps!




Sunday, December 2, 12
So Many Streaming
                              Apps!




Sunday, December 2, 12
Netflix




Sunday, December 2, 12
Flixter




Sunday, December 2, 12
ABC




Sunday, December 2, 12
PBS




Sunday, December 2, 12
NBC Olympics Live
                              Extra




Sunday, December 2, 12
DirecTV




Sunday, December 2, 12
UStream




Sunday, December 2, 12
Crunchyroll




Sunday, December 2, 12
TwitchTV




Sunday, December 2, 12
TwitchTV




Sunday, December 2, 12
iTunes Festival




Sunday, December 2, 12
Apple Events




Sunday, December 2, 12
Oh, and it can be embedded
                     in the <video> tag




Sunday, December 2, 12
Sounds good? How
                         do I get in on that?




Sunday, December 2, 12
What You'll Learn

               • What streaming is (and isn't)

               • Setting up HLS on the server

               • Using HLS streams in iOS apps

               • Real-world deployment




Sunday, December 2, 12
HLS: What It Is (and
                               isn't)




Sunday, December 2, 12
Good Ol' Broadcast




Sunday, December 2, 12
Broadcast Media

               • Always live on some channel (a band of EM
                 spectrum).

               • Every client tuned to that channel sees the
                 same thing, at the same time.

               • One-way, one-to-many model.




Sunday, December 2, 12
Internet
               • Generally one-to-one (host to host).

                    • Multicast IP is an exception, but is rare on
                      the public Internet.

               • Two-way communication over sockets.

               • Routing can take many hops, via multiple
                 transport media (wire, wifi, cellular, etc.).


Sunday, December 2, 12
Impedence Mismatch!




Sunday, December 2, 12
Ye Olde Streaming
               • Client makes socket connection and keeps it
                 open for duration of program.

               • Server sends media at playback speed (plus
                 buffering).

                    • Shoutcast: MP3 files served slowly over HTTP.

               • Typically use a special port number and
                 special server software.


Sunday, December 2, 12
Streaming Problems
               • Difficult and expensive to scale.

               • Special port numbers routinely blocked by
                 businesses, ISPs, firewalls, etc.

               • Competing standards: Real Player, Windows
                 Media, QuickTime (all with their own plugins).

                         • No wonder Flash won.

               • Good luck holding a socket connection on cellular.


Sunday, December 2, 12
What If…
               • We didn't need an always-on socket
                 connection?

               • We could just run over port 80?

               • We could just adopt industry standards like H.
                 264 and AAC instead of cooking custom
                 codecs?



Sunday, December 2, 12
HTTP Live Streaming
               • Serves media as a series of short flat files, via
                 HTTP, usually on port 80.

               • Any web server will do.

               • Client software reassembles the data into a
                 continuous media stream.

               • Spec does not specify contents, but Apple uses
                 H.264 and AAC, just like all their media apps.


Sunday, December 2, 12
Serving up HLS


               • Client URL is an .m3u8 playlist file

               • Playlist points to the media segment files




Sunday, December 2, 12
Sunday, December 2, 12
The HLS playlist
     #EXTM3U
     #EXT-X-TARGETDURATION:10
     #EXT-X-VERSION:3
     #EXT-X-MEDIA-SEQUENCE:0
     #EXT-X-PLAYLIST-TYPE:VOD
     #EXTINF:9.975,!
     fileSequence0.ts
     #EXTINF:9.975,!
     fileSequence1.ts
     #EXTINF:9.975,!
     fileSequence2.ts
     #EXTINF:9.9767,!
     fileSequence3.ts
     #EXTINF:9.975,!

     [...]

     #EXT-X-ENDLIST

Sunday, December 2, 12
The HLS playlist
     #EXTM3U                       Format: .m3u8 format,
     #EXT-X-TARGETDURATION:10
     #EXT-X-VERSION:3
                                   just a list of files to play
     #EXT-X-MEDIA-SEQUENCE:0
     #EXT-X-PLAYLIST-TYPE:VOD
     #EXTINF:9.975,!
     fileSequence0.ts
     #EXTINF:9.975,!
     fileSequence1.ts
     #EXTINF:9.975,!
     fileSequence2.ts
     #EXTINF:9.9767,!
     fileSequence3.ts
     #EXTINF:9.975,!

     [...]

     #EXT-X-ENDLIST

Sunday, December 2, 12
The HLS playlist
     #EXTM3U                       Format: .m3u8 format,
     #EXT-X-TARGETDURATION:10
     #EXT-X-VERSION:3
                                   just a list of files to play
     #EXT-X-MEDIA-SEQUENCE:0
     #EXT-X-PLAYLIST-TYPE:VOD      Metadata tags describe
     #EXTINF:9.975,!
     fileSequence0.ts              the contents
     #EXTINF:9.975,!
     fileSequence1.ts
     #EXTINF:9.975,!
     fileSequence2.ts
     #EXTINF:9.9767,!
     fileSequence3.ts
     #EXTINF:9.975,!

     [...]

     #EXT-X-ENDLIST

Sunday, December 2, 12
The HLS playlist
     #EXTM3U                       Format: .m3u8 format,
     #EXT-X-TARGETDURATION:10
     #EXT-X-VERSION:3
                                   just a list of files to play
     #EXT-X-MEDIA-SEQUENCE:0
     #EXT-X-PLAYLIST-TYPE:VOD      Metadata tags describe
     #EXTINF:9.975,!
     fileSequence0.ts              the contents
     #EXTINF:9.975,!
     fileSequence1.ts
     #EXTINF:9.975,!               Each segment file
     fileSequence2.ts
     #EXTINF:9.9767,!
                                   preceded by metadata
     fileSequence3.ts              (e.g., duration)
     #EXTINF:9.975,!

     [...]

     #EXT-X-ENDLIST

Sunday, December 2, 12
The HLS playlist
     #EXTM3U                       Format: .m3u8 format,
     #EXT-X-TARGETDURATION:10
     #EXT-X-VERSION:3
                                   just a list of files to play
     #EXT-X-MEDIA-SEQUENCE:0
     #EXT-X-PLAYLIST-TYPE:VOD      Metadata tags describe
     #EXTINF:9.975,!
     fileSequence0.ts              the contents
     #EXTINF:9.975,!
     fileSequence1.ts
     #EXTINF:9.975,!               Each segment file
     fileSequence2.ts
     #EXTINF:9.9767,!
                                   preceded by metadata
     fileSequence3.ts              (e.g., duration)
     #EXTINF:9.975,!

     [...]                        If no end tag, client
     #EXT-X-ENDLIST               refreshes periodically
Sunday, December 2, 12
<video src="prog_index.m3u8" width="640" height="480"
                 controls autoplay>No video tag support</video>
Sunday, December 2, 12
How is this better than
                       a flat .m4v file?
               • Streams can provide variants for different
                 bandwidths (as we’ll see…)

               • Segments make it easier to scrub into the
                 video

               • Streams can be live video




Sunday, December 2, 12
The “Live” in HLS
               • A playlist is a live stream if it doesn’t have an
                 #EXT-X-ENDLIST tag

               • Live playlist will generally just contain the last
                 minute or so of segments

               • Client will refresh playlist every minute or so,
                 download whatever segments it doesn’t already
                 have, queue them locally

               • “Live” isn’t really “live” (often a minute behind)

Sunday, December 2, 12
Serving up HLS




Sunday, December 2, 12
Sunday, December 2, 12
Sunday, December 2, 12
Sunday, December 2, 12
Sunday, December 2, 12
Sunday, December 2, 12
mediafilesegmenter
               • Splits an A/V file into segment files, creates
                 the .m3u8 playlist

               • Source must be .mov or .m4v with H.264 video,
                 AAC audio

               • Output segments will be MPEG-2 Transport Stream
                 (.ts) files, or .aac if audio-only

               • Segment paths are relative, use -b to prepend URL
                 stub


Sunday, December 2, 12
Technical Note TN2224
       The following audio and video formats are supported:

       • Video: H.264 Baseline Profile Level 3.0 (iPhone/iPod Touch),
         Main Profile Level 3.1 (iPad 1,2)

       • Audio: HE-AAC or AAC-LC up to 48 kHz, stereo audio OR
         MP3 (MPEG-1 Audio Layer 3) 8 kHz to 48 kHz, stereo audio

       Note: iPhone 3G supports Baseline Profile Level 3.1. If your
       app runs on older iPhones, however, you should use H.264
       Baseline Profile 3.0 for compatibility.


Sunday, December 2, 12
Yuna:HTTP Live Streaming tests cadamson$ mediafilesegmenter
           -f basic source/IMG_0251.MOV
           Jun 24 2012 10:01:24.203: Using floating point is not
           backward compatible to iOS 4.1 or earlier devices
           Jun 24 2012 10:01:24.204: Processing file /Users/cadamson/
           Documents/HTTP Live Streaming tests/source/IMG_0251.MOV
           Jun 24 2012 10:01:24.338: Finalized /Users/cadamson/
           Documents/HTTP Live Streaming tests/basic/fileSequence0.ts
           Jun 24 2012 10:01:24.375: segment bitrate 3.78028e+06 is
           new max
           Jun 24 2012 10:01:24.468: Finalized /Users/cadamson/
           Documents/HTTP Live Streaming tests/basic/fileSequence1.ts
           Jun 24 2012 10:01:24.554: Finalized /Users/cadamson/
           Documents/HTTP Live Streaming tests/basic/fileSequence2.ts
           Jun 24 2012 10:01:24.631: Finalized /Users/cadamson/
           Documents/HTTP Live Streaming tests/basic/fileSequence3.ts
           Jun 24 2012 10:01:24.717: Finalized /Users/cadamson/
           Documents/HTTP Live Streaming tests/basic/fileSequence4.ts




Sunday, December 2, 12
Demo




Sunday, December 2, 12
Variant Playlists
               • One bitrate does not fit all: Mac on Ethernet
                 versus iPhone on Edge.

               • Solution: encode your video at multiple bitrates,
                 offer metadata in playlist about what's
                 available, let client figure out which to use.

               • HLS clients automatically switch to best variant
                 for current network conditions, switch on the fly.



Sunday, December 2, 12
variantplaylistcreator
               • Creates a playlist that itself points to playlists
                 created with mediafilesegmenter.

                    • Each entry contains metadata describing the
                      bitrate and encoding of the variant.

               • Tool takes argument pairs: file or URL of a
                 variant .m3u8, and metadata .plist created with
                 mediafilesegmenter -I flag

               • First entry in variant playlist is default; client will try
                 this one first

Sunday, December 2, 12
Encoding the variants




Sunday, December 2, 12
TN2224
                         Recommendations




Sunday, December 2, 12
Creating variants
           Yuna:HTTP Live Streaming tests cadamson$
           mediafilesegmenter -I -f variants/
           broadband/ source/IMG_0254_Broadband.m4v

           Yuna:HTTP Live Streaming tests cadamson$
           mediafilesegmenter -I -f variants/wifi
           source/IMG_0254_WiFi.m4v

           Yuna:HTTP Live Streaming tests cadamson$
           mediafilesegmenter -I -f variants/
           cellular source/IMG_0254_Cellular.m4v


Sunday, December 2, 12
Creating variant playlist
         Yuna:HTTP Live Streaming tests cadamson$
         variantplaylistcreator -o variants/
         variants.m3u8 variants/broadband/
         prog_index.m3u8 source/
         IMG_0254_Broadband.plist variants/wifi/
         prog_index.m3u8 source/
         IMG_0254_WiFi.plist variants/cellular/
         prog_index.m3u8 source/
         IMG_0254_Cellular.plist



Sunday, December 2, 12
Demo




Sunday, December 2, 12
That's Great, but…
                         How do we keep people from stealing our stream?




Sunday, December 2, 12
Encryption
               • HLS encrypts files, not transport.

               • Easy to scale: still serving flat files, but now
                 they're useless without decryption keys.

               • Serving the keys still needs to be secure.

               • Necessary, but not sufficient, for DRM.



Sunday, December 2, 12
Encrypting a playlist
    Yuna:HTTP Live Streaming tests cadamson$ mediafilesegmenter -
    I -k keys -f encrypted/cellular source/IMG_0426_Cellular.m4v
    Jun 24 2012 18:59:47.115: Using new key/iv rotation period;
    this is not backward compatible to iOS 3.1.* or earlier
    devices.  Use the "-encrypt-iv=sequence" option for
    compatibility with those devices.
    Jun 24 2012 18:59:47.115: Using floating point is not
    backward compatible to iOS 4.1 or earlier devices
    Jun 24 2012 18:59:47.115: Processing file /Users/cadamson/
    Documents/HTTP Live Streaming tests/source/
    IMG_0426_Cellular.m4v
    Jun 24 2012 18:59:47.152: changing IV
    Jun 24 2012 18:59:47.160: Finalized /Users/cadamson/
    Documents/HTTP Live Streaming tests/encrypted/cellular/
    fileSequence0.ts
    Jun 24 2012 18:59:47.160: segment bitrate 271257 is new max


Sunday, December 2, 12
Encrypted .ts files




Sunday, December 2, 12
Encrypted .ts files




Sunday, December 2, 12
Encrypted .ts files




Sunday, December 2, 12
Encrypted .ts files




Sunday, December 2, 12
Protect those keys




                         /www/protected


                                          /www/hls



Sunday, December 2, 12
Demo




Sunday, December 2, 12
Client-side HLS




Sunday, December 2, 12
Opening an HLS
                            stream

               • Provide the .m3u8 URL to
                 MPMoviePlayerController or AVPlayer

               • Add the movie view or layer to your UI,
                 customizing size or scaling if necessary




Sunday, December 2, 12
Create an
               MPMoviePlayerController

     // create new movie player
     self.moviePlayer = [[MPMoviePlayerController alloc]
     ! ! ! ! ! ! ! ! initWithContentURL:streamURL];
     [self.moviePlayer prepareToPlay];



               • This is the same as playing a local file or any
                 other URL


Sunday, December 2, 12
Add it to your UI

          [self.moviePlayer.view setFrame:
          ! ! ! ! ! ! ! self.movieContainerView.bounds];
          [self.movieContainerView addSubview:
          ! ! ! ! ! ! ! ! self.moviePlayer.view];
          self.moviePlayer.scalingMode =
          ! ! ! ! ! ! ! ! MPMovieScalingModeFill;


               • Can inspect the moviePlayer's naturalSize, though it
                 may change during playback (listen for
                 MPMovieNaturalSizeAvailableNotification), or
                 just setFullscreen:animated:

Sunday, December 2, 12
MPMovieScalingMode
                       AspectFit




Sunday, December 2, 12
MPMovieScalingMode
                       AspectFill




Sunday, December 2, 12
MPMovieScalingMode 
                          Fill




Sunday, December 2, 12
Accessing Encrypted
                              Streams
               • Media Player and AV Foundation can use
                 NSURLCredentials that you've provided

               • Place credentials in NSURLCredentialStorage

               • Server can provide the keys securely(*) with
                 HTTP Basic or Digest authentication, an
                 HTTPS script, etc.

                           * - For various values of "secure"

Sunday, December 2, 12
Setting credentials (1)

       NSURLProtectionSpace *protectionSpace =
       ! [[NSURLProtectionSpace alloc]
       ! ! initWithHost:host
       ! ! port:port
       ! ! protocol:protocol
       ! ! realm:realm
       ! ! authenticationMethod:
       ! ! ! NSURLAuthenticationMethodDefault];




Sunday, December 2, 12
Setting credentials (2)

          NSURLCredential *credential =
          ! [NSURLCredential credentialWithUser:username
          ! ! ! ! ! ! ! ! !         password:password
          ! ! ! ! ! ! ! ! ! ! ! persistence:
          ! ! ! NSURLCredentialPersistenceForSession];

          [[NSURLCredentialStorage
          ! sharedCredentialStorage]
          ! ! setDefaultCredential:credential
          ! !    forProtectionSpace:protectionSpace];



Sunday, December 2, 12
Live Streaming




Sunday, December 2, 12
Live Streaming
               • mediastreamsegmenter mostly works like the
                 file version, but takes its input from UDP stream
                 or a Unix pipe

                    • Only difference is that .m3u8 file doesn't have
                      an EXT-X-ENDLIST tag, so client reloads
                      periodically to fetch new segments

               • How the heck do you create a UDP A/V
                 stream?


Sunday, December 2, 12
You Don't


               • None of Apple's tools create the required
                 stream

                    • This is a "third party opportunity"

                    • Which begs the question… buy or build?


Sunday, December 2, 12
Streaming in the Real
                           World
                         It's not all about iPhones…




Sunday, December 2, 12
Streaming Clients
               • Mobile Devices: iPhone, iPad, iPod Touch…
                 plus Android, Windows Mobile, etc.

               • Mac and Windows PCs

               • Over-the-top (OTT) boxes: Apple TV, Roku

               • Game consoles



Sunday, December 2, 12
Let's Get Practical

               • What devices do you have to be on?

               • What devices will you get for free?

               • How to encode and deliver to the devices you
                 need?




Sunday, December 2, 12
HLS Alternatives
               • Flash still rules on the desktop/browser
                 space, thanks in part to Mozilla's obstinance
                 about H.264 in <video> (irony alert: H.264 is
                 the de facto standard for Flash video)

               • Adobe Dynamic Streaming and Microsoft
                 Smooth Streaming are highly similar to HLS:
                 bitrate-adaptive streams over HTTP



Sunday, December 2, 12
MPEG-DASH
               • Attempt at a standardized approach to HTTP
                 adaptive-bitrate streaming. ISO/IEC 23009-1.




                            http://xkcd.com/927/
Sunday, December 2, 12
Emerging Consensus

               • Flash for PCs

               • HTTP Live Streaming for iOS

               • Plus whatever other devices you need to
                 support




Sunday, December 2, 12
Real-World HLS

               • Can you competently encode all your media
                 at all the variant bitrates you need?

               • Do you have a way to QC all your streams?

               • Can you handle the server load?




Sunday, December 2, 12
Build or Buy: Services
               • Provide hosting, transcoding, bandwidth

                    • All-in-one: UStream, LiveStream, Justin.tv /
                      Twitch.tv (all of which have iOS apps)

                    • May provide broadcast tools (Flash applet,
                      Telestream Wirecast, etc.

                    • Often free with ads; you pay to go ad-free,
                      embed on your site, etc.


Sunday, December 2, 12
invalidstream




                     http://www.ustream.tv/channel/invalidstream

Sunday, December 2, 12
Production Demo




                         http://www.telestream.net/wirecast/
Sunday, December 2, 12
Content Delivery
                            Networks




        http://en.wikipedia.org/wiki/Content_delivery_network
Sunday, December 2, 12
Content Delivery
                            Networks
               • CDNs host your media on edge servers that are
                 closer to your clients. Less strain on your
                 servers and the backbones.

               • Examples: Akamai, Limelight, EdgeCast

               • Big media companies may have their own CDN

               • Most already know how to do HLS



Sunday, December 2, 12
Buy or Build: Encoders




Sunday, December 2, 12
Buy or Build:
                           Bandwidth

               • Each HLS client will consume up to 1GB /
                 hour, depending on variant bitrates, client
                 bandwidth, etc.

               • Many CDNs charge around $0.20/GB.




Sunday, December 2, 12
Bandwidth Costs




                  Prices from ScaleEngine, UStream, and LiveStream as of
                                      October 2012
Sunday, December 2, 12
Bandwidth Costs




                  Prices from ScaleEngine, UStream, and LiveStream as of
                                      October 2012
Sunday, December 2, 12
Bandwidth Costs




                  Prices from ScaleEngine, UStream, and LiveStream as of
                                      October 2012
Sunday, December 2, 12
Bandwidth Costs




                  Prices from ScaleEngine, UStream, and LiveStream as of
                                      October 2012
Sunday, December 2, 12
Wrap Up




Sunday, December 2, 12
Takeaways
               • HLS is a very practical streaming solution

               • Only part of the picture if you're multi-platform

               • Encoding and serving correctly requires some
                 care and expertise, and a lot of money

               • Client-side software requirements are fairly
                 simple


Sunday, December 2, 12
Q&A
                         Slides and code will be available on my blog:
                                 http://www.subfurther.com/blog
                             http://www.slideshare.net/invalidname

                                        @invalidname




Sunday, December 2, 12

Weitere ähnliche Inhalte

Mehr von Chris Adamson

Forward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is FineForward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is FineChris Adamson
 
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...Chris Adamson
 
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)Chris Adamson
 
Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)Chris Adamson
 
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)Chris Adamson
 
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)Chris Adamson
 
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)Chris Adamson
 
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...Chris Adamson
 
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Chris Adamson
 
Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks, CocoaConf Seattle 2014Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks, CocoaConf Seattle 2014Chris Adamson
 
Stupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Las VegasStupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Las VegasChris Adamson
 
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Chris Adamson
 
Stupid Video Tricks (CocoaConf DC, March 2014)
Stupid Video Tricks (CocoaConf DC, March 2014)Stupid Video Tricks (CocoaConf DC, March 2014)
Stupid Video Tricks (CocoaConf DC, March 2014)Chris Adamson
 
Introduction to the Roku SDK
Introduction to the Roku SDKIntroduction to the Roku SDK
Introduction to the Roku SDKChris Adamson
 
Get On The Audiobus (CocoaConf Atlanta, November 2013)
Get On The Audiobus (CocoaConf Atlanta, November 2013)Get On The Audiobus (CocoaConf Atlanta, November 2013)
Get On The Audiobus (CocoaConf Atlanta, November 2013)Chris Adamson
 
Get On The Audiobus (CocoaConf Boston, October 2013)
Get On The Audiobus (CocoaConf Boston, October 2013)Get On The Audiobus (CocoaConf Boston, October 2013)
Get On The Audiobus (CocoaConf Boston, October 2013)Chris Adamson
 
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)Chris Adamson
 
iOS Media APIs (MobiDevDay Detroit, May 2013)
iOS Media APIs (MobiDevDay Detroit, May 2013)iOS Media APIs (MobiDevDay Detroit, May 2013)
iOS Media APIs (MobiDevDay Detroit, May 2013)Chris Adamson
 
Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Core Audio in iOS 6 (CocoaConf San Jose, April 2013) Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Core Audio in iOS 6 (CocoaConf San Jose, April 2013) Chris Adamson
 

Mehr von Chris Adamson (20)

Forward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is FineForward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
 
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
Firebase: Totally Not Parse All Over Again (Unless It Is) (CocoaConf San Jose...
 
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
Building A Streaming Apple TV App (CocoaConf San Jose, Nov 2016)
 
Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)Firebase: Totally Not Parse All Over Again (Unless It Is)
Firebase: Totally Not Parse All Over Again (Unless It Is)
 
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
Building A Streaming Apple TV App (CocoaConf DC, Sept 2016)
 
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
Video Killed the Rolex Star (CocoaConf San Jose, November, 2015)
 
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
Video Killed the Rolex Star (CocoaConf Columbus, July 2015)
 
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
Revenge of the 80s: Cut/Copy/Paste, Undo/Redo, and More Big Hits (CocoaConf C...
 
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
 
Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks, CocoaConf Seattle 2014Stupid Video Tricks, CocoaConf Seattle 2014
Stupid Video Tricks, CocoaConf Seattle 2014
 
Stupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Las VegasStupid Video Tricks, CocoaConf Las Vegas
Stupid Video Tricks, CocoaConf Las Vegas
 
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
 
Stupid Video Tricks (CocoaConf DC, March 2014)
Stupid Video Tricks (CocoaConf DC, March 2014)Stupid Video Tricks (CocoaConf DC, March 2014)
Stupid Video Tricks (CocoaConf DC, March 2014)
 
Stupid Video Tricks
Stupid Video TricksStupid Video Tricks
Stupid Video Tricks
 
Introduction to the Roku SDK
Introduction to the Roku SDKIntroduction to the Roku SDK
Introduction to the Roku SDK
 
Get On The Audiobus (CocoaConf Atlanta, November 2013)
Get On The Audiobus (CocoaConf Atlanta, November 2013)Get On The Audiobus (CocoaConf Atlanta, November 2013)
Get On The Audiobus (CocoaConf Atlanta, November 2013)
 
Get On The Audiobus (CocoaConf Boston, October 2013)
Get On The Audiobus (CocoaConf Boston, October 2013)Get On The Audiobus (CocoaConf Boston, October 2013)
Get On The Audiobus (CocoaConf Boston, October 2013)
 
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)
Glitch-Free A/V Encoding (CocoaConf Boston, October 2013)
 
iOS Media APIs (MobiDevDay Detroit, May 2013)
iOS Media APIs (MobiDevDay Detroit, May 2013)iOS Media APIs (MobiDevDay Detroit, May 2013)
iOS Media APIs (MobiDevDay Detroit, May 2013)
 
Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Core Audio in iOS 6 (CocoaConf San Jose, April 2013) Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
Core Audio in iOS 6 (CocoaConf San Jose, April 2013)
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Kürzlich hochgeladen (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Mobile Movies with HTTP Live Streaming (CocoaConf Raleigh, Dec. '12)

  • 1. Mobile Movies with HTTP Live Streaming Chris Adamson • @invalidname December 1, 2012 • Raleigh, NC Sides and code available on my blog: http://www.subfurther.com/blog Sunday, December 2, 12
  • 2. So Many Streaming Apps! Sunday, December 2, 12
  • 3. So Many Streaming Apps! Sunday, December 2, 12
  • 8. NBC Olympics Live Extra Sunday, December 2, 12
  • 16. Oh, and it can be embedded in the <video> tag Sunday, December 2, 12
  • 17. Sounds good? How do I get in on that? Sunday, December 2, 12
  • 18. What You'll Learn • What streaming is (and isn't) • Setting up HLS on the server • Using HLS streams in iOS apps • Real-world deployment Sunday, December 2, 12
  • 19. HLS: What It Is (and isn't) Sunday, December 2, 12
  • 20. Good Ol' Broadcast Sunday, December 2, 12
  • 21. Broadcast Media • Always live on some channel (a band of EM spectrum). • Every client tuned to that channel sees the same thing, at the same time. • One-way, one-to-many model. Sunday, December 2, 12
  • 22. Internet • Generally one-to-one (host to host). • Multicast IP is an exception, but is rare on the public Internet. • Two-way communication over sockets. • Routing can take many hops, via multiple transport media (wire, wifi, cellular, etc.). Sunday, December 2, 12
  • 24. Ye Olde Streaming • Client makes socket connection and keeps it open for duration of program. • Server sends media at playback speed (plus buffering). • Shoutcast: MP3 files served slowly over HTTP. • Typically use a special port number and special server software. Sunday, December 2, 12
  • 25. Streaming Problems • Difficult and expensive to scale. • Special port numbers routinely blocked by businesses, ISPs, firewalls, etc. • Competing standards: Real Player, Windows Media, QuickTime (all with their own plugins). • No wonder Flash won. • Good luck holding a socket connection on cellular. Sunday, December 2, 12
  • 26. What If… • We didn't need an always-on socket connection? • We could just run over port 80? • We could just adopt industry standards like H. 264 and AAC instead of cooking custom codecs? Sunday, December 2, 12
  • 27. HTTP Live Streaming • Serves media as a series of short flat files, via HTTP, usually on port 80. • Any web server will do. • Client software reassembles the data into a continuous media stream. • Spec does not specify contents, but Apple uses H.264 and AAC, just like all their media apps. Sunday, December 2, 12
  • 28. Serving up HLS • Client URL is an .m3u8 playlist file • Playlist points to the media segment files Sunday, December 2, 12
  • 30. The HLS playlist #EXTM3U #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD #EXTINF:9.975,! fileSequence0.ts #EXTINF:9.975,! fileSequence1.ts #EXTINF:9.975,! fileSequence2.ts #EXTINF:9.9767,! fileSequence3.ts #EXTINF:9.975,! [...] #EXT-X-ENDLIST Sunday, December 2, 12
  • 31. The HLS playlist #EXTM3U Format: .m3u8 format, #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:3 just a list of files to play #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD #EXTINF:9.975,! fileSequence0.ts #EXTINF:9.975,! fileSequence1.ts #EXTINF:9.975,! fileSequence2.ts #EXTINF:9.9767,! fileSequence3.ts #EXTINF:9.975,! [...] #EXT-X-ENDLIST Sunday, December 2, 12
  • 32. The HLS playlist #EXTM3U Format: .m3u8 format, #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:3 just a list of files to play #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD Metadata tags describe #EXTINF:9.975,! fileSequence0.ts the contents #EXTINF:9.975,! fileSequence1.ts #EXTINF:9.975,! fileSequence2.ts #EXTINF:9.9767,! fileSequence3.ts #EXTINF:9.975,! [...] #EXT-X-ENDLIST Sunday, December 2, 12
  • 33. The HLS playlist #EXTM3U Format: .m3u8 format, #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:3 just a list of files to play #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD Metadata tags describe #EXTINF:9.975,! fileSequence0.ts the contents #EXTINF:9.975,! fileSequence1.ts #EXTINF:9.975,! Each segment file fileSequence2.ts #EXTINF:9.9767,! preceded by metadata fileSequence3.ts (e.g., duration) #EXTINF:9.975,! [...] #EXT-X-ENDLIST Sunday, December 2, 12
  • 34. The HLS playlist #EXTM3U Format: .m3u8 format, #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:3 just a list of files to play #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD Metadata tags describe #EXTINF:9.975,! fileSequence0.ts the contents #EXTINF:9.975,! fileSequence1.ts #EXTINF:9.975,! Each segment file fileSequence2.ts #EXTINF:9.9767,! preceded by metadata fileSequence3.ts (e.g., duration) #EXTINF:9.975,! [...] If no end tag, client #EXT-X-ENDLIST refreshes periodically Sunday, December 2, 12
  • 35. <video src="prog_index.m3u8" width="640" height="480" controls autoplay>No video tag support</video> Sunday, December 2, 12
  • 36. How is this better than a flat .m4v file? • Streams can provide variants for different bandwidths (as we’ll see…) • Segments make it easier to scrub into the video • Streams can be live video Sunday, December 2, 12
  • 37. The “Live” in HLS • A playlist is a live stream if it doesn’t have an #EXT-X-ENDLIST tag • Live playlist will generally just contain the last minute or so of segments • Client will refresh playlist every minute or so, download whatever segments it doesn’t already have, queue them locally • “Live” isn’t really “live” (often a minute behind) Sunday, December 2, 12
  • 38. Serving up HLS Sunday, December 2, 12
  • 44. mediafilesegmenter • Splits an A/V file into segment files, creates the .m3u8 playlist • Source must be .mov or .m4v with H.264 video, AAC audio • Output segments will be MPEG-2 Transport Stream (.ts) files, or .aac if audio-only • Segment paths are relative, use -b to prepend URL stub Sunday, December 2, 12
  • 45. Technical Note TN2224 The following audio and video formats are supported: • Video: H.264 Baseline Profile Level 3.0 (iPhone/iPod Touch), Main Profile Level 3.1 (iPad 1,2) • Audio: HE-AAC or AAC-LC up to 48 kHz, stereo audio OR MP3 (MPEG-1 Audio Layer 3) 8 kHz to 48 kHz, stereo audio Note: iPhone 3G supports Baseline Profile Level 3.1. If your app runs on older iPhones, however, you should use H.264 Baseline Profile 3.0 for compatibility. Sunday, December 2, 12
  • 46. Yuna:HTTP Live Streaming tests cadamson$ mediafilesegmenter -f basic source/IMG_0251.MOV Jun 24 2012 10:01:24.203: Using floating point is not backward compatible to iOS 4.1 or earlier devices Jun 24 2012 10:01:24.204: Processing file /Users/cadamson/ Documents/HTTP Live Streaming tests/source/IMG_0251.MOV Jun 24 2012 10:01:24.338: Finalized /Users/cadamson/ Documents/HTTP Live Streaming tests/basic/fileSequence0.ts Jun 24 2012 10:01:24.375: segment bitrate 3.78028e+06 is new max Jun 24 2012 10:01:24.468: Finalized /Users/cadamson/ Documents/HTTP Live Streaming tests/basic/fileSequence1.ts Jun 24 2012 10:01:24.554: Finalized /Users/cadamson/ Documents/HTTP Live Streaming tests/basic/fileSequence2.ts Jun 24 2012 10:01:24.631: Finalized /Users/cadamson/ Documents/HTTP Live Streaming tests/basic/fileSequence3.ts Jun 24 2012 10:01:24.717: Finalized /Users/cadamson/ Documents/HTTP Live Streaming tests/basic/fileSequence4.ts Sunday, December 2, 12
  • 48. Variant Playlists • One bitrate does not fit all: Mac on Ethernet versus iPhone on Edge. • Solution: encode your video at multiple bitrates, offer metadata in playlist about what's available, let client figure out which to use. • HLS clients automatically switch to best variant for current network conditions, switch on the fly. Sunday, December 2, 12
  • 49. variantplaylistcreator • Creates a playlist that itself points to playlists created with mediafilesegmenter. • Each entry contains metadata describing the bitrate and encoding of the variant. • Tool takes argument pairs: file or URL of a variant .m3u8, and metadata .plist created with mediafilesegmenter -I flag • First entry in variant playlist is default; client will try this one first Sunday, December 2, 12
  • 51. TN2224 Recommendations Sunday, December 2, 12
  • 52. Creating variants Yuna:HTTP Live Streaming tests cadamson$ mediafilesegmenter -I -f variants/ broadband/ source/IMG_0254_Broadband.m4v Yuna:HTTP Live Streaming tests cadamson$ mediafilesegmenter -I -f variants/wifi source/IMG_0254_WiFi.m4v Yuna:HTTP Live Streaming tests cadamson$ mediafilesegmenter -I -f variants/ cellular source/IMG_0254_Cellular.m4v Sunday, December 2, 12
  • 53. Creating variant playlist Yuna:HTTP Live Streaming tests cadamson$ variantplaylistcreator -o variants/ variants.m3u8 variants/broadband/ prog_index.m3u8 source/ IMG_0254_Broadband.plist variants/wifi/ prog_index.m3u8 source/ IMG_0254_WiFi.plist variants/cellular/ prog_index.m3u8 source/ IMG_0254_Cellular.plist Sunday, December 2, 12
  • 55. That's Great, but… How do we keep people from stealing our stream? Sunday, December 2, 12
  • 56. Encryption • HLS encrypts files, not transport. • Easy to scale: still serving flat files, but now they're useless without decryption keys. • Serving the keys still needs to be secure. • Necessary, but not sufficient, for DRM. Sunday, December 2, 12
  • 57. Encrypting a playlist Yuna:HTTP Live Streaming tests cadamson$ mediafilesegmenter - I -k keys -f encrypted/cellular source/IMG_0426_Cellular.m4v Jun 24 2012 18:59:47.115: Using new key/iv rotation period; this is not backward compatible to iOS 3.1.* or earlier devices.  Use the "-encrypt-iv=sequence" option for compatibility with those devices. Jun 24 2012 18:59:47.115: Using floating point is not backward compatible to iOS 4.1 or earlier devices Jun 24 2012 18:59:47.115: Processing file /Users/cadamson/ Documents/HTTP Live Streaming tests/source/ IMG_0426_Cellular.m4v Jun 24 2012 18:59:47.152: changing IV Jun 24 2012 18:59:47.160: Finalized /Users/cadamson/ Documents/HTTP Live Streaming tests/encrypted/cellular/ fileSequence0.ts Jun 24 2012 18:59:47.160: segment bitrate 271257 is new max Sunday, December 2, 12
  • 62. Protect those keys /www/protected /www/hls Sunday, December 2, 12
  • 65. Opening an HLS stream • Provide the .m3u8 URL to MPMoviePlayerController or AVPlayer • Add the movie view or layer to your UI, customizing size or scaling if necessary Sunday, December 2, 12
  • 66. Create an MPMoviePlayerController // create new movie player self.moviePlayer = [[MPMoviePlayerController alloc] ! ! ! ! ! ! ! ! initWithContentURL:streamURL]; [self.moviePlayer prepareToPlay]; • This is the same as playing a local file or any other URL Sunday, December 2, 12
  • 67. Add it to your UI [self.moviePlayer.view setFrame: ! ! ! ! ! ! ! self.movieContainerView.bounds]; [self.movieContainerView addSubview: ! ! ! ! ! ! ! ! self.moviePlayer.view]; self.moviePlayer.scalingMode = ! ! ! ! ! ! ! ! MPMovieScalingModeFill; • Can inspect the moviePlayer's naturalSize, though it may change during playback (listen for MPMovieNaturalSizeAvailableNotification), or just setFullscreen:animated: Sunday, December 2, 12
  • 68. MPMovieScalingMode AspectFit Sunday, December 2, 12
  • 69. MPMovieScalingMode AspectFill Sunday, December 2, 12
  • 70. MPMovieScalingMode  Fill Sunday, December 2, 12
  • 71. Accessing Encrypted Streams • Media Player and AV Foundation can use NSURLCredentials that you've provided • Place credentials in NSURLCredentialStorage • Server can provide the keys securely(*) with HTTP Basic or Digest authentication, an HTTPS script, etc. * - For various values of "secure" Sunday, December 2, 12
  • 72. Setting credentials (1) NSURLProtectionSpace *protectionSpace = ! [[NSURLProtectionSpace alloc] ! ! initWithHost:host ! ! port:port ! ! protocol:protocol ! ! realm:realm ! ! authenticationMethod: ! ! ! NSURLAuthenticationMethodDefault]; Sunday, December 2, 12
  • 73. Setting credentials (2) NSURLCredential *credential = ! [NSURLCredential credentialWithUser:username ! ! ! ! ! ! ! ! !         password:password ! ! ! ! ! ! ! ! ! ! ! persistence: ! ! ! NSURLCredentialPersistenceForSession]; [[NSURLCredentialStorage ! sharedCredentialStorage] ! ! setDefaultCredential:credential ! ! forProtectionSpace:protectionSpace]; Sunday, December 2, 12
  • 75. Live Streaming • mediastreamsegmenter mostly works like the file version, but takes its input from UDP stream or a Unix pipe • Only difference is that .m3u8 file doesn't have an EXT-X-ENDLIST tag, so client reloads periodically to fetch new segments • How the heck do you create a UDP A/V stream? Sunday, December 2, 12
  • 76. You Don't • None of Apple's tools create the required stream • This is a "third party opportunity" • Which begs the question… buy or build? Sunday, December 2, 12
  • 77. Streaming in the Real World It's not all about iPhones… Sunday, December 2, 12
  • 78. Streaming Clients • Mobile Devices: iPhone, iPad, iPod Touch… plus Android, Windows Mobile, etc. • Mac and Windows PCs • Over-the-top (OTT) boxes: Apple TV, Roku • Game consoles Sunday, December 2, 12
  • 79. Let's Get Practical • What devices do you have to be on? • What devices will you get for free? • How to encode and deliver to the devices you need? Sunday, December 2, 12
  • 80. HLS Alternatives • Flash still rules on the desktop/browser space, thanks in part to Mozilla's obstinance about H.264 in <video> (irony alert: H.264 is the de facto standard for Flash video) • Adobe Dynamic Streaming and Microsoft Smooth Streaming are highly similar to HLS: bitrate-adaptive streams over HTTP Sunday, December 2, 12
  • 81. MPEG-DASH • Attempt at a standardized approach to HTTP adaptive-bitrate streaming. ISO/IEC 23009-1. http://xkcd.com/927/ Sunday, December 2, 12
  • 82. Emerging Consensus • Flash for PCs • HTTP Live Streaming for iOS • Plus whatever other devices you need to support Sunday, December 2, 12
  • 83. Real-World HLS • Can you competently encode all your media at all the variant bitrates you need? • Do you have a way to QC all your streams? • Can you handle the server load? Sunday, December 2, 12
  • 84. Build or Buy: Services • Provide hosting, transcoding, bandwidth • All-in-one: UStream, LiveStream, Justin.tv / Twitch.tv (all of which have iOS apps) • May provide broadcast tools (Flash applet, Telestream Wirecast, etc. • Often free with ads; you pay to go ad-free, embed on your site, etc. Sunday, December 2, 12
  • 85. invalidstream http://www.ustream.tv/channel/invalidstream Sunday, December 2, 12
  • 86. Production Demo http://www.telestream.net/wirecast/ Sunday, December 2, 12
  • 87. Content Delivery Networks http://en.wikipedia.org/wiki/Content_delivery_network Sunday, December 2, 12
  • 88. Content Delivery Networks • CDNs host your media on edge servers that are closer to your clients. Less strain on your servers and the backbones. • Examples: Akamai, Limelight, EdgeCast • Big media companies may have their own CDN • Most already know how to do HLS Sunday, December 2, 12
  • 89. Buy or Build: Encoders Sunday, December 2, 12
  • 90. Buy or Build: Bandwidth • Each HLS client will consume up to 1GB / hour, depending on variant bitrates, client bandwidth, etc. • Many CDNs charge around $0.20/GB. Sunday, December 2, 12
  • 91. Bandwidth Costs Prices from ScaleEngine, UStream, and LiveStream as of October 2012 Sunday, December 2, 12
  • 92. Bandwidth Costs Prices from ScaleEngine, UStream, and LiveStream as of October 2012 Sunday, December 2, 12
  • 93. Bandwidth Costs Prices from ScaleEngine, UStream, and LiveStream as of October 2012 Sunday, December 2, 12
  • 94. Bandwidth Costs Prices from ScaleEngine, UStream, and LiveStream as of October 2012 Sunday, December 2, 12
  • 96. Takeaways • HLS is a very practical streaming solution • Only part of the picture if you're multi-platform • Encoding and serving correctly requires some care and expertise, and a lot of money • Client-side software requirements are fairly simple Sunday, December 2, 12
  • 97. Q&A Slides and code will be available on my blog: http://www.subfurther.com/blog http://www.slideshare.net/invalidname @invalidname Sunday, December 2, 12