forked from runabol/tork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhls.yaml
136 lines (125 loc) · 5.48 KB
/
hls.yaml
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
name: Sample HLS Job Multiple Bitrates
description: |
This job generates a multi-bitrate HLS package from a sample source video.
This demo assumes a locally running instace of Minio (AWS S3-like service) which will be used to store the
video chunks and the final video output
You can get a running instance of minio using the following command:
docker network create minio
docker run --name=minio --network=minio -d -p 9000:9000 -p 9001:9001 minio/minio server /data --console-address ":9001"
The default credentials for Minio Server are minioadmin/minioadmin
You can view the output using the minio console on http://127.0.0.1:9001/browser
inputs:
source: https://upload.wikimedia.org/wikipedia/commons/1/18/Big_Buck_Bunny_Trailer_1080p.ogv
accessKeyID: minioadmin
secretKeyID: minioadmin
endpointURL: http://minio:9000
tasks:
- var: bucketName
name: generate a random bucket name to store the results
image: ubuntu:mantic
run: echo -n "video-$(shuf -i 1-10000 -n1)" > $TORK_OUTPUT
- name: create a temporary bucket to house the chunks
image: "amazon/aws-cli:2.13.10"
networks:
- minio
env:
AWS_ACCESS_KEY_ID: "{{inputs.accessKeyID}}"
AWS_SECRET_ACCESS_KEY: "{{inputs.secretKeyID}}"
BUCKET_NAME: "{{tasks.bucketName}}"
ENDPOINT_URL: "{{inputs.endpointURL}}"
run: |
aws \
--endpoint-url $ENDPOINT_URL s3api create-bucket --bucket $BUCKET_NAME
- name: create the master playlist
image: "amazon/aws-cli:2.13.10"
networks:
- minio
env:
AWS_ACCESS_KEY_ID: "{{inputs.accessKeyID}}"
AWS_SECRET_ACCESS_KEY: "{{inputs.secretKeyID}}"
BUCKET_NAME: "{{tasks.bucketName}}"
ENDPOINT_URL: "{{inputs.endpointURL}}"
run: |
printf "#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360\n360p.m3u8\n#EXT-X-STREAM-INF:BANDWIDTH=1400000,RESOLUTION=842x480\n480p.m3u8\n#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720\n720p.m3u8" > /tmp/playlist.m3u8
aws --endpoint-url $ENDPOINT_URL s3 cp /tmp/playlist.m3u8 s3://$BUCKET_NAME/hls/playlist.m3u8
- name: Generate the HLS streams
parallel:
tasks:
- name: Generate 360p HLS stream
retry:
limit: 2
mounts:
- type: volume
target: /tmp
networks:
- minio
run: |
mkdir /tmp/output
ffmpeg -y -i $SOURCE -vf scale=w=-2:h=360 -c:a aac -ar 48000 -b:a 96k -c:v h264 -profile:v main \
-crf 20 -g 48 -keyint_min 48 -sc_threshold 0 -b:v 800k -maxrate 856k -bufsize 1200k -hls_time 4 \
-hls_playlist_type vod -hls_segment_filename /tmp/output/360p_%03d.ts /tmp/output/360p.m3u8
image: jrottenberg/ffmpeg:3.4-alpine
env:
SOURCE: "{{ inputs.source }}"
post:
- name: upload the chunk to minio
image: "amazon/aws-cli:2.13.10"
env:
AWS_ACCESS_KEY_ID: "{{inputs.accessKeyID}}"
AWS_SECRET_ACCESS_KEY: "{{inputs.secretKeyID}}"
BUCKET_NAME: "{{tasks.bucketName}}"
ENDPOINT_URL: "{{inputs.endpointURL}}"
run:
aws --endpoint-url $ENDPOINT_URL s3 sync /tmp/output/ s3://$BUCKET_NAME/hls/
- name: Generate 480p HLS stream
retry:
limit: 2
mounts:
- type: volume
target: /tmp
networks:
- minio
run: |
mkdir /tmp/output
ffmpeg -y -i $SOURCE -vf scale=w=-2:h=480 -c:a aac -ar 48000 -b:a 128k -c:v h264 -profile:v main \
-crf 20 -g 48 -keyint_min 48 -sc_threshold 0 -b:v 1400k -maxrate 1498k -bufsize 2100k -hls_time 4 \
-hls_playlist_type vod -hls_segment_filename /tmp/output/480p_%03d.ts /tmp/output/480p.m3u8
image: jrottenberg/ffmpeg:3.4-alpine
env:
SOURCE: "{{ inputs.source }}"
post:
- name: upload the chunk to minio
image: "amazon/aws-cli:2.13.10"
env:
AWS_ACCESS_KEY_ID: "{{inputs.accessKeyID}}"
AWS_SECRET_ACCESS_KEY: "{{inputs.secretKeyID}}"
BUCKET_NAME: "{{tasks.bucketName}}"
ENDPOINT_URL: "{{inputs.endpointURL}}"
run:
aws --endpoint-url $ENDPOINT_URL s3 sync /tmp/output/ s3://$BUCKET_NAME/hls/
- name: Generate 720p HLS stream
retry:
limit: 2
mounts:
- type: volume
target: /tmp
networks:
- minio
run: |
mkdir /tmp/output
ffmpeg -y -i $SOURCE -vf scale=w=-2:h=720 -c:a aac -ar 48000 -b:a 128k -c:v h264 -profile:v main \
-crf 20 -g 48 -keyint_min 48 -sc_threshold 0 -b:v 2800k -maxrate 2800k -bufsize 4200k -hls_time 4 \
-hls_playlist_type vod -hls_segment_filename /tmp/output/720p_%03d.ts /tmp/output/720p.m3u8
image: jrottenberg/ffmpeg:3.4-alpine
env:
SOURCE: "{{ inputs.source }}"
post:
- name: upload the chunk to minio
image: "amazon/aws-cli:2.13.10"
env:
AWS_ACCESS_KEY_ID: "{{inputs.accessKeyID}}"
AWS_SECRET_ACCESS_KEY: "{{inputs.secretKeyID}}"
BUCKET_NAME: "{{tasks.bucketName}}"
ENDPOINT_URL: "{{inputs.endpointURL}}"
run:
aws --endpoint-url $ENDPOINT_URL s3 sync /tmp/output/ s3://$BUCKET_NAME/hls/