remotion_lambda 4.0.541 → 4.0.543

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccb3a059f308e6d8dfd7c08d4a70fb343bddb6c7d79df0e581d4051b5561b506
4
- data.tar.gz: f054f96f8ff195fbc8732939fb3a7aa09724c343f8bd6582185a690060e78380
3
+ metadata.gz: f0e355da5cfe2bb1823754c014b095eb9a19352516f9da8cbbb730f4e8e83b95
4
+ data.tar.gz: 49ecf09dfa8c06c3500b29cfaef5863548664e1a2f99175144e2787f3fa9708d
5
5
  SHA512:
6
- metadata.gz: 697195ecf411dfa662511de08fed7c34f300568952e8e1a7f58c242937938f11d0f5262d5f46bcf23e5df494ca3e225826f71dfa45f577762955c88dab45aa4e
7
- data.tar.gz: 6a35b7410b8b4fdcaf500d625190d22b8b8f83961670318f455b8a465a0e59f7339429b206c5804a0898b98fdf3ff4191844a8f62dfeadede4f4034572dc7585
6
+ metadata.gz: fb8f2c5b4091d4bd1281685ffda7312534613f3bcfba21be9aee2ea703cdc32799e09610be273388c61db8a6f3174433e82d922c5f4c6cb0b4cbb6bc5818e18d
7
+ data.tar.gz: 07a305ef45f51e6035c2fea6607aa102f97948df5150528a66780c19a0d87bbb75f0fd931aeee4271ae89d5ea30ce56a0bb22408a3e728cc6bdffd7b0b07c17d
@@ -0,0 +1,86 @@
1
+ module RemotionLambda
2
+ # Uploads oversized input props to S3, mirroring the reference implementations
3
+ # in the JavaScript, Go, Python and PHP SDKs: AWS Lambda rejects synchronous
4
+ # invoke payloads over 256 KB, so props that exceed the inline limit are
5
+ # written to the render bucket and passed to the render as a reference.
6
+ module InputPropsSerializer
7
+ INLINE_PAYLOAD_MARGIN = 5_000 + 1_024 # 5KB headroom for the payload + 1KB for webhook data
8
+ MAX_STILL_INLINE_PAYLOAD_SIZE = 5_000_000 - INLINE_PAYLOAD_MARGIN
9
+ MAX_VIDEO_INLINE_PAYLOAD_SIZE = 200_000 - INLINE_PAYLOAD_MARGIN
10
+ INPUT_PROPS_KEY_TEMPLATE = 'input-props/%s.json'
11
+ BUCKET_NAME_PREFIX = 'remotionlambda-'
12
+ US_EAST_1 = 'us-east-1'
13
+
14
+ def self.needs_upload?(payload_size, render_type)
15
+ max_size = render_type == 'still' ? MAX_STILL_INLINE_PAYLOAD_SIZE : MAX_VIDEO_INLINE_PAYLOAD_SIZE
16
+ payload_size > max_size
17
+ end
18
+
19
+ # Returns a new payload in which an oversized inline `inputProps` block is
20
+ # replaced by an S3 reference. The caller's payload hash is left untouched,
21
+ # so the same payload can be reused for multiple renders.
22
+ def self.upload_oversized_input_props(payload, s3_client, render_type, region)
23
+ input_props = payload[:inputProps]
24
+ return payload unless input_props.is_a?(Hash) && input_props[:type] == 'payload'
25
+
26
+ payload_string = input_props[:payload].to_s
27
+ return payload unless needs_upload?(payload_string.bytesize, render_type)
28
+
29
+ bucket_name = payload[:bucketName] || get_or_create_bucket(s3_client, region)
30
+ hash = random_hash
31
+ s3_client.put_object(
32
+ bucket: bucket_name,
33
+ key: format(INPUT_PROPS_KEY_TEMPLATE, hash),
34
+ body: payload_string
35
+ )
36
+
37
+ warn(
38
+ "Warning: The props are #{(payload_string.bytesize + 1023) / 1024}KB in size. " \
39
+ 'Uploading them to S3 to circumvent the AWS Lambda payload size limit, which may lead to slowdown.'
40
+ )
41
+
42
+ payload.merge(
43
+ inputProps: {
44
+ type: 'bucket-url',
45
+ hash: hash,
46
+ bucketName: bucket_name
47
+ }
48
+ )
49
+ end
50
+
51
+ # Mirrors getOrCreateBucket() in the Go SDK: reuse the single existing
52
+ # Remotion bucket in the region, create one if none exists, and refuse to
53
+ # guess when several exist. The Lambda runtime resolves the render bucket
54
+ # the same way when the payload omits bucketName.
55
+ def self.get_or_create_bucket(s3_client, region)
56
+ buckets = s3_client.list_buckets.buckets.map(&:name).select do |name|
57
+ name.start_with?(BUCKET_NAME_PREFIX) && bucket_in_region?(s3_client, name, region)
58
+ end
59
+
60
+ if buckets.size > 1
61
+ raise ArgumentError,
62
+ "You have multiple buckets (#{buckets.join(', ')}) in your S3 region (#{region}) starting with \"#{BUCKET_NAME_PREFIX}\". Please see https://remotion.dev/docs/lambda/multiple-buckets"
63
+ end
64
+
65
+ return buckets.first unless buckets.empty?
66
+
67
+ bucket = "#{BUCKET_NAME_PREFIX}#{region.delete('-')}-#{random_hash}"
68
+ options = {bucket: bucket}
69
+ unless region == US_EAST_1
70
+ options[:create_bucket_configuration] = {location_constraint: region}
71
+ end
72
+ s3_client.create_bucket(options)
73
+ bucket
74
+ end
75
+
76
+ def self.bucket_in_region?(s3_client, bucket, region)
77
+ location = s3_client.get_bucket_location(bucket: bucket).location_constraint
78
+ location == region || (location.to_s.empty? && region == US_EAST_1)
79
+ end
80
+
81
+ def self.random_hash
82
+ alphabet = ('a'..'z').to_a + ('0'..'9').to_a
83
+ Array.new(10) { alphabet.sample }.join
84
+ end
85
+ end
86
+ end
@@ -16,6 +16,7 @@ def get_render_media_on_lambda_payload(
16
16
  composition: nil,
17
17
  concurrency_per_lambda: 1,
18
18
  concurrency: nil,
19
+ chunks: nil,
19
20
  crf: nil,
20
21
  delete_after: nil,
21
22
  download_behavior: nil,
@@ -60,6 +61,7 @@ def get_render_media_on_lambda_payload(
60
61
  webhook: nil,
61
62
  x264_preset: nil,
62
63
  gop_size: nil,
64
+ pro_res_bits_per_macroblock: nil,
63
65
  disable_shared_memory_capture: false,
64
66
  chromium_options: {},
65
67
  is_production: nil,
@@ -71,6 +73,7 @@ if api_key != nil
71
73
  end
72
74
 
73
75
  payload = {
76
+ streamProgress: false,
74
77
  audioBitrate: audio_bitrate,
75
78
  audioCodec: audio_codec,
76
79
  storageClass: storage_class,
@@ -79,6 +82,7 @@ payload = {
79
82
  composition: composition,
80
83
  concurrencyPerLambda: concurrency_per_lambda,
81
84
  concurrency: concurrency,
85
+ chunks: chunks,
82
86
  chromiumOptions: chromium_options,
83
87
  crf: crf,
84
88
  deleteAfter: delete_after,
@@ -130,6 +134,7 @@ payload = {
130
134
  webhook: webhook,
131
135
  x264Preset: x264_preset,
132
136
  gopSize: gop_size,
137
+ proResBitsPerMacroblock: pro_res_bits_per_macroblock,
133
138
  disableSharedMemoryCapture: disable_shared_memory_capture,
134
139
  bucketName: bucket_name,
135
140
  isProduction: is_production
@@ -2,6 +2,7 @@ require 'aws-sdk-lambda'
2
2
  require 'aws-sdk-s3'
3
3
  require 'json'
4
4
  require 'logger'
5
+ require_relative 'input_props_serializer'
5
6
  require_relative 'version'
6
7
 
7
8
  module RemotionLambda
@@ -32,19 +33,22 @@ module RemotionLambda
32
33
  end
33
34
 
34
35
  def render_media_on_lambda(function_name, payload)
35
- body = invoke(function_name, payload)
36
+ payload = InputPropsSerializer.upload_oversized_input_props(payload, s3_client, 'video-or-audio', @region)
37
+ body = invoke(function_name, payload)
36
38
  raise "Failed to call renderMediaOnLambda: #{body['message']}" if body["type"] == "error"
37
39
  body
38
40
  end
39
41
 
40
42
  def render_frames_on_lambda(function_name, payload)
43
+ payload = InputPropsSerializer.upload_oversized_input_props(payload, s3_client, 'video-or-audio', @region)
41
44
  body = invoke(function_name, payload)
42
45
  raise "Failed to call renderFramesOnLambda: #{body['message']}" if body["type"] == "error"
43
46
  body
44
47
  end
45
48
 
46
49
  def render_still_on_lambda(function_name, payload)
47
- body = invoke(function_name, payload)
50
+ payload = InputPropsSerializer.upload_oversized_input_props(payload, s3_client, 'still', @region)
51
+ body = invoke(function_name, payload)
48
52
  raise "Failed to call renderStillOnLambda: #{body['message']}" if body["type"] == "error"
49
53
  body
50
54
  end
@@ -1 +1 @@
1
- VERSION = "4.0.541"
1
+ VERSION = "4.0.543"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotion_lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.541
4
+ version: 4.0.543
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonny Burger
@@ -89,6 +89,7 @@ files:
89
89
  - lib/remotion_lambda.rb
90
90
  - lib/remotion_lambda/cancel_render_on_lambda_spec.rb
91
91
  - lib/remotion_lambda/compositions_payload.rb
92
+ - lib/remotion_lambda/input_props_serializer.rb
92
93
  - lib/remotion_lambda/render_frames_on_lambda_payload.rb
93
94
  - lib/remotion_lambda/render_media_on_lambda_payload.rb
94
95
  - lib/remotion_lambda/render_media_on_lambda_payload_spec.rb