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
63
How Go cache tests
timakin
1
2.9k
Other Decks in Programming
See All in Programming
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Quine, Polyglot, 良いコード
qnighy
4
650
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Jakarta EE meets AI
ivargrimstad
0
590
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
Remix on Hono on Cloudflare Workers
yusukebe
1
300
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
距離関数を極める! / SESSIONS 2024
gam0022
0
290
Featured
See All Featured
Teambox: Starting and Learning
jrom
133
8.8k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Bash Introduction
62gerente
608
210k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Building Your Own Lightsaber
phodgson
103
6.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Statistics for Hackers
jakevdp
796
220k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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!!