Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go and on-demand video streaming / Goとオンデマンド動画配信
Search
Seiji Takahashi
December 13, 2017
Programming
4
2.9k
Go and on-demand video streaming / Goとオンデマンド動画配信
Lecture at university of Aizu / 2017/12/10
Seiji Takahashi
December 13, 2017
Tweet
Share
More Decks by Seiji Takahashi
See All by Seiji Takahashi
Go Backends for frontends with GraphQL and gRPC
timakin
6
3.7k
Design Pattern for Image and Text Composition in Go
timakin
5
6.5k
Golang API Testing the HARD way
timakin
13
6.4k
Head First Golang Image Package
timakin
2
10k
React Native Beyond Prototype
timakin
2
1.6k
Performance Optimization on Google AppEngine
timakin
5
6.2k
testcache.pdf
timakin
1
130
How Go cache
timakin
1
66
How Go cache tests
timakin
1
2.9k
Other Decks in Programming
See All in Programming
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
140
良いユニットテストを書こう
mototakatsu
8
2.4k
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
130
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
Security_for_introducing_eBPF
kentatada
0
110
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
380
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
Featured
See All Featured
Fireside Chat
paigeccino
34
3.1k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
The Invisible Side of Design
smashingmag
298
50k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Practical Orchestrator
shlominoach
186
10k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
98
Visualization
eitanlees
146
15k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
How to Ace a Technical Interview
jacobian
276
23k
Music & Morning Musume
bryan
46
6.2k
Transcript
Goͱ ΦϯσϚϯυಈը ৴ج൫ @__timakin__
• Seiji Takahashi • Github: timakin / Twitter: @__timakin__ •
גࣜձࣾσΟʔɾΤψɾΤʔ • Perl / JavaScript • גࣜձࣾτϥϯεϦϛοτ • C++ (Cocos-2dx) • גࣜձࣾGunosy ৽نࣄۀ։ൃࣨ • Go / Swift ࣗݾհ
גࣜձࣾGunosy ৽نࣄۀ։ൃࣨʹ͍ͭͯ
Gunosyͷ5ʙ10ޙͷΛ࡞Δ͘ɺ VRARɺԻUIͳͲࠓޙීٴ͢ΔՄೳੑͷ͋Δ ৽͍͠σόΠεٕज़Λݚڀ͠ɺ ৽نαʔϏεͷ্ཱͪ͛ͳͲΛߦ͏෦ॺ
Ϧαʔν • ւ֎ͷઌਐࣄྫͷ·ͱΊ • SDKͷެࣜDocsGithub repoͷ ίʔυΛړͬͯ࠷৽ٕज़ͷ νϡʔτϦɾԠ༻ྫΛ୳Δ • SlackʹRSS௨ɺϨϙʔτڞ༗
Δ͜ͱ
։ൃ • ͓ன͍ͭͰʹνϡʔτϦΞϧ ϋοΧιϯ • ্ཱ͕ͪΓظ ۃྗখنνʔϜͰ Δ͜ͱ
ྫ
ྫ
ษڧձ։࠵
ຊͷΞδΣϯμ
GoͱΦϯσϚϯυಈը৴ج൫ • ಈը৴ͱʁ • ৴·ͰͷྲྀΕ • GoΛͲ͏͏͔ • ·ͱΊ ΞδΣϯμ
ΞδΣϯμ GoͰ࡞ΔΦϯσϚϯυಈը৴ج൫ • ಈը৴ͱʁ • ৴·ͰͷྲྀΕ • GoΛͲ͏͏͔ • ·ͱΊ
େ͖͚ͯ͘ ̎ छྨ ಈը৴ͱʁ
ϦΞϧλΠϜ৴ • ͍ΘΏΔϥΠϒಈը • WebSocketͷ ίωΫγϣϯͳͲΛ ௨ͯ͡ϒϩʔυΩϟετ ಈը৴ͷछྨ
ΦϯσϚϯυ৴ • ͋Β͔͡Ί࡞͞Εͨ ಈըΛݟΔ • ಈը͕ඞཁʹͳͬͨ λΠϛϯάͰࣗ༝ʹ ࢹௌͰ͖Δ ಈը৴ͷछྨ
GoͰ࡞ΔΦϯσϚϯυಈը৴ج൫ • ಈը৴ͱʁ • ৴·ͰͷྲྀΕ • GoΛͲ͏͏͔ • ·ͱΊ ΞδΣϯμ
ಈը৴ʹඞཁͳ࡞ۀ Ξοϓϩʔυ ө૾ॲཧ ύοέʔδԽ ৴
ಈը৴ʹඞཁͳ࡞ۀ Ξοϓϩʔυ ө૾ॲཧ ύοέʔδԽ ৴ ετϨʔδ ৴ऀ AWSͷS3 Bucket GCPͷCloud
Storage ͳͲʹΞοϓϩʔυ
ಈը৴ʹඞཁͳ࡞ۀ Ξοϓϩʔυ ө૾ॲཧ ύοέʔδԽ ৴ Τϯίʔμʔ ετϨʔδ ࣈນૠೖೖྗө૾ͷ ΤϯίʔσΟϯάʹՃ͑ͯɺ αϜωΠϧͷΓऔΓͳͲ
ಈը৴ʹඞཁͳ࡞ۀ Ξοϓϩʔυ ө૾ॲཧ ύοέʔδԽ ৴ ετϨʔδ ಈըΛׂͯ͠ ޮతʹ৴Մೳͳ ϑΝΠϧΛੜ͢Δɺ ҉߸Խ͢Δ
ύοέʔδϯά"1*
ಈը৴ʹඞཁͳ࡞ۀ Ξοϓϩʔυ ө૾ॲཧ ύοέʔδԽ ৴ ৴"1* $%/ ετϨʔδ ड৴ऀ HTTPΫϥΠΞϯτʹରͯ͠
CDNΛ௨ͭͭ͠৴
શମ૾ ετϨʔδ ৴ऀ ө૾ॲཧɺ ύοέʔδϯά ৴"1* $%/ ड৴ऀ
GoͱΦϯσϚϯυಈը৴ج൫ • ಈը৴ͱʁ • ৴·ͰͷྲྀΕ • GoΛͲ͏͏͔ • ·ͱΊ ΞδΣϯμ
Ξοϓϩʔυ ө૾ॲཧ ύοέʔδԽ ৴ Go͕ؔΘΔͱ͜Ζ ʁ
Go͕ؔΘΔͱ͜Ζ ө૾ॲཧ • ఏڙը࣭ʹ߹ΘͤͨϑϨʔϜ/ϏοτϨʔτͷௐ • ϩεΛ͑ͨѹॖ ύοέʔδԽ • m3u8 +
TSϑΝΠϧͷੜ • ετϨʔδͷΞοϓϩʔυ ৴ • ಈըͷJSONΛฦ͢௨ৗͷAPIػೳ • αϜωΠϧؔ࿈ಈըੜ
Կߟ͑ͳ͍৴ mp4
Կߟ͑ͳ͍৴ mp4 Ϋιॏ͍
HLS৴ • HTTP Live Streaming • Apple͕iOS͚ʹ։ൃͨ͠ετϦʔϛϯάϓϩτίϧ • WindowsͳͲ࠶ੜڥ͕ݶఆ •
ϫʔΫϑϩʔ • ಈըίϯςϯπͷΞοϓϩʔυ • ηάϝϯτԽ • ಉ࣌ʹαϜωΠϧੜ৴࣭ผͷੜͳͲ • IndexFile(m3u8)Λ৴ͯ͠ɺΫϥΠΞϯτ ΠϯσοΫε͞ΕͨMPEG-2 TSϑΝΠϧΛಡΈʹߦ͘
HLSͷத segmented media files (MPEG-2 TS) Index file (m3u8)
HLS৴ͷྲྀΕ NV )JHI NV .JE NV -PX
؆୯ʹHLSΤϯίʔυ͢Δํ๏ ffmpeg Elastic Transcoder
؆୯ʹHLSΤϯίʔυ͢Δํ๏ ffmpeg Elastic Transcoder
ffmpeg • ಈըͱԻΛهɾมɾ࠶ੜ͢ΔͨΊͷϑϦʔιϑτ ΣΞ • ffmpegΛར༻ͨ͠Τϯίʔυɾσίʔυ͕Ͱ͖Δ ༻ιϑτΣΞஶ࡞ݖ৵ΛሃΉ…? https://blog.tai2.net/mpegla_and_ffmpeg.html
ffmpeg-based API • Docker multi-stage buildͰੜ͞ΕͨimageΛݩʹɺ execܦ༝ͰffmpegΛݺͿɻ • binding࣮͔ίϚϯυͷexecuteͰݺͿ΄͔ͳ͍ɻ •
ݸਓతʹGKEͰ্هimageΛݩʹͨ͠ίϯςφΛཱͯ ͯɺੜ݁ՌΛGoogle Cloud StorageʹΞοϓϩʔυ͢ ΔͳͲ͕ྑ͍ͱࢥͬͯΔɻ
ffmpeg-based API media file Kubernetes Engine Cloud Storage goroutine
ffmpeg encoding
ffmpeg encoding
Encoding command mp4ΛAACɺH.264ͰΤϯίʔυ͠ɺ 4ඵ͝ͱͷηάϝϯτʹׂͨ݁͠ՌΛอଘ͢Δίʔυɻ ಉҰσΟϨΫτϦʹm3u8ͱtsϑΝΠϧ͕ੜ͞ΕΔɻ
Exec Commands ffmpegͷbinding࣮(goav)Λ͏ͷ͋Γɻ ͨͩɺॊೈͳΦϓγϣϯઃఆͳͲΛؑΈΔͱffmpegΛ ͦͷ··࣮ߦͨ͠ํ͕ྑ͍ɻ
ffmpeg bindingΛΘͳ͍߹۪ʹݺͿ͔͠ͳ͍ Exec Commands
goroutineΛར༻ͯ͠ੜ͞Εͨ ϑΝΠϧΛฒྻΞοϓϩʔυ Parallel upload
ffmpeg-based APIͷ·ͱΊ • αʔόʔʹΠϯετʔϧ͞ΕͨffmpegΛར༻͢Δɻ • GKEͳͲΛ͍ͭͭɺDocker multi-stage buildͰੜ ͞ΕͨimageΛݩʹɺexecܦ༝ͰffmpegΛݺͿํ๏ ͋Γɻ
• binding࣮ΑΓίϚϯυͷexecuteΛ͓͢͢Ίɻ
؆୯ʹHLSΤϯίʔυ͢Δํ๏ ffmpeg Elastic Transcoder
Elastic Transcoder • AWS্ͷϚωʔδυಈըΤϯίʔμʔ • ίϯςϯπͷ࠶ੜ࣌ؒΛϕʔεʹ՝ۚ͞ΕΔ • ੜ݁ՌS3ΦϒδΣΫτͱͯ͠อଘ͞ΕΔ
Elastic Transcoder input bucket media file Lambda Transcoder output bucket
Transcoding Pipeline
Elastic Transcoder input bucket media file Lambda Transcoder output bucket
Transcoding Pipeline
None
• goͰlambdaؔΛॻ͚ΔϥΠϒϥϦ • όΠφϦͱͦΕΛݺͼग़͢index.jsΛੜͯ͠ɺ Node.jsϥϯλΠϜͰ࣮ߦ͢Δ go-apex
Elastic Transcoder input bucket media file Lambda Transcoder output bucket
Transcoding Pipeline
S3 Observation
Elastic Transcoder input bucket media file Lambda Transcoder output bucket
Transcoding Pipeline
Parameter Tuning
Elastic Transcoder ·ͱΊ • go-apexʹΑΔS3ࢹͱมॲཧ • ࠷ۙLambda͕σϑΥϧτͰGoରԠ͢Δతͳൃදͨ͠ ͠ݟͨ·ͬͨΒͦͬͪʹ͠·͠ΐ͏ɻ • ϚωʔδυͰ৭ʑͬͯ͘ΕΔɺׂසͳͲͷ
ύϥϝʔλʔνϡʔχϯάʹҙ͠·͠ΐ͏ɻ
ʕ ◔ϖ◔ʔ < Thank You!!