forked from CaitlinOCallaghan/shaka-streamer-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_aws_stream.sh
executable file
·136 lines (116 loc) · 3.7 KB
/
e2e_aws_stream.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# set arguments
driverType="mediastore" # specify "mediastore" or "s3"
bucketName="dropbears"
awsEndpoint="https://jzw2ldnc6rzikp.data.mediastore.us-west-2.amazonaws.com"
vid=$(date '+%M%S')
rm pipe0
mkfifo pipe0
# start shim
sudo pkill s3-upload-proxy
export LOG_LEVEL=debug UPLOAD_DRIVER=${driverType} REGION_NAME=us-west-2 BUCKET_NAME=${bucketName} HTTP_PORT=8080
cd s3-upload-proxy
go build -o ./s3-upload-proxy
cd ..
./s3-upload-proxy/s3-upload-proxy &
# generate player
cat > /tmp/${vid}.html <<_PAGE_
<!doctype html>
<html>
<head>
<body>
<style>
body {
background-color : black;
margin : 0;
}
video {
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
width: 100%;
max-height: 100%;
}
</style>
</head>
<!-- Shaka Player compiled library: -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/3.0.5/shaka-player.compiled.js"></script>
<!-- Your application source: -->
<script src="${vid}.js"></script>
</head>
<body>
<video id="video"
width="640"
controls autoplay></video>
</body>
</html>
_PAGE_
cat > /tmp/${vid}.js <<_JS_
const manifestUri =
'${vid}.mpd';
function initApp() {
// Install built-in polyfills to patch browser incompatibilities.
shaka.polyfill.installAll();
// Check to see if the browser supports the basic APIs Shaka needs.
if (shaka.Player.isBrowserSupported()) {
// Everything looks good!
initPlayer();
} else {
// This browser does not have the minimum set of APIs we need.
console.error('Browser not supported!');
}
}
async function initPlayer() {
// Create a Player instance.
const video = document.getElementById('video');
const player = new shaka.Player(video);
// Attach player to the window to make it easy to access in the JS console.
window.player = player;
// Listen for error events.
player.addEventListener('error', onErrorEvent);
// Try to load a manifest.
// This is an asynchronous process.
try {
await player.load(manifestUri);
// This runs if the asynchronous load is successful.
console.log('The video has now been loaded!');
} catch (e) {
// onError is executed if the asynchronous load fails.
onError(e);
}
}
function onErrorEvent(event) {
// Extract the shaka.util.Error object from the event.
onError(event.detail);
}
function onError(error) {
// Log the error.
console.error('Error code', error.code, 'object', error);
}
document.addEventListener('DOMContentLoaded', initApp);
_JS_
# Upload the player over HTTP PUT to the origin server
# NOTE: ensure that the endpoint is to your specific bucket/container
aws mediastore-data put-object --endpoint ${awsEndpoint} --body /tmp/${vid}.html --path ${vid}.html --cache-control "max-age=6, public" --content-type text/html --region us-west-2
aws mediastore-data put-object --endpoint ${awsEndpoint} --body /tmp/${vid}.js --path ${vid}.js --cache-control "max-age=6, public" --content-type text/javascript --region us-west-2
# encode with ffmpeg
x264enc='libx264 -tune zerolatency -profile:v high -preset ultrafast -bf 0 -refs 3 -sc_threshold 0'
ffmpeg \
-hide_banner \
-re \
-i "/home/coc/shaka-streamer-demo/BigBuckBunny.mp4" \
-pix_fmt yuv420p \
-map 0:v \
-c:v ${x264enc} \
-g 30 \
-keyint_min 30 \
-b:v 4000k \
-f mpegts \
pipe: > pipe0 &
# package as dash
packager \
--io_block_size 65536 \
in=pipe0,stream=video,init_segment='http://0.0.0.0:8080/'${vid}'_live_video_init.mp4',segment_template='http://0.0.0.0:8080/'${vid}'_live_video_$Number$.m4s' \
--mpd_output "http://0.0.0.0:8080/${vid}.mpd"
rm pipe0