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
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Zoneless Testing
rainerhahnekamp
0
120
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
670
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
310
Go の GC の不得意な部分を克服したい
taiyow
2
770
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
useSyncExternalStoreを使いまくる
ssssota
6
1k
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
710
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
770
Featured
See All Featured
Building Applications with DynamoDB
mza
91
6.1k
Building an army of robots
kneath
302
44k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Navigating Team Friction
lara
183
15k
Mobile First: as difficult as doing things right
swwweet
222
9k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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!!