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
9.9k
React Native Beyond Prototype
timakin
2
1.6k
Performance Optimization on Google AppEngine
timakin
5
6.1k
testcache.pdf
timakin
1
120
How Go cache
timakin
1
62
How Go cache tests
timakin
1
2.9k
Other Decks in Programming
See All in Programming
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
220
Re:proS_案内資料
rect
0
260
テスト駆動開発✅️
akitoshiga
1
210
Java ジェネリクス入門 2024
nagise
0
530
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
100
リリース8年目のサービスの1800個のERBファイルをViewComponentに移行した方法とその結果
katty0324
2
2.8k
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
170
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
4
13k
C#/.NETのこれまでのふりかえり
tomokusaba
1
140
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
4
150
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
10
2.2k
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
170
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
Faster Mobile Websites
deanohume
304
30k
Rails Girls Zürich Keynote
gr2m
93
13k
Adopting Sorbet at Scale
ufuk
73
9k
Testing 201, or: Great Expectations
jmmastey
38
7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
360
Scaling GitHub
holman
458
140k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
41
9.2k
KATA
mclloyd
29
13k
Docker and Python
trallard
40
3k
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!!