bitmovin-ruby 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/bitmovin-ruby.gemspec +1 -1
- data/lib/bitmovin/encoding/encodings.rb +2 -0
- data/lib/bitmovin/encoding/encodings/sprites/sprite.rb +76 -0
- data/lib/bitmovin/encoding/encodings/stream.rb +12 -0
- data/lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb +71 -0
- data/lib/bitmovin/encoding/manifests/hls_audio_media.rb +15 -10
- data/lib/bitmovin/encoding/stream_output.rb +1 -0
- data/lib/bitmovin/version.rb +1 -1
- data/lib/bitmovin/webhooks.rb +1 -0
- data/lib/bitmovin/webhooks/encoding_error_webhook.rb +14 -0
- data/lib/bitmovin/webhooks/encoding_finished_webhook.rb +9 -0
- metadata +6 -9
- data/examples/create_encoding_finished_webhook.rb +0 -21
- data/examples/dash_hls_mp4_encoding_with_manifests.rb +0 -502
- data/examples/hls_multi_codec.rb +0 -205
- data/examples/simple_dash.rb +0 -221
- data/examples/simple_dash_with_http_input.rb +0 -216
- data/examples/simple_hls_with_aes128.rb +0 -197
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f33bc3d3ad45622a17cd9a6fe6cbc446c3522be
|
4
|
+
data.tar.gz: da41e2a81ae4ee3d992991f6e37182fc47b4a781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16ffa8271ef89ba08c8d2bfe1f0a24ad97fa9af512b8b456ee568a28a8086d13d57333aab62e8ace112d6b11f2e8cbd4a21043e9ad67a9c6d2dbd1f6ed009b82
|
7
|
+
data.tar.gz: d87a2fd898b955438589241e35362bc8d0922fb8894b7df9293acac302ad282e32e1ea52223254400bd50b2b2f80422ffb46924a4bd21457f2a2a406d164a7ff
|
data/Gemfile.lock
CHANGED
data/bitmovin-ruby.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
-
f.match(%r{^(test|spec|features)/})
|
18
|
+
f.match(%r{^(test|spec|features|examples)/})
|
19
19
|
end
|
20
20
|
spec.bindir = "exe"
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
@@ -26,3 +26,5 @@ require 'bitmovin/encoding/encodings/muxings/drms/drm_muxings'
|
|
26
26
|
require 'bitmovin/encoding/encodings/muxings/drms/ts_muxing_drm_list'
|
27
27
|
require 'bitmovin/encoding/encodings/muxings/drms/ts_muxing_aes_encryption_list'
|
28
28
|
require 'bitmovin/encoding/encodings/muxings/drms/drm_muxing_resource'
|
29
|
+
require 'bitmovin/encoding/encodings/thumbnails/thumbnail'
|
30
|
+
require 'bitmovin/encoding/encodings/sprites/sprite'
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Bitmovin::Encoding::Encodings
|
2
|
+
class Sprite < Bitmovin::Resource
|
3
|
+
|
4
|
+
def initialize(encoding_id, stream_id, hash = {})
|
5
|
+
@errors = []
|
6
|
+
self.class.init(File.join('/v1/encoding/encodings', encoding_id, 'streams', stream_id, 'sprites'))
|
7
|
+
|
8
|
+
@encoding_id = encoding_id
|
9
|
+
@stream_id = stream_id
|
10
|
+
|
11
|
+
hsh = ActiveSupport::HashWithIndifferentAccess.new(underscore_hash(hash))
|
12
|
+
@height = hsh[:height]
|
13
|
+
@width = hsh[:width]
|
14
|
+
@sprite_name = hsh[:sprite_name]
|
15
|
+
@vtt_name = hsh[:vtt_name]
|
16
|
+
@distance = hsh[:distance]
|
17
|
+
@outputs = (hsh[:outputs] || []).map {|output| Bitmovin::Encoding::StreamOutput.new(output)}
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_accessor :height, :width, :sprite_name, :vtt_name, :distance, :outputs
|
21
|
+
|
22
|
+
def save!
|
23
|
+
if valid?
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def errors
|
29
|
+
@errors
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid?
|
33
|
+
validate!
|
34
|
+
unless @errors.empty?
|
35
|
+
puts errors
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def invalid?
|
42
|
+
!valid?
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate!
|
46
|
+
@errors = []
|
47
|
+
|
48
|
+
if @height == nil || @height < 0
|
49
|
+
@errors << 'The height has to be set and must be greater than 0'
|
50
|
+
end
|
51
|
+
|
52
|
+
if @width == nil || @width < 0
|
53
|
+
@errors << 'The width has to be set and must be greater than 0'
|
54
|
+
end
|
55
|
+
|
56
|
+
if @sprite_name == nil || @sprite_name.blank?
|
57
|
+
@errors << 'The spriteName has to be set and must not be blank'
|
58
|
+
end
|
59
|
+
|
60
|
+
if @vtt_name == nil || @vtt_name.blank?
|
61
|
+
@errors << 'The vttName has to be set and must not be blank'
|
62
|
+
end
|
63
|
+
|
64
|
+
if @distance < 0
|
65
|
+
@errors << 'The distance is not allowed to be less than 0'
|
66
|
+
end
|
67
|
+
|
68
|
+
@outputs.each do |output|
|
69
|
+
@errors << output.errors unless output.valid?
|
70
|
+
end
|
71
|
+
|
72
|
+
@errors.flatten!
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -69,6 +69,18 @@ module Bitmovin::Encoding::Encodings
|
|
69
69
|
@errors
|
70
70
|
end
|
71
71
|
|
72
|
+
def input_details
|
73
|
+
path = File.join("/v1/encoding/encodings/", @encoding_id, "streams", @id, "input")
|
74
|
+
response = Bitmovin.client.get(path)
|
75
|
+
hash_to_struct(result(response))
|
76
|
+
end
|
77
|
+
|
78
|
+
def input_analysis
|
79
|
+
path = File.join("/v1/encoding/encodings/", @encoding_id, "streams", @id, "inputs")
|
80
|
+
response = Bitmovin.client.get(path)
|
81
|
+
hash_to_struct(result(response))
|
82
|
+
end
|
83
|
+
|
72
84
|
private
|
73
85
|
def collect_attributes
|
74
86
|
val = Hash.new
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Bitmovin::Encoding::Encodings
|
2
|
+
class Thumbnail < Bitmovin::Resource
|
3
|
+
|
4
|
+
def initialize(encoding_id, stream_id, hash = {})
|
5
|
+
@errors = []
|
6
|
+
self.class.init(File.join('/v1/encoding/encodings', encoding_id, 'streams', stream_id, 'thumbnails'))
|
7
|
+
|
8
|
+
@encoding_id = encoding_id
|
9
|
+
@stream_id = stream_id
|
10
|
+
|
11
|
+
hsh = ActiveSupport::HashWithIndifferentAccess.new(underscore_hash(hash))
|
12
|
+
@positions = hsh[:positions] || []
|
13
|
+
@unit = hsh[:unit]
|
14
|
+
@height = hsh[:height]
|
15
|
+
@pattern = hsh[:pattern]
|
16
|
+
@outputs = (hsh[:outputs] || []).map { |output| Bitmovin::Encoding::StreamOutput.new(output) }
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :positions, :unit, :height, :pattern, :outputs
|
20
|
+
|
21
|
+
def save!
|
22
|
+
if valid?
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def errors
|
28
|
+
@errors
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid?
|
32
|
+
validate!
|
33
|
+
unless @errors.empty?
|
34
|
+
puts errors
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def invalid?
|
41
|
+
!valid?
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate!
|
45
|
+
@errors = []
|
46
|
+
|
47
|
+
if @positions.nil? || @positions.empty?
|
48
|
+
@errors << 'There has to be at least one position for a thumbnail'
|
49
|
+
end
|
50
|
+
|
51
|
+
if @height.nil? || @height <= 0
|
52
|
+
@errors << 'The height has to be set and must be greater than 0'
|
53
|
+
end
|
54
|
+
|
55
|
+
if @pattern.nil? || @pattern.blank?
|
56
|
+
@errors << 'The pattern has to be set and must not be blank'
|
57
|
+
end
|
58
|
+
|
59
|
+
unless ['SECONDS', 'PERCENTS', nil].include? @unit
|
60
|
+
@errors << "The unit can only be 'SECONDS' or 'PERCENTS'"
|
61
|
+
end
|
62
|
+
|
63
|
+
@outputs.each do |output|
|
64
|
+
@errors << output.errors unless output.valid?
|
65
|
+
end
|
66
|
+
|
67
|
+
@errors.flatten!
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module Bitmovin::Encoding::Manifests
|
2
2
|
class HlsAudioMedia < Bitmovin::Resource
|
3
3
|
attr_accessor :manifest_id
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :group_id
|
5
5
|
attr_accessor :language
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :assoc_language
|
7
7
|
attr_accessor :name
|
8
|
-
attr_accessor :
|
8
|
+
attr_accessor :is_default
|
9
9
|
attr_accessor :autoselect
|
10
10
|
attr_accessor :characteristics
|
11
|
-
attr_accessor :
|
12
|
-
attr_accessor :
|
13
|
-
attr_accessor :
|
14
|
-
attr_accessor :
|
15
|
-
attr_accessor :
|
16
|
-
attr_accessor :
|
17
|
-
attr_accessor :
|
11
|
+
attr_accessor :segment_path
|
12
|
+
attr_accessor :encoding_id
|
13
|
+
attr_accessor :stream_id
|
14
|
+
attr_accessor :muxing_id
|
15
|
+
attr_accessor :drm_id
|
16
|
+
attr_accessor :start_segment_number
|
17
|
+
attr_accessor :end_segment_number
|
18
18
|
attr_accessor :uri
|
19
19
|
|
20
20
|
def initialize(manifest_id, hash = {})
|
@@ -23,5 +23,10 @@ module Bitmovin::Encoding::Manifests
|
|
23
23
|
self.class.init(File.join("/v1/encoding/manifests/hls/", manifest_id, "media/audio"))
|
24
24
|
super(hsh)
|
25
25
|
end
|
26
|
+
|
27
|
+
def ignore_fields
|
28
|
+
return [:@manifest_id, :@id]
|
29
|
+
end
|
30
|
+
|
26
31
|
end
|
27
32
|
end
|
data/lib/bitmovin/version.rb
CHANGED
data/lib/bitmovin/webhooks.rb
CHANGED
@@ -4,5 +4,6 @@ module Bitmovin
|
|
4
4
|
end
|
5
5
|
require 'bitmovin/webhooks/webhook_resource'
|
6
6
|
require 'bitmovin/webhooks/encoding_finished_webhook'
|
7
|
+
require 'bitmovin/webhooks/encoding_error_webhook'
|
7
8
|
require 'bitmovin/webhooks/webhook_encryption'
|
8
9
|
require 'bitmovin/webhooks/webhook_signature'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Bitmovin::Webhooks
|
2
|
+
class EncodingErrorWebhook < WebhookResource
|
3
|
+
init 'notifications/webhooks/encoding/encodings/error'
|
4
|
+
def initialize(encoding_id, hash = {})
|
5
|
+
if encoding_id.kind_of?(String)
|
6
|
+
@encoding_id = encoding_id
|
7
|
+
self.class.init("notifications/webhooks/encoding/encodings/#{encoding_id}/error")
|
8
|
+
else
|
9
|
+
hash = encoding_id
|
10
|
+
end
|
11
|
+
init_from_hash(hash)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,5 +1,14 @@
|
|
1
1
|
module Bitmovin::Webhooks
|
2
2
|
class EncodingFinishedWebhook < WebhookResource
|
3
3
|
init 'notifications/webhooks/encoding/encodings/finished'
|
4
|
+
def initialize(encoding_id = {}, hash = {})
|
5
|
+
if encoding_id.kind_of?(String)
|
6
|
+
@encoding_id = encoding_id
|
7
|
+
self.class.init("notifications/webhooks/encoding/encodings/#{encoding_id}/finished")
|
8
|
+
else
|
9
|
+
hash = encoding_id
|
10
|
+
end
|
11
|
+
init_from_hash(hash)
|
12
|
+
end
|
4
13
|
end
|
5
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitmovin-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Hoelbling-Inzko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -133,12 +133,6 @@ files:
|
|
133
133
|
- bin/console
|
134
134
|
- bin/setup
|
135
135
|
- bitmovin-ruby.gemspec
|
136
|
-
- examples/create_encoding_finished_webhook.rb
|
137
|
-
- examples/dash_hls_mp4_encoding_with_manifests.rb
|
138
|
-
- examples/hls_multi_codec.rb
|
139
|
-
- examples/simple_dash.rb
|
140
|
-
- examples/simple_dash_with_http_input.rb
|
141
|
-
- examples/simple_hls_with_aes128.rb
|
142
136
|
- lib/bitmovin-ruby.rb
|
143
137
|
- lib/bitmovin/bitmovin_error.rb
|
144
138
|
- lib/bitmovin/child_collection.rb
|
@@ -168,9 +162,11 @@ files:
|
|
168
162
|
- lib/bitmovin/encoding/encodings/muxings/ts_muxing_list.rb
|
169
163
|
- lib/bitmovin/encoding/encodings/muxings/webm_muxing.rb
|
170
164
|
- lib/bitmovin/encoding/encodings/muxings/webm_muxing_list.rb
|
165
|
+
- lib/bitmovin/encoding/encodings/sprites/sprite.rb
|
171
166
|
- lib/bitmovin/encoding/encodings/stream.rb
|
172
167
|
- lib/bitmovin/encoding/encodings/stream_input.rb
|
173
168
|
- lib/bitmovin/encoding/encodings/stream_list.rb
|
169
|
+
- lib/bitmovin/encoding/encodings/thumbnails/thumbnail.rb
|
174
170
|
- lib/bitmovin/encoding/inputs.rb
|
175
171
|
- lib/bitmovin/encoding/inputs/analysis.rb
|
176
172
|
- lib/bitmovin/encoding/inputs/analysis_task.rb
|
@@ -207,6 +203,7 @@ files:
|
|
207
203
|
- lib/bitmovin/resource.rb
|
208
204
|
- lib/bitmovin/version.rb
|
209
205
|
- lib/bitmovin/webhooks.rb
|
206
|
+
- lib/bitmovin/webhooks/encoding_error_webhook.rb
|
210
207
|
- lib/bitmovin/webhooks/encoding_finished_webhook.rb
|
211
208
|
- lib/bitmovin/webhooks/webhook_encryption.rb
|
212
209
|
- lib/bitmovin/webhooks/webhook_resource.rb
|
@@ -231,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
228
|
version: '0'
|
232
229
|
requirements: []
|
233
230
|
rubyforge_project:
|
234
|
-
rubygems_version: 2.6.
|
231
|
+
rubygems_version: 2.6.11
|
235
232
|
signing_key:
|
236
233
|
specification_version: 4
|
237
234
|
summary: Api Client for the Bitmovin API
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'bitmovin-ruby'
|
2
|
-
|
3
|
-
# Adding finished webhook to encoding
|
4
|
-
finished_webhook = Bitmovin::Webhooks::EncodingFinishedWebhook.new(
|
5
|
-
{
|
6
|
-
method: 'POST',
|
7
|
-
insecure_ssl: 'false',
|
8
|
-
url: 'http://httpbin.org/post',
|
9
|
-
encryption: Bitmovin::Webhooks::WebhookEncryption.new({
|
10
|
-
key: 'mySecretKey',
|
11
|
-
type: 'AES'
|
12
|
-
}),
|
13
|
-
signature: Bitmovin::Webhooks::WebhookSignature.new({
|
14
|
-
key: 'mySecretKey',
|
15
|
-
type: 'HMAC'
|
16
|
-
})
|
17
|
-
}
|
18
|
-
)
|
19
|
-
|
20
|
-
finished_webhook.save!
|
21
|
-
puts "Added finished webkook with id #{finished_webhook.id}!"
|
@@ -1,502 +0,0 @@
|
|
1
|
-
require 'bitmovin-ruby'
|
2
|
-
|
3
|
-
# CONFIGURATION
|
4
|
-
BITMOVIN_API_KEY = 'YOUR API KEY HERE'
|
5
|
-
|
6
|
-
S3_INPUT_ID = 'The ID of the Input'
|
7
|
-
S3_OUTPUT_ID = 'The ID of the Output'
|
8
|
-
OUTPUT_PATH = "/encoding_test/bitmovin-ruby/#{Time.now.strftime('%v-%H-%M')}/"
|
9
|
-
INPUT_FILE_PATH = 'your_input_file_name'
|
10
|
-
|
11
|
-
Bitmovin.init(BITMOVIN_API_KEY)
|
12
|
-
|
13
|
-
# This will create a Input Bucket you can reuse in future encodings
|
14
|
-
# To get a list of all your S3Inputs do:
|
15
|
-
# Bitmovin::Encoding::Inputs::S3Input.list
|
16
|
-
s3_input = Bitmovin::Encoding::Inputs::S3Input.find(S3_INPUT_ID)
|
17
|
-
|
18
|
-
# This will create a Output Bucket you can reuse in future encodings
|
19
|
-
# To get a list of all your Output do:
|
20
|
-
# Bitmovin::Encoding::Outputs::S3Output.list
|
21
|
-
s3_output = Bitmovin::Encoding::Outputs::S3Output.find(S3_OUTPUT_ID)
|
22
|
-
|
23
|
-
# Please note inputs/outputs are not individual files but rather the
|
24
|
-
# Bucket you are reading/writing files to and they can be reused between encodings.
|
25
|
-
|
26
|
-
|
27
|
-
# This hash contains the H264 Codec Configurations we want to create
|
28
|
-
# Codec Configurations are similar to Inputs/Outputs in that they are configured once
|
29
|
-
# and can be reused for future encodings.
|
30
|
-
video_configs = [
|
31
|
-
{name: 'h264_360p_600', profile: 'HIGH', height: 360, bitrate: 600000},
|
32
|
-
{name: 'h264_432p_700', profile: 'HIGH', height: 432, bitrate: 700000},
|
33
|
-
{name: 'h264_576p_1050', profile: 'HIGH', height: 576, bitrate: 1050000},
|
34
|
-
{name: 'h264_720p_1380', profile: 'HIGH', height: 720, bitrate: 1380000},
|
35
|
-
{name: 'h264_720p_1800', profile: 'HIGH', height: 720, bitrate: 1800000},
|
36
|
-
{name: 'h264_1080p_2150', profile: 'HIGH', height: 1080, bitrate: 2150000},
|
37
|
-
{name: 'h264_1080p_2900', profile: 'HIGH', height: 1080, bitrate: 2900000},
|
38
|
-
{name: 'h264_2160p_4000', profile: 'HIGH', height: 2160, bitrate: 4000000},
|
39
|
-
{name: 'h264_2160p_6000', profile: 'HIGH', height: 2160, bitrate: 6000000},
|
40
|
-
{name: 'h264_2160p_8500', profile: 'HIGH', height: 2160, bitrate: 8500000},
|
41
|
-
{name: 'h264_2160p_10000', profile: 'HIGH', height: 2160, bitrate: 10000000},
|
42
|
-
|
43
|
-
{name: 'h265_360p_420', profile: 'main', height: 360, bitrate: 420000},
|
44
|
-
{name: 'h265_432p_490', profile: 'main', height: 432, bitrate: 490000},
|
45
|
-
{name: 'h265_576p_735', profile: 'main', height: 576, bitrate: 735000},
|
46
|
-
{name: 'h265_720p_966', profile: 'main', height: 720, bitrate: 966000},
|
47
|
-
{name: 'h265_720p_1260', profile: 'main', height: 720, bitrate: 1260000},
|
48
|
-
{name: 'h265_1080p_1505', profile: 'main', height: 1080, bitrate: 1505000},
|
49
|
-
{name: 'h265_1080p_2030', profile: 'main', height: 1080, bitrate: 2030000},
|
50
|
-
{name: 'h265_2160p_2800', profile: 'main', height: 2160, bitrate: 2800000},
|
51
|
-
{name: 'h265_2160p_4200', profile: 'main', height: 2160, bitrate: 4200000},
|
52
|
-
{name: 'h265_2160p_5950', profile: 'main', height: 2160, bitrate: 5950000},
|
53
|
-
{name: 'h265_2160p_7000', profile: 'main', height: 2160, bitrate: 7000000}
|
54
|
-
]
|
55
|
-
|
56
|
-
# The actual instance of the encoding task you are about to start
|
57
|
-
enc = Bitmovin::Encoding::Encodings::EncodingTask.new({
|
58
|
-
name: 'VOD h264/h265 Encoding HLS'
|
59
|
-
})
|
60
|
-
enc.save!
|
61
|
-
|
62
|
-
# Create or load the Audio Config
|
63
|
-
#audio_config = Bitmovin::Encoding::CodecConfigurations::AacConfiguration.find("<EXISTING_AAC_CONFIG_ID>")
|
64
|
-
audio_config = Bitmovin::Encoding::CodecConfigurations::AacConfiguration.new({
|
65
|
-
name: 'AAC_PROFILE_128k',
|
66
|
-
bitrate: 128000,
|
67
|
-
rate: 48000
|
68
|
-
})
|
69
|
-
audio_config.save!
|
70
|
-
|
71
|
-
# Adding Audio Stream to Encoding
|
72
|
-
audio_stream = enc.streams.build(name: 'audio stream')
|
73
|
-
audio_stream.codec_configuration = audio_config
|
74
|
-
audio_stream.build_input_stream(input_path: INPUT_FILE_PATH, input_id: s3_input.id, selection_mode: 'AUTO')
|
75
|
-
audio_stream.conditions = {
|
76
|
-
type: 'CONDITION',
|
77
|
-
attribute: 'INPUTSTREAM',
|
78
|
-
operator: '==',
|
79
|
-
value: 'TRUE'
|
80
|
-
}
|
81
|
-
puts audio_stream.conditions.to_json
|
82
|
-
audio_stream.save!
|
83
|
-
|
84
|
-
# Audio Muxing
|
85
|
-
audio_muxing = enc.muxings.fmp4.build(name: 'audio-muxing', segment_length: 4)
|
86
|
-
audio_muxing.build_output({
|
87
|
-
output_id: s3_output.id,
|
88
|
-
output_path: File.join(OUTPUT_PATH, 'audio/aac')
|
89
|
-
})
|
90
|
-
audio_muxing.build_output({
|
91
|
-
output_id: s3_output.id,
|
92
|
-
output_path: File.join(OUTPUT_PATH, 'audio/aac'),
|
93
|
-
acl: [{
|
94
|
-
permission: 'PUBLIC_READ'
|
95
|
-
}]
|
96
|
-
})
|
97
|
-
audio_muxing.streams << audio_stream.id
|
98
|
-
audio_muxing.save!
|
99
|
-
|
100
|
-
# Let's also start the Manifest generation
|
101
|
-
# Multi Codec HLS Manifest
|
102
|
-
multi_hls_manifest = Bitmovin::Encoding::Manifests::HlsManifest.new({
|
103
|
-
name: 'Multi Codec HLS manifest',
|
104
|
-
description: 'Multi Codec HLS manifest',
|
105
|
-
manifest_name: 'multi_playlist.m3u8'
|
106
|
-
})
|
107
|
-
|
108
|
-
multi_hls_manifest.outputs << Bitmovin::Encoding::StreamOutput.new({
|
109
|
-
output_id: s3_output.id,
|
110
|
-
output_path: OUTPUT_PATH
|
111
|
-
})
|
112
|
-
multi_hls_manifest.save!
|
113
|
-
|
114
|
-
multi_hls_manifest.build_audio_medium({
|
115
|
-
name: 'HLS Audio Media',
|
116
|
-
group_id: 'audio_group',
|
117
|
-
segment_path: 'audio/aac',
|
118
|
-
encoding_id: enc.id,
|
119
|
-
stream_id: audio_stream.id,
|
120
|
-
muxing_id: audio_muxing.id,
|
121
|
-
language: 'en',
|
122
|
-
uri: 'audio_media.m3u8'
|
123
|
-
}).save!
|
124
|
-
|
125
|
-
# H264 HLS Manifest
|
126
|
-
h264_hls_manifest = Bitmovin::Encoding::Manifests::HlsManifest.new({
|
127
|
-
name: 'H264 HLS manifest',
|
128
|
-
description: 'Multi Codec HLS manifest',
|
129
|
-
manifest_name: 'h264_playlist.m3u8'
|
130
|
-
})
|
131
|
-
|
132
|
-
h264_hls_manifest.outputs << Bitmovin::Encoding::StreamOutput.new({
|
133
|
-
output_id: s3_output.id,
|
134
|
-
output_path: OUTPUT_PATH
|
135
|
-
})
|
136
|
-
h264_hls_manifest.save!
|
137
|
-
|
138
|
-
h264_hls_manifest.build_audio_medium({
|
139
|
-
name: 'HLS Audio Media',
|
140
|
-
group_id: 'audio_group',
|
141
|
-
segment_path: 'audio/aac',
|
142
|
-
encoding_id: enc.id,
|
143
|
-
stream_id: audio_stream.id,
|
144
|
-
muxing_id: audio_muxing.id,
|
145
|
-
language: 'en',
|
146
|
-
uri: 'audio_media.m3u8'
|
147
|
-
}).save!
|
148
|
-
# H265 HLS Manifest
|
149
|
-
h265_hls_manifest = Bitmovin::Encoding::Manifests::HlsManifest.new({
|
150
|
-
name: 'H265 HLS manifest',
|
151
|
-
description: 'Multi Codec HLS manifest',
|
152
|
-
manifest_name: 'h265_playlist.m3u8'
|
153
|
-
})
|
154
|
-
|
155
|
-
h265_hls_manifest.outputs << Bitmovin::Encoding::StreamOutput.new({
|
156
|
-
output_id: s3_output.id,
|
157
|
-
output_path: OUTPUT_PATH
|
158
|
-
})
|
159
|
-
h265_hls_manifest.save!
|
160
|
-
|
161
|
-
h265_hls_manifest.build_audio_medium({
|
162
|
-
name: 'HLS Audio Media',
|
163
|
-
group_id: 'audio_group',
|
164
|
-
segment_path: 'audio/aac',
|
165
|
-
encoding_id: enc.id,
|
166
|
-
stream_id: audio_stream.id,
|
167
|
-
muxing_id: audio_muxing.id,
|
168
|
-
language: 'en',
|
169
|
-
uri: 'audio_media.m3u8'
|
170
|
-
}).save!
|
171
|
-
|
172
|
-
hls_manifests = [multi_hls_manifest, h264_hls_manifest, h265_hls_manifest]
|
173
|
-
|
174
|
-
# H264 DASH Manifest
|
175
|
-
h264_dash_manifest = Bitmovin::Encoding::Manifests::DashManifest.new({
|
176
|
-
name: 'H264 DASH Manifest',
|
177
|
-
description: 'H264 DASH Manifest',
|
178
|
-
manifest_name: 'h264_manifest.mpd'
|
179
|
-
})
|
180
|
-
|
181
|
-
h264_dash_manifest.outputs << Bitmovin::Encoding::StreamOutput.new({
|
182
|
-
output_id: s3_output.id,
|
183
|
-
output_path: OUTPUT_PATH
|
184
|
-
})
|
185
|
-
h264_dash_manifest.save!
|
186
|
-
|
187
|
-
h264_period = Bitmovin::Encoding::Manifests::Period.new(
|
188
|
-
h264_dash_manifest.id
|
189
|
-
)
|
190
|
-
h264_period.save!
|
191
|
-
|
192
|
-
h264_video_adaptation_set = Bitmovin::Encoding::Manifests::VideoAdaptationSet.new(
|
193
|
-
h264_dash_manifest.id,
|
194
|
-
h264_period.id
|
195
|
-
)
|
196
|
-
h264_video_adaptation_set.save!
|
197
|
-
|
198
|
-
# Adding Audio Stream to H264 DASH Manifest
|
199
|
-
audio_adaptation_set = Bitmovin::Encoding::Manifests::AudioAdaptationSet.new(
|
200
|
-
h264_dash_manifest.id,
|
201
|
-
h264_period.id
|
202
|
-
)
|
203
|
-
audio_adaptation_set.save!
|
204
|
-
|
205
|
-
audio_adaptation_set.build_fmp4_representation({
|
206
|
-
encoding_id: enc.id,
|
207
|
-
muxing_id: audio_muxing.id,
|
208
|
-
segment_path: 'audio/aac',
|
209
|
-
type: 'TEMPLATE',
|
210
|
-
name: 'Audio Adaptation Set'
|
211
|
-
|
212
|
-
}).save!
|
213
|
-
|
214
|
-
# H265 DASH Manifest
|
215
|
-
h265_dash_manifest = Bitmovin::Encoding::Manifests::DashManifest.new({
|
216
|
-
name: 'H265 DASH Manifest',
|
217
|
-
description: 'H265 DASH Manifest',
|
218
|
-
manifest_name: 'h265_manifest.mpd'
|
219
|
-
})
|
220
|
-
|
221
|
-
h265_dash_manifest.outputs << Bitmovin::Encoding::StreamOutput.new({
|
222
|
-
output_id: s3_output.id,
|
223
|
-
output_path: OUTPUT_PATH
|
224
|
-
})
|
225
|
-
h265_dash_manifest.save!
|
226
|
-
|
227
|
-
h265_period = Bitmovin::Encoding::Manifests::Period.new(
|
228
|
-
h265_dash_manifest.id
|
229
|
-
)
|
230
|
-
h265_period.save!
|
231
|
-
|
232
|
-
h265_video_adaptation_set = Bitmovin::Encoding::Manifests::VideoAdaptationSet.new(
|
233
|
-
h265_dash_manifest.id,
|
234
|
-
h265_period.id
|
235
|
-
)
|
236
|
-
h265_video_adaptation_set.save!
|
237
|
-
|
238
|
-
# Adding Audio Stream to H265 DASH Manifest
|
239
|
-
audio_adaptation_set = Bitmovin::Encoding::Manifests::AudioAdaptationSet.new(
|
240
|
-
h265_dash_manifest.id,
|
241
|
-
h265_period.id
|
242
|
-
)
|
243
|
-
audio_adaptation_set.save!
|
244
|
-
|
245
|
-
audio_adaptation_set.build_fmp4_representation({
|
246
|
-
encoding_id: enc.id,
|
247
|
-
muxing_id: audio_muxing.id,
|
248
|
-
segment_path: 'audio/aac',
|
249
|
-
type: 'TEMPLATE',
|
250
|
-
name: 'Audio Adaptation Set'
|
251
|
-
|
252
|
-
}).save!
|
253
|
-
|
254
|
-
# Multi Codec DASH manifest
|
255
|
-
multi_codec_dash_manifest = Bitmovin::Encoding::Manifests::DashManifest.new({
|
256
|
-
name: 'MULTI CODEC DASH Manifest',
|
257
|
-
description: 'MULTI CODEC DASH Manifest',
|
258
|
-
manifest_name: 'multi_codec_manifest.mpd'
|
259
|
-
})
|
260
|
-
|
261
|
-
multi_codec_dash_manifest.outputs << Bitmovin::Encoding::StreamOutput.new({
|
262
|
-
output_id: s3_output.id,
|
263
|
-
output_path: OUTPUT_PATH
|
264
|
-
})
|
265
|
-
multi_codec_dash_manifest.save!
|
266
|
-
|
267
|
-
multi_codec_period = Bitmovin::Encoding::Manifests::Period.new(
|
268
|
-
multi_codec_dash_manifest.id
|
269
|
-
).save!
|
270
|
-
|
271
|
-
multi_h265_adaptation_set = Bitmovin::Encoding::Manifests::VideoAdaptationSet.new(
|
272
|
-
multi_codec_dash_manifest.id,
|
273
|
-
multi_codec_period.id
|
274
|
-
).save!
|
275
|
-
|
276
|
-
multi_h264_adaptation_set = Bitmovin::Encoding::Manifests::VideoAdaptationSet.new(
|
277
|
-
multi_codec_dash_manifest.id,
|
278
|
-
multi_codec_period.id
|
279
|
-
).save!
|
280
|
-
|
281
|
-
# Adding Audio Stream to Multi Codec DASH Manifest
|
282
|
-
audio_adaptation_set = Bitmovin::Encoding::Manifests::AudioAdaptationSet.new(
|
283
|
-
multi_codec_dash_manifest.id,
|
284
|
-
multi_codec_period.id
|
285
|
-
).save!
|
286
|
-
|
287
|
-
audio_adaptation_set.build_fmp4_representation({
|
288
|
-
encoding_id: enc.id,
|
289
|
-
muxing_id: audio_muxing.id,
|
290
|
-
segment_path: 'audio/aac',
|
291
|
-
type: 'TEMPLATE',
|
292
|
-
name: 'Audio Adaptation Set'
|
293
|
-
|
294
|
-
}).save!
|
295
|
-
|
296
|
-
dash_manifests = [multi_codec_dash_manifest, h264_dash_manifest, h265_dash_manifest]
|
297
|
-
|
298
|
-
def create_mp4(streams, name, enc, s3_output)
|
299
|
-
mp4_muxing = enc.muxings.mp4.build(name: "MP4 #{name} muxing", filename: "#{name}.mp4")
|
300
|
-
mp4_muxing.streams << streams.map {|stream| stream.id}
|
301
|
-
mp4_muxing.streams.flatten!
|
302
|
-
mp4_muxing.build_output({
|
303
|
-
output_id: s3_output.id,
|
304
|
-
output_path: File.join(OUTPUT_PATH, name),
|
305
|
-
acl: [{
|
306
|
-
permission: 'PUBLIC_READ'
|
307
|
-
}]
|
308
|
-
})
|
309
|
-
|
310
|
-
mp4_muxing.save!
|
311
|
-
puts "Added MP4 muxing #{mp4_muxing.name}"
|
312
|
-
end
|
313
|
-
|
314
|
-
# Adding Video Streams to Encoding
|
315
|
-
video_configs.each do |config|
|
316
|
-
|
317
|
-
if config[:name].start_with?('h264')
|
318
|
-
video_config_type = 'H264'
|
319
|
-
elsif config[:name].start_with?('h265')
|
320
|
-
video_config_type = 'H265'
|
321
|
-
else
|
322
|
-
video_config_type = 'NONE'
|
323
|
-
end
|
324
|
-
|
325
|
-
if video_config_type == 'H264'
|
326
|
-
codec_config = Bitmovin::Encoding::CodecConfigurations::H264Configuration.new(config).save!
|
327
|
-
config = OpenStruct.new(config)
|
328
|
-
|
329
|
-
str = enc.streams.build(name: codec_config.name)
|
330
|
-
str.codec_configuration = codec_config
|
331
|
-
str.build_input_stream(input_path: INPUT_FILE_PATH, input_id: s3_input.id, selection_mode: 'AUTO')
|
332
|
-
str.conditions = {
|
333
|
-
type: 'CONDITION',
|
334
|
-
attribute: 'HEIGHT',
|
335
|
-
operator: '>=',
|
336
|
-
value: codec_config.height
|
337
|
-
}
|
338
|
-
str.save!
|
339
|
-
|
340
|
-
create_mp4([str, audio_stream], codec_config.name, enc, s3_output)
|
341
|
-
|
342
|
-
fmp4_muxing = enc.muxings.fmp4.build(name: "#{codec_config.name} muxing", segment_length: 4)
|
343
|
-
fmp4_muxing.streams << str.id
|
344
|
-
fmp4_muxing.build_output({
|
345
|
-
output_id: s3_output.id,
|
346
|
-
output_path: File.join(OUTPUT_PATH, config.name),
|
347
|
-
acl: [{
|
348
|
-
permission: 'PUBLIC_READ'
|
349
|
-
}]
|
350
|
-
})
|
351
|
-
fmp4_muxing.save!
|
352
|
-
puts "Added FMP4 muxing #{fmp4_muxing.name}"
|
353
|
-
|
354
|
-
h264_video_adaptation_set.build_fmp4_representation(
|
355
|
-
encoding_id: enc.id,
|
356
|
-
muxing_id: fmp4_muxing.id,
|
357
|
-
type: 'TEMPLATE',
|
358
|
-
segment_path: config.name
|
359
|
-
).save!
|
360
|
-
puts "Added muxing #{fmp4_muxing.name} to #{video_config_type} only DASH manifest"
|
361
|
-
|
362
|
-
multi_h264_adaptation_set.build_fmp4_representation(
|
363
|
-
encoding_id: enc.id,
|
364
|
-
muxing_id: fmp4_muxing.id,
|
365
|
-
type: 'TEMPLATE',
|
366
|
-
segment_path: config.name
|
367
|
-
).save!
|
368
|
-
puts "Added muxing #{fmp4_muxing.name} to multi codec DASH manifest"
|
369
|
-
|
370
|
-
h264_hls_manifest.build_stream({
|
371
|
-
audio: 'audio_group',
|
372
|
-
closed_captions: 'NONE',
|
373
|
-
segmentPath: config.name,
|
374
|
-
encoding_id: enc.id,
|
375
|
-
muxing_id: fmp4_muxing.id,
|
376
|
-
stream_id: str.id,
|
377
|
-
uri: config.name + '.m3u8'
|
378
|
-
}).save!
|
379
|
-
|
380
|
-
puts "Added muxing #{fmp4_muxing.name} to #{video_config_type} HLS manifest"
|
381
|
-
else
|
382
|
-
codec_config = Bitmovin::Encoding::CodecConfigurations::H265Configuration.new(config)
|
383
|
-
codec_config.save!
|
384
|
-
config = OpenStruct.new(config)
|
385
|
-
|
386
|
-
str = enc.streams.build(name: codec_config.name)
|
387
|
-
str.codec_configuration = codec_config
|
388
|
-
str.build_input_stream(input_path: INPUT_FILE_PATH, input_id: s3_input.id, selection_mode: 'AUTO')
|
389
|
-
str.conditions = {
|
390
|
-
type: 'CONDITION',
|
391
|
-
attribute: 'HEIGHT',
|
392
|
-
operator: '>=',
|
393
|
-
value: codec_config.height
|
394
|
-
}
|
395
|
-
str.save!
|
396
|
-
|
397
|
-
create_mp4([str, audio_stream], codec_config.name, enc, s3_output)
|
398
|
-
|
399
|
-
fmp4_muxing = enc.muxings.fmp4.build(name: "#{codec_config.name} muxing", segment_length: 4)
|
400
|
-
fmp4_muxing.streams << str.id
|
401
|
-
fmp4_muxing.build_output({
|
402
|
-
output_id: s3_output.id,
|
403
|
-
output_path: File.join(OUTPUT_PATH, config.name),
|
404
|
-
acl: [{
|
405
|
-
permission: 'PUBLIC_READ'
|
406
|
-
}]
|
407
|
-
})
|
408
|
-
fmp4_muxing.save!
|
409
|
-
puts "Added FMP4 muxing #{fmp4_muxing.name}"
|
410
|
-
|
411
|
-
h265_video_adaptation_set.build_fmp4_representation(
|
412
|
-
encoding_id: enc.id,
|
413
|
-
muxing_id: fmp4_muxing.id,
|
414
|
-
type: 'TEMPLATE',
|
415
|
-
segment_path: config.name
|
416
|
-
).save!
|
417
|
-
puts "Added muxing #{fmp4_muxing.name} to #{video_config_type} only DASH manifest"
|
418
|
-
|
419
|
-
multi_h265_adaptation_set.build_fmp4_representation(
|
420
|
-
encoding_id: enc.id,
|
421
|
-
muxing_id: fmp4_muxing.id,
|
422
|
-
type: 'TEMPLATE',
|
423
|
-
segment_path: config.name
|
424
|
-
).save!
|
425
|
-
puts "Added muxing #{fmp4_muxing.name} to multi codec DASH manifest"
|
426
|
-
|
427
|
-
h265_hls_manifest.build_stream({
|
428
|
-
audio: 'audio_group',
|
429
|
-
closed_captions: 'NONE',
|
430
|
-
segmentPath: config.name,
|
431
|
-
encoding_id: enc.id,
|
432
|
-
muxing_id: fmp4_muxing.id,
|
433
|
-
stream_id: str.id,
|
434
|
-
uri: config.name + '.m3u8'
|
435
|
-
}).save!
|
436
|
-
|
437
|
-
puts "Added muxing #{fmp4_muxing.name} to #{video_config_type} HLS manifest"
|
438
|
-
end
|
439
|
-
|
440
|
-
# Add the Stream to the multi codec HLS Manifest
|
441
|
-
multi_hls_manifest.build_stream({
|
442
|
-
audio: 'audio_group',
|
443
|
-
closed_captions: 'NONE',
|
444
|
-
segmentPath: config.name,
|
445
|
-
encoding_id: enc.id,
|
446
|
-
muxing_id: fmp4_muxing.id,
|
447
|
-
stream_id: str.id,
|
448
|
-
uri: config.name + '.m3u8'
|
449
|
-
}).save!
|
450
|
-
|
451
|
-
puts "Added muxing #{fmp4_muxing.name} to multi codec HLS manifest"
|
452
|
-
end
|
453
|
-
|
454
|
-
# Starting an encoding and monitoring it's status
|
455
|
-
enc.start!
|
456
|
-
|
457
|
-
while enc.status != 'FINISHED' && enc.status != 'ERROR'
|
458
|
-
puts "Encoding Status is #{enc.status}"
|
459
|
-
progress = enc.progress
|
460
|
-
if progress > 0
|
461
|
-
puts "Progress: #{enc.progress} %"
|
462
|
-
end
|
463
|
-
sleep 2
|
464
|
-
end
|
465
|
-
puts "Encoding finished with status #{enc.status}!"
|
466
|
-
|
467
|
-
# Now that the encoding is finished we can start writing the m3u8 Manifest
|
468
|
-
hls_manifests.each do |hls_manifest|
|
469
|
-
|
470
|
-
hls_manifest.start!
|
471
|
-
|
472
|
-
while hls_manifest.status != 'FINISHED' && hls_manifest.status != 'ERROR'
|
473
|
-
puts "HLS Manifest status is #{hls_manifest.status}"
|
474
|
-
progress = hls_manifest.progress
|
475
|
-
if progress > 0
|
476
|
-
puts "Progress: #{hls_manifest.progress} %"
|
477
|
-
end
|
478
|
-
sleep 2
|
479
|
-
end
|
480
|
-
|
481
|
-
puts "HLS Manifest generation #{hls_manifest.name} finished with status #{hls_manifest.status}"
|
482
|
-
|
483
|
-
end
|
484
|
-
|
485
|
-
# Begin DASH manifests generation
|
486
|
-
dash_manifests.each do |dash_manifest|
|
487
|
-
|
488
|
-
dash_manifest.start!
|
489
|
-
|
490
|
-
while dash_manifest.status != 'FINISHED' && dash_manifest.status != 'ERROR'
|
491
|
-
puts "DASH manifest generation status is #{dash_manifest.status}"
|
492
|
-
progress = dash_manifest.progress
|
493
|
-
if progress > 0
|
494
|
-
puts "Progress: #{dash_manifest.progress}"
|
495
|
-
end
|
496
|
-
sleep 2
|
497
|
-
end
|
498
|
-
|
499
|
-
puts "DASH Manifest generation #{dash_manifest.name} finished with status #{dash_manifest.status}"
|
500
|
-
end
|
501
|
-
|
502
|
-
puts 'All Manifests generated!'
|