Class: Shotstack::Rendition

Inherits:
Object
  • Object
show all
Defined in:
lib/shotstack/models/rendition.rb

Overview

A rendition is a new output file that is generated from the source. The rendition can be encoded to a different format and have transformations applied to it such as resizing, cropping, etc…

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Rendition

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/shotstack/models/rendition.rb', line 113

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `Shotstack::Rendition` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Shotstack::Rendition`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'format')
    self.format = attributes[:'format']
  end

  if attributes.key?(:'size')
    self.size = attributes[:'size']
  end

  if attributes.key?(:'fit')
    self.fit = attributes[:'fit']
  end

  if attributes.key?(:'resolution')
    self.resolution = attributes[:'resolution']
  end

  if attributes.key?(:'quality')
    self.quality = attributes[:'quality']
  end

  if attributes.key?(:'fps')
    self.fps = attributes[:'fps']
  end

  if attributes.key?(:'speed')
    self.speed = attributes[:'speed']
  end

  if attributes.key?(:'keyframe_interval')
    self.keyframe_interval = attributes[:'keyframe_interval']
  end

  if attributes.key?(:'enhance')
    self.enhance = attributes[:'enhance']
  end

  if attributes.key?(:'filename')
    self.filename = attributes[:'filename']
  end
end

Instance Attribute Details

#enhanceObject

Returns the value of attribute enhance.



41
42
43
# File 'lib/shotstack/models/rendition.rb', line 41

def enhance
  @enhance
end

#filenameObject

A custom name for the generated rendition file. The file extension will be automatically added based on the format of the rendition. If no filename is provided, the rendition ID will be used.



44
45
46
# File 'lib/shotstack/models/rendition.rb', line 44

def filename
  @filename
end

#fitObject

Set how the rendition should be scaled and cropped when using a size with an aspect ratio that is different from the source. Fit applies to both videos and images. <ul> <li>‘crop` (default) - scale the rendition to fill the output area while maintaining the aspect ratio. The rendition will be cropped if it exceeds the bounds of the output.</li> <li>`cover` - stretch the rendition to fill the output without maintaining the aspect ratio.</li> <li>`contain` - fit the entire rendition within the output while maintaining the original aspect ratio.</li> </ul>



25
26
27
# File 'lib/shotstack/models/rendition.rb', line 25

def fit
  @fit
end

#formatObject

The output format to encode the file to. You can only encode a file to the same type, i.e. a video to a video or an image to an image. You can’t encode a video as an image. The following formats are available: <ul> <li>‘mp4` - mp4 video file (video only)</li> <li>`webm` - webm video file (video only)</li> <li>`mov` - mov video file (video only)</li> <li>`avi` - avi video file (video only)</li> <li>`mkv` - mkv video file (video only)</li> <li>`ogv` - ogv video file (video only)</li> <li>`wmv` - wmv video file (video only)</li> <li>`avif` - avif video file (video only)</li> <li>`gif` - animated gif file (video only)</li> <li>`jpg` - jpg image file (image only)</li> <li>`png` - png image file (image only)</li> <li>`webp` - webp image file (image only)</li> <li>`tif` - tif image file (image only)</li> <li>`mp3` - mp3 audio file (audio only)</li> <li>`wav` - wav audio file (audio only)</li> </ul>



20
21
22
# File 'lib/shotstack/models/rendition.rb', line 20

def format
  @format
end

#fpsObject

Change the frame rate of a video asset. <ul> <li>‘12` - 12fps</li> <li>`15` - 15fps</li> <li>`24` - 24fps</li> <li>`23.976` - 23.976fps</li> <li>`25` (default) - 25fps</li> <li>`29.97` - 29.97fps</li> <li>`30` - 30fps</li> <li>`48` - 48fps</li> <li>`50` - 50fps</li> <li>`59.94` - 59.94fps</li> <li>`60` - 60fps</li> </ul>



34
35
36
# File 'lib/shotstack/models/rendition.rb', line 34

def fps
  @fps
end

#keyframe_intervalObject

The keyframe interval is useful to optimize playback, seeking and smoother scrubbing in browsers. The value sets the number of frames between a keyframe. The lower the number, the larger the file. Try a value between 10 and 25 for smooth scrubbing.



39
40
41
# File 'lib/shotstack/models/rendition.rb', line 39

def keyframe_interval
  @keyframe_interval
end

#qualityObject

Adjust the visual quality of the video or image. The higher the value, the sharper the image quality but the larger file size and slower the encoding process. When specifying quality, the goal is to balance file size vs visual quality. Quality is a value between 1 and 100 where 1 is fully compressed with low image quality and 100 is close to lossless with high image quality and large file size. Sane values are between 50 and 75. Omitting the quality parameter will result in an asset optimised for encoding speed, file size and visual quality.



31
32
33
# File 'lib/shotstack/models/rendition.rb', line 31

def quality
  @quality
end

#resolutionObject

The preset output resolution of the video or image. This is a convenience property that sets the width and height based on industry standard resolutions. The following resolutions are available: <ul> <li>‘preview` - 512px x 288px</li> <li>`mobile` - 640px x 360px</li> <li>`sd` - 1024px x 576px</li> <li>`hd` - 1280px x 720px</li> <li>`fhd` - 1920px x 1080px</li> </ul>



28
29
30
# File 'lib/shotstack/models/rendition.rb', line 28

def resolution
  @resolution
end

#sizeObject

Returns the value of attribute size.



22
23
24
# File 'lib/shotstack/models/rendition.rb', line 22

def size
  @size
end

#speedObject

Returns the value of attribute speed.



36
37
38
# File 'lib/shotstack/models/rendition.rb', line 36

def speed
  @speed
end

Class Method Details

._deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/shotstack/models/rendition.rb', line 342

def self._deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = Shotstack.const_get(type)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



85
86
87
# File 'lib/shotstack/models/rendition.rb', line 85

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/shotstack/models/rendition.rb', line 69

def self.attribute_map
  {
    :'format' => :'format',
    :'size' => :'size',
    :'fit' => :'fit',
    :'resolution' => :'resolution',
    :'quality' => :'quality',
    :'fps' => :'fps',
    :'speed' => :'speed',
    :'keyframe_interval' => :'keyframeInterval',
    :'enhance' => :'enhance',
    :'filename' => :'filename'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/shotstack/models/rendition.rb', line 318

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



106
107
108
109
# File 'lib/shotstack/models/rendition.rb', line 106

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_typesObject

Attribute type mapping.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/shotstack/models/rendition.rb', line 90

def self.openapi_types
  {
    :'format' => :'String',
    :'size' => :'Size',
    :'fit' => :'String',
    :'resolution' => :'String',
    :'quality' => :'Integer',
    :'fps' => :'Float',
    :'speed' => :'Speed',
    :'keyframe_interval' => :'Integer',
    :'enhance' => :'Enhancements',
    :'filename' => :'String'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/shotstack/models/rendition.rb', line 288

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      format == o.format &&
      size == o.size &&
      fit == o.fit &&
      resolution == o.resolution &&
      quality == o.quality &&
      fps == o.fps &&
      speed == o.speed &&
      keyframe_interval == o.keyframe_interval &&
      enhance == o.enhance &&
      filename == o.filename
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/shotstack/models/rendition.rb', line 413

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


305
306
307
# File 'lib/shotstack/models/rendition.rb', line 305

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



311
312
313
# File 'lib/shotstack/models/rendition.rb', line 311

def hash
  [format, size, fit, resolution, quality, fps, speed, keyframe_interval, enhance, filename].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/shotstack/models/rendition.rb', line 169

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if !@quality.nil? && @quality > 100
    invalid_properties.push('invalid value for "quality", must be smaller than or equal to 100.')
  end

  if !@quality.nil? && @quality < 1
    invalid_properties.push('invalid value for "quality", must be greater than or equal to 1.')
  end

  if !@keyframe_interval.nil? && @keyframe_interval > 300
    invalid_properties.push('invalid value for "keyframe_interval", must be smaller than or equal to 300.')
  end

  if !@keyframe_interval.nil? && @keyframe_interval < 1
    invalid_properties.push('invalid value for "keyframe_interval", must be greater than or equal to 1.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



389
390
391
# File 'lib/shotstack/models/rendition.rb', line 389

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/shotstack/models/rendition.rb', line 395

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



383
384
385
# File 'lib/shotstack/models/rendition.rb', line 383

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/shotstack/models/rendition.rb', line 193

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  format_validator = EnumAttributeValidator.new('String', ["mp4", "webm", "mov", "avi", "mkv", "ogv", "wmv", "avif", "gif", "mp3", "wav", "jpg", "png", "webp", "tif"])
  return false unless format_validator.valid?(@format)
  fit_validator = EnumAttributeValidator.new('String', ["cover", "contain", "crop"])
  return false unless fit_validator.valid?(@fit)
  resolution_validator = EnumAttributeValidator.new('String', ["preview", "mobile", "sd", "hd", "fhd"])
  return false unless resolution_validator.valid?(@resolution)
  return false if !@quality.nil? && @quality > 100
  return false if !@quality.nil? && @quality < 1
  fps_validator = EnumAttributeValidator.new('Float', [12, 15, 23.976, 24, 25, 29.97, 30, 48, 50, 59.94, 60])
  return false unless fps_validator.valid?(@fps)
  return false if !@keyframe_interval.nil? && @keyframe_interval > 300
  return false if !@keyframe_interval.nil? && @keyframe_interval < 1
  true
end