moving pictures - web 2.0 expo nyc

70
Moving Pictures Implementing Video on Flickr Cal Henderson

Upload: cal-henderson

Post on 16-Apr-2017

5.370 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Moving Pictures - Web 2.0 Expo NYC

Moving PicturesImplementing Video on Flickr

Cal Henderson

Page 2: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 2

Hello

Page 3: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 3

Flickr

• Large scale kitten sharing website

• Started 2003, launched 2004– 5 years old this december

• Almost 3 billion photos

Page 4: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 4

Enter: Video

• Video was added this year– Launched April 2008

• Many hundreds of thousands of videos uploaded

• Many millions of playbacks

Page 5: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 5

Page 6: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 6

Page 7: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 7

Page 8: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 8

Page 9: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 9

Page 10: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 10

“Video? That’s just like photos!”

-Me, before Flickr Video

Page 11: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 11

12 4 Steps

• 4 main tasks– Uploading– Transcoding– Storage– Serving & Playback

Page 12: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 12

1. Upload

Page 13: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 13

Simple upload

• Web forms– Just like any other file

<form action="/uploadify/" method="post" enctype="multipart/form-data">

<input type="file" name="fred" /> <input type="submit" value="Go!" />

</form>

• But files are large / huge

Page 14: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 14

Issues

• Two components for uploading:– Sending from the client– Receiving on the server

• Both of these present problems

Page 15: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 15

Sending from the client

• Multiple options– Simple form– Flash– Desktop app

Page 16: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 16

Simple Forms

• Pros– Very easy to implement– Works on every browser out of the box

• Cons– Upload progress is harder– ‘Slow’– Select a single file at once

Page 17: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 17

Flash

• Pros– Upload progress is easy– ‘Fast’– Multi select of files

• Cons– Harder to implement– Flash isn’t quite ubiquitous

Page 18: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 18

Desktop App

• Pros– Upload progress is easy– ‘Very fast’– Multi select of files– Drag and drop

• Cons– Hard to develop– Hard to deploy (relative to the web)

Page 19: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 19

Making Progress

• Upload progress– Not impossible with plain forms– Just need to be able to query the upload

progress via AJAX

• Multiple machines– The VIP issue– Enter Perlbal

Page 20: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 20

Making Progress

Browser

Web 1

Web 2

1. Browser starts upload

2. Web server broadcastsprogress via UDP

3. Browser queries progressvia AJX call

Loadbalancer

Page 21: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 21

Receiving on the server

• File uploads are slow– Much slower than serving pages

• Apache processes are heavy– Waste of resources

• Use a poll based server (like jetty)

Page 22: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 22

Receiving on the server

• Or, use a buffering layer– Perlbal is great for this

• Or a lightweight Apache– E.g. w/ mod_proxy

Browser Buffer ServerSlow Fast

Page 23: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 23

But wait

• It’s not just the first step that’s slow

• Moving files around between servers is slow– Do it out of band

• Asynchronous jobs are in order anyway– Do it!

Page 24: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 24

2. Transcode

Page 25: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 25

Transcode?

• Why transcode at all?

• Input comes from many sources– Point & shoots– DV Cams– Mobile devices– Video editing software

• All in different formats

Page 26: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 26

So many formats

• But very few of these formats can be played back cross platform– Without special software or hardware

• Formats are designed to do one thing well– They don’t always manage even that

• Transcoding puts all videos on an equal footing

Page 27: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 27

Video file basics

• Most file types are really just containers– MOV, FLV, AVI

• The data inside can be in multiple formats– We call these codecs (encoder + decoder)

• Files contains multiple ‘streams’– Both audio and video

Page 28: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 28

Interleave

• Audio and video are often interleaved– Hence AVI

• A video file looks like this:– Headers– Video chunk– Audio chunk– Video chunk– Audio chunk– Etc

Page 29: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 29

Compress

• Raw video files are huge– A bitmap for every frame– Rarely used, even in post production

• At 30 fps, that gets crazy pretty quickly

• We don’t need to store every frame– Static backgrounds don’t change (much)

between frames

Page 30: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 30

Compresssss

• Intraframe– Treat each frame as a picture– Compress it (just like JPEG)– DCT (Discrete Cosine Transform)

• Interframe– Store the differences between frames– Treat the pixels as a 3D array to be

compressed

Page 31: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 31

The IPB

• Three frame types: I, P & B

• Intra coded pictures– A full raw frame

• Predicted pictures– Based on a single reference frame

• Bi-predictive pictures– Based on two or more reference frames

Page 32: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 32

IPBIPBIPBIPB

• Reference frames may be I, P or B

• P & B frames may contain a mix of image data and motion vector displacements

• I frames require the most bits– Then P frames– Then B frames

Page 33: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 33

Bad terminology

• We should really say picture– (Not frame)– Because of interlacing

• Really, we encode fields not frames– Picture is the general term

• And H.264 contains ‘slices’– Sub-regions of the field– ‘Macroblocks’ & ‘Artifacts’

Page 34: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 34

I-Frames

• Also called Key Frames

• Allow easy random seeking

• Twice a second for Digital TV & DVDs

• More widely spaced online

Page 35: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 35

Seekable

Page 36: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 36

Seekable

Page 37: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 37

Oh, and audio too

• We can worry less about this– Older problem, well solved

• MP3 is pretty good– Who cares how it works?

• Syncing is the only issue– Presentation Time Stamps (PTS) and Decode

Time Stamps (DTS) in MPEG-2

Page 38: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 38

Flash! Woah-oh!

The big question:

Flash?

Page 39: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 39

Non-flash sites• QuickTime• Windows Media• This is gradually disappearing

• Flash player is ubiquitous• Compression is good enough• Interactive too

• But no 3D/VR as with QuickTime :(

Page 40: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 40

The Flash Player

• Flash Player 6– March 2002

• Video: Sorenson Spark (H.263)• Audio: MP3

– Or ADPCM / Uncompressed– Or Nellymoser Asao

Page 41: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 41

Second Generation

• Flash Player 7– August 2005

• Video: On2 TrueMotion VP6• Audio: MP3

Page 42: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 42

The hot shit

• Flash Player 9 (update 3)– December 2007

• Video: H.264 (MPEG-4 Part 10)– w/ container formats from MPEG-4 Part 14

• Audio: AAC (MPEG-4 Part 3)

• Plus 3GPP Timed Text (MPEG-4 Part 17)

Page 43: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 43

TrueMotion VP6

• Proprietary• Reasonable compression• Created by On2

– Patented– Probably illegal for GPL code

• YouTube uses it for lower quality and old streams

Page 44: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 44

H.264• Not proprietary• Good compression• MPEG Standard

– Open, but patented– Patent licenses from the MPEG LA– Unclear how this applies to (L)GPL code– But probably badly

• YouTube using it for higher quality streams

• iPhones and AppleTV

Page 45: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 45

Software

• Open source transcode tools

• FFmepg– libavcodec for VP6– Probably illegal – dubious– Also pretty shoddy– Can only decode H.264

Page 46: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 46

More software

• MEncoder– libmpcodecs uses libavcodec

• VLC– libvlc uses libavcodec

• So basically the same– Different muxing, same codecs

Page 47: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 47

Free H.264?

• Unfortunately, not really

• x264 is the only usable one– It’s pretty good– MEncoder can use it– Still limited in options at this point– Again, dubiously legal

Page 48: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 48

Non-free tools• Flash encoder

– Not automatable

• On2 FlixEngine– Creators of VP6– Windows or Linux– Some support for H.264

• Rhozet Carbon Coder– The new hot shit– Good H.264 support– Windows

Page 49: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 49

Choices

• Video codec• Resolution• Bitrate (VBR, CBR)• Keyframes• Audio codec

– Channels– Bit depth– Sampling rate

Page 50: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 50

Doing it at scale

• Not really a problem• Very easily parallelizable

• Amazon EC2 is awesome here– Exactly what it was design for– Grow/shrink as needed– But, per-CPU software licensing

Page 51: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 51

3.Store

Page 52: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 52

Easy!

• Really, just like photos– But with bigger files

• Same disk layout as any other serving

• But the serving part is slower

Page 53: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 53

But..

• Remember the files are huge

• Operations take time– More likely to fail halfway through– Checksums are your friend

• Do it all asynchronously

Page 54: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 54

4. Serve & Playback

Page 55: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 55

The choice

Streamingvs

Progressive

Page 56: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 56

Streaming

• Pros– Easily seekable– Live feeds

• Cons– Special server software– Slower to start– Firewall troubles

Page 57: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 57

Progressive download

• Pros– Just use a web server– Play offline– Firewall/proxy friendly

• Cons– Harder to seek ahead (but not impossible)

Page 58: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 58

Streaming tech

• Non flash stuff– We’ll ignore that– You’re using flash, right?

• RTMP– Real-time Messaging Protocol– Proprietary (thanks Adobe!)

Page 59: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 59

RTMP

• RTMP - Raw TCP socket stuffs• RTMPT – RTMP tunneled over HHTP

– For firewalls, etc

• Flash Media Server– previously Flash Communication Server

• Wowza Pro– $1000/server

Page 60: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 60

Open source

• It’s not all bad

• Red5– Java implementation of RTMP server– Mostly feature complete– Beta quality, but usable in production– Facebook

Page 61: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 61

Progressive

• Used by the majority of large sites

• Very simple!

• Seekable with server support

Page 62: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 62

Seeking

• Serve the FLV starting at a different point

• Just add a simple FLV preamble before seeking into the file

• Simple to do in PHP, Perl, etc• mod_flvx for Apache• mod_secdownload for lighttpd

Page 63: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 63

5. Other considerations

Page 64: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 64

Review

• Videos are slow• Expensive to review

• Review grids– Doesn’t cover audio

Page 65: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 65

Page 66: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 66

Not enough?

• Social tools are useful here

Page 67: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 67

Summary

Page 68: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 68

Summing up

• Flash makes sense– For uploading too

• H.264 is probably your best bet today• Transcoding software still costs money

– Unless you’re willing to take on the risk• Progressive download is basically

awesome

Page 69: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 69

The end!

Page 70: Moving Pictures - Web 2.0 Expo NYC

Web 2.0 Expo NYC, 17th September 2008 70

Awesome!

These slides are available online:iamcal.com/talks/