Skip to content

Commit

Permalink
Add highdef video definitions for Zencoder
Browse files Browse the repository at this point in the history
Added definitions are fullhd (1080p) und 4k (2160p).

Highdef outputs are only generated if feature 'highdef_video_encoding'
has state `true`.

Highdef outputs are only generated if source resolution exceeds
min_size.
  • Loading branch information
aviav authored and tf committed Oct 20, 2016
1 parent 0b263c0 commit 02527db
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 108 deletions.
8 changes: 8 additions & 0 deletions app/models/pageflow/video_file.rb
Expand Up @@ -50,6 +50,14 @@ def webm_medium
end


def mp4_4k
ZencoderAttachment.new(self, "4k.mp4")
end

def mp4_fullhd
ZencoderAttachment.new(self, "fullhd.mp4")
end

def mp4_high
ZencoderAttachment.new(self, "high.mp4")
end
Expand Down
1 change: 1 addition & 0 deletions config/initializers/features.rb
Expand Up @@ -5,6 +5,7 @@

config.features.register('auto_change_page')
config.features.register('delayed_text_fade_in')
config.features.register('highdef_video_encoding')
config.features.register('storylines') do |feature_config|
feature_config.help_entries.register('pageflow.help_entries.storylines', priority: 7)
end
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/zencoder.rb
Expand Up @@ -12,7 +12,7 @@
Pageflow::ZencoderOutputDefinition.default_akamai_host = zencoder_options[:akamai_host]
Pageflow::ZencoderOutputDefinition.default_akamai_credentials = zencoder_options[:akamai_credentials]
Pageflow::ZencoderVideoOutputDefinition.skip_hls = zencoder_options.fetch(:skip_hls, false)
Pageflow::ZencoderVideoOutputDefinition.skip_smil = zencoder_options.fetch(:skip_hls, false)
Pageflow::ZencoderVideoOutputDefinition.skip_smil = zencoder_options.fetch(:skip_smil, false)

raise "Missing s3_host_alias option in Pageflow.config.zencoder_options." unless zencoder_options.has_key?(:s3_host_alias)
raise "Missing s3_protocol option in Pageflow.config.zencoder_options." unless zencoder_options.has_key?(:s3_protocol)
Expand Down
4 changes: 4 additions & 0 deletions config/locales/new/highdef_video_encoding.de.yml
@@ -0,0 +1,4 @@
de:
pageflow:
highdef_video_encoding:
feature_name: "Full HD und 4K Videos"
4 changes: 4 additions & 0 deletions config/locales/new/highdef_video_encoding.en.yml
@@ -0,0 +1,4 @@
en:
pageflow:
highdef_video_encoding:
feature_name: "Full HD and 4K videos"
249 changes: 142 additions & 107 deletions lib/pageflow/zencoder_video_output_definition.rb
Expand Up @@ -17,6 +17,8 @@ def outputs
[
transferable(webm_high_definition),
transferable(webm_medium_definition),

mp4_highdef_definitions,
transferable(mp4_high_definition),
transferable(mp4_medium_definition),
transferable(mp4_low_definition),
Expand All @@ -32,80 +34,117 @@ def outputs

def webm_high_definition
{
:label => 'webm_high',
:format => 'webm',
:path => video_file.webm_high.path,
:size => '1280x720',
:quality => 4,
:max_video_bitrate => 3500,
:public => 1,
:sharpen => true
label: 'webm_high',
format: 'webm',
path: video_file.webm_high.path,
size: '1280x720',
quality: 4,
max_video_bitrate: 3500,
public: 1,
sharpen: true
}
end

def webm_medium_definition
{
:label => 'webm_medium',
:format => 'webm',
:path => video_file.webm_medium.path,
:size => '1280x720',
:quality => 3,
:max_video_bitrate => 2000,
:public => 1,
:sharpen => true
label: 'webm_medium',
format: 'webm',
path: video_file.webm_medium.path,
size: '1280x720',
quality: 3,
max_video_bitrate: 2000,
public: 1,
sharpen: true
}
end

def mp4_highdef_definitions
return [] unless video_file.entry.feature_state('highdef_video_encoding')
[transferable(mp4_4k_definition), transferable(mp4_fullhd_definition)]
end

def mp4_4k_definition
{
label: '4k',
prepare_for_segmenting: ['hls', 'dash'],
path: video_file.mp4_4k.path,
video_bitrate: 22000,
decoder_bitrate_cap: 24420,
decoder_buffer_size: 36631,
audio_bitrate: 320,
size: '3839x2160',
skip: {
min_size: '1920x1080'
},
public: 1,
}
end

def mp4_fullhd_definition
{
label: 'fullhd',
prepare_for_segmenting: ['hls', 'dash'],
path: video_file.mp4_fullhd.path,
video_bitrate: 6000,
decoder_bitrate_cap: 6660,
decoder_buffer_size: 9990,
audio_bitrate: 192,
size: '1919x1080',
skip: {
min_size: '1281x720'
},
public: 1,
}
end

def mp4_high_definition
{
:label => 'high',
:format => 'mp4',
:path => video_file.mp4_high.path,
:h264_level => 3.1,
:max_frame_rate => 30,
:max_video_bitrate => 3500,
:audio_bitrate => 192,
:h264_profile => 'main',
:size => '1280x720',
:public => 1,
:forced_keyframe_rate => '0.5',
:tuning => "film",
:sharpen => true
label: 'high',
format: 'mp4',
path: video_file.mp4_high.path,
h264_level: 3.1,
max_frame_rate: 30,
max_video_bitrate: 3500,
audio_bitrate: 192,
h264_profile: 'main',
size: '1280x720',
public: 1,
forced_keyframe_rate: '0.5',
tuning: 'film',
sharpen: true
}
end

def mp4_medium_definition
{
:label => 'medium',
:format => 'mp4',
:path => video_file.mp4_medium.path,
:h264_level => 3.1,
:max_frame_rate => 30,
:max_video_bitrate => 2000,
:audio_bitrate => 128,
:h264_profile => 'main',
:size => '1280x720',
:forced_keyframe_rate => '0.5',
:public => 1,
:sharpen => true
label: 'medium',
format: 'mp4',
path: video_file.mp4_medium.path,
h264_level: 3.1,
max_frame_rate: 30,
max_video_bitrate: 2000,
audio_bitrate: 128,
h264_profile: 'main',
size: '1280x720',
forced_keyframe_rate: '0.5',
public: 1,
sharpen: true
}
end

def mp4_low_definition
{
:label => 'low',
:format => 'mp4',
:path => video_file.mp4_low.path,
:device_profile => 'mobile/legacy',
:audio_bitrate => 56,
:forced_keyframe_rate => '0.5',
:public => 1,
:sharpen => true
label: 'low',
format: 'mp4',
path: video_file.mp4_low.path,
device_profile: 'mobile/legacy',
audio_bitrate: 56,
forced_keyframe_rate: '0.5',
public: 1,
sharpen: true
}
end


def hls_definitions
return [] if skip_hls

Expand All @@ -119,66 +158,66 @@ def hls_definitions

def hls_low_definition
{
:label => 'hls-low',
:format => 'ts',
:source => 'low',
:copy_audio => 'true',
:copy_video => 'true',
:path => video_file.hls_low.path,
:type => 'segmented',
:public => 1
label: 'hls-low',
format: 'ts',
source: 'low',
copy_audio: 'true',
copy_video: 'true',
path: video_file.hls_low.path,
type: 'segmented',
public: 1
}
end

def hls_medium_definition
{
:label => 'hls-medium',
:format => 'ts',
:source => 'medium',
:copy_audio => 'true',
:copy_video => 'true',
:path => video_file.hls_medium.path,
:type => 'segmented',
:public => 1
label: 'hls-medium',
format: 'ts',
source: 'medium',
copy_audio: 'true',
copy_video: 'true',
path: video_file.hls_medium.path,
type: 'segmented',
public: 1
}
end

def hls_high_definition
{
:label => 'hls-high',
:format => 'ts',
:source => 'high',
:copy_audio => 'true',
:copy_video => 'true',
:path => video_file.hls_high.path,
:type => 'segmented',
:public => 1
label: 'hls-high',
format: 'ts',
source: 'high',
copy_audio: 'true',
copy_video: 'true',
path: video_file.hls_high.path,
type: 'segmented',
public: 1
}
end

def hls_playlist_definition
{
:label => 'hls-playlist',
:streams => hls_stream_definitions,
:type => 'playlist',
:path => video_file.hls_playlist.path,
:public => 1
label: 'hls-playlist',
streams: hls_stream_definitions,
type: 'playlist',
path: video_file.hls_playlist.path,
public: 1
}
end

def hls_stream_definitions
[
{
:path => video_file.hls_medium.url(host: :hls_origin, default_protocol: 'http'),
:bandwidth => 2250
path: video_file.hls_medium.url(host: :hls_origin, default_protocol: 'http'),
bandwidth: 2250
},
{
:path => video_file.hls_low.url(host: :hls_origin, default_protocol: 'http'),
:bandwidth => 256
path: video_file.hls_low.url(host: :hls_origin, default_protocol: 'http'),
bandwidth: 256
},
{
:path => video_file.hls_high.url(host: :hls_origin, default_protocol: 'http'),
:bandwidth => 3750
path: video_file.hls_high.url(host: :hls_origin, default_protocol: 'http'),
bandwidth: 3750
}
]
end
Expand All @@ -197,12 +236,12 @@ def smil_definition
def smil_stream_definitions
[
{
:path => video_file.mp4_medium.url(host: :hls_origin, default_protocol: 'http'),
:bandwidth => 2250
path: video_file.mp4_medium.url(host: :hls_origin, default_protocol: 'http'),
bandwidth: 2250
},
{
:path => video_file.mp4_low.url(host: :hls_origin, default_protocol: 'http'),
:bandwidth => 256
path: video_file.mp4_low.url(host: :hls_origin, default_protocol: 'http'),
bandwidth: 256
},
{
path: video_file.mp4_high.url(host: :hls_origin, default_protocol: 'http'),
Expand All @@ -223,24 +262,20 @@ def thumbnails_definitions

def thumbnails_definition(url_helper)
{
:thumbnails => [
with_credentials({
:label => 'poster',
:format => video_file.zencoder_poster.format,
:number => 1,
:start_at_first_frame => true,
:filename => video_file.zencoder_poster.base_name_pattern,
:base_url => url_helper.call(video_file.zencoder_poster.dir_name),
:public => 1
}),
with_credentials({
:label => 'thumbnail',
:format => video_file.zencoder_thumbnail.format,
:number => 1,
:filename => video_file.zencoder_thumbnail.base_name_pattern,
:base_url => url_helper.call(video_file.zencoder_thumbnail.dir_name),
:public => 1
})
thumbnails: [
with_credentials(label: 'poster',
format: video_file.zencoder_poster.format,
number: 1,
start_at_first_frame: true,
filename: video_file.zencoder_poster.base_name_pattern,
base_url: url_helper.call(video_file.zencoder_poster.dir_name),
public: 1),
with_credentials(label: 'thumbnail',
format: video_file.zencoder_thumbnail.format,
number: 1,
filename: video_file.zencoder_thumbnail.base_name_pattern,
base_url: url_helper.call(video_file.zencoder_thumbnail.dir_name),
public: 1)
]
}
end
Expand Down

0 comments on commit 02527db

Please sign in to comment.