Skip to content

FEATURE: Add support for aws MediaConvert #33092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Jul 23, 2025
Merged

Conversation

blake-discourse
Copy link
Contributor

@blake-discourse blake-discourse commented Jun 5, 2025

When enabled this will convert uploaded videos to a standard format that should
be playable on all devices and browsers.

The goal of this feature is to prevent codec playback issues that sometimes can
occur with video uploads.

It uses an adapter pattern, so that other services for video conversion could be easily added in the future.

@blake-discourse blake-discourse force-pushed the media-convert-job branch 2 times, most recently from d87e737 to b806554 Compare June 17, 2025 17:37
@github-actions github-actions bot added the i18n PRs which update English locale files or i18n related code label Jun 17, 2025
blake-discourse added a commit that referenced this pull request Jun 18, 2025
In an upcoming pr #33092 that adds support for aws-sdk-mediaconvert it requires
that we bump aws-sdk-core to 3.225.0

``` +    aws-sdk-mediaconvert (1.160.0) +      aws-sdk-core (~> 3, >= 3.225.0)
```

but in doing so there are apparently some api changes and it requires changes
in core to support the new version. I thought it would best to break out these
changes in a separate PR as to not muddy up the mediaconvert pr that is already
quite large.
blake-discourse added a commit that referenced this pull request Jun 19, 2025
In an upcoming pr #33092 that adds support for aws-sdk-mediaconvert it requires
that we bump aws-sdk-core to 3.225.0

```
+    aws-sdk-mediaconvert (1.160.0)
+      aws-sdk-core (~> 3, >= 3.225.0)
```

but in doing so there are apparently some api changes and it requires changes
in core to support the new version. I thought it would best to break out these
changes in a separate PR as to not muddy up the mediaconvert pr that is already
quite large.
blake-discourse added a commit that referenced this pull request Jun 20, 2025
In an upcoming pr #33092 that adds support for aws-sdk-mediaconvert it
requires
that we bump aws-sdk-core to 3.225.0

```
+    aws-sdk-mediaconvert (1.160.0)
+      aws-sdk-core (~> 3, >= 3.225.0)
```

but in doing so there are apparently some api changes and it requires
changes
in core to support the new version. I thought it would best to break out
these
changes in a separate PR as to not muddy up the mediaconvert pr that is
already
quite large.
@blake-discourse blake-discourse marked this pull request as ready for review June 24, 2025 16:29
@@ -115,6 +116,11 @@ def store_file(file, path, opts = {})
path, etag = s3_helper.upload(file, path, options)
end

if opts[:upload_id] && FileHelper.is_supported_video?(opts[:filename]) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we trigger the video conversion job. It will only fire after it detects a video file being uploaded to s3 and the video conversion site setting is enabled.


begin
response =
mediaconvert_client.create_job(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we tell media convert to what video file in our existing s3 bucket to convert and where we want to store the output.

if upload && optimized_video = OptimizedVideo.find_by(upload_id: upload.id)
# Only update if the URL is different
if container["data-video-src"] != optimized_video.url
container["data-original-video-src"] = container["data-video-src"] unless container[
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add the original url back in here even though the video tag doesn't use it, this keeps the original upload from being cleaned up I believe.

Copy link
Contributor

@martin-brennan martin-brennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is looking fairly good so far 👌 I haven't tested it locally, since I'm not sure how to set this up in S3

Copy link
Contributor

@pmusaraj pmusaraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me!

I didn't test this locally, but the overall logic and setup make sense. Only left a few minor comments regarding verbose logging.

@martin-brennan @tgxworld is this in good shape from your point of view?

when :error
Rails.logger.error(
"Video conversion job failed for upload ID #{upload.id} and job ID #{args[:job_id]}",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be useful to have a verbose_video_conversion_logging site setting in place and only output these logging entries when it's enabled. Could be default enabled for the initial PR, and then once kinks are ironed out, we switch the default to disabled.


begin
new_sha1 = SecureRandom.hex(20)
output_path = "original/1X/#{new_sha1}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we have some logic to derive the path for uploads in FileStore::BaseStore

"#{type}/#{depth + 1}X/#{tree}#{sha}#{extension}"

Generally, I'm wondering if we can lean on the logic in UploadCreator here instead instead of duplicating some of the logic in this adapter.

@blake-discourse blake-discourse merged commit af3abb5 into main Jul 23, 2025
27 of 28 checks passed
@blake-discourse blake-discourse deleted the media-convert-job branch July 23, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n PRs which update English locale files or i18n related code
Development

Successfully merging this pull request may close these issues.

4 participants