Skip to content

Use optimal self-hosted video for user by width#15561

Open
domlander wants to merge 10 commits intomainfrom
doml/sh-optimise-video-source
Open

Use optimal self-hosted video for user by width#15561
domlander wants to merge 10 commits intomainfrom
doml/sh-optimise-video-source

Conversation

@domlander
Copy link
Copy Markdown
Contributor

@domlander domlander commented Mar 19, 2026

What does this change?

Selects the optimal video from the list of video sources. Selects the best set of dimensions for the users screen size.

Use the same logic when extracting sources from assets for both fronts and articles.

Why?

To serve smaller videos to users without any reduction in video quality.

Logic for extracting sources is likely to be the same for both fronts and articles. Combining the logic into one function ensures that changes to one will affect the other.

@domlander domlander self-assigned this Mar 19, 2026
@domlander domlander added run_chromatic Runs chromatic when label is applied fronts + curation maintenance Departmental tracking: maintenance work, not a fix or a feature labels Mar 19, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 19, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 19, 2026

@domlander domlander force-pushed the doml/sh-optimise-video-source branch from fa4b4f0 to be2b4d6 Compare March 23, 2026 15:22
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

@domlander domlander force-pushed the doml/sh-optimise-video-source branch from be2b4d6 to 0e973f4 Compare March 23, 2026 15:48
@domlander domlander changed the title WIP Pick best self-hosted video for user by dimensions Use optimal self-hosted video for user by width Mar 23, 2026
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 23, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 23, 2026
@domlander domlander force-pushed the doml/sh-optimise-video-source branch from 0e973f4 to 24275c2 Compare March 25, 2026 09:29
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@domlander domlander marked this pull request as ready for review March 25, 2026 09:37
@github-actions
Copy link
Copy Markdown

Hello 👋! When you're ready to run Chromatic, please apply the run_chromatic label to this PR.

You will need to reapply the label each time you want to run Chromatic.

Click here to see the Chromatic project.

@domlander domlander force-pushed the doml/sh-optimise-video-source branch from dac04f1 to 5fc414a Compare March 25, 2026 12:41
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@domlander domlander force-pushed the doml/sh-optimise-video-source branch from c8c8f1a to 9313fcc Compare March 25, 2026 13:08
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@domlander domlander force-pushed the doml/sh-optimise-video-source branch from 9313fcc to 9331026 Compare March 25, 2026 16:00
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 25, 2026
@domlander domlander requested a review from abeddow91 March 25, 2026 16:27
"footballMatch": {
"$ref": "#/definitions/{id:string;homeTeam:{name:string;id:string;scorers:string[];codename:string;players:{name:string;id:string;position:string;lastName:string;substitute:boolean;timeOnPitch:string;shirtNumber:string;events:{eventTime:string;eventType:string;}[];}[];possession:number;shotsOn:number;shotsOff:number;corners:number;fouls:number;colours:string;crest:string;score?:number;};awayTeam:{name:string;id:string;scorers:string[];codename:string;players:{name:string;id:string;position:string;lastName:string;substitute:boolean;timeOnPitch:string;shirtNumber:string;events:{eventTime:string;eventType:string;}[];}[];possession:number;shotsOn:number;shotsOff:number;corners:number;fouls:number;colours:string;crest:string;score?:number;};status:string;comments?:string;}"
},
"matchInfo": {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please ignore these changes - these are temporary to allow CI to run. It is not intended that these will be a part of this PR when it gets merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, these changes are a part of the changeset when running make gen-schemas. I've narrowed it down to the changes in the video.ts file, but I cannot explain why. Since these changes are harmless, I will continue.

Copy link
Copy Markdown
Member

@davidfurey davidfurey left a comment

Choose a reason for hiding this comment

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

Great to share this code between articles and fronts. Sorry, I haven't reviewed the whole thing but have made a couple of comments.

@domlander domlander force-pushed the doml/sh-optimise-video-source branch from 9331026 to 5621360 Compare March 25, 2026 17:47
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 26, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 26, 2026
return DEFAULT_ASPECT_RATIO;
}

return firstSource.width / firstSource.height;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why have you opted to calculate the aspect ratio rather than taking it from the video asset?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll convert the string into a number, so that the aspect ratio defined on the video source is the source of truth for the aspect ratio passed into the component.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Brilliant, this should help with m3u8 as well which are only passed with the aspect ratio, not the dimensions

@domlander domlander force-pushed the doml/sh-optimise-video-source branch from b2b3469 to b735be8 Compare March 26, 2026 10:51
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 26, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 26, 2026
@domlander domlander added the run_chromatic Runs chromatic when label is applied label Mar 26, 2026
@github-actions github-actions bot removed the run_chromatic Runs chromatic when label is applied label Mar 26, 2026
@domlander domlander requested a review from abeddow91 March 26, 2026 11:31
Comment on lines +235 to +239
const videoAssets =
convertFEMediaAssetsToVideoAssets(selfHostedAssets);
const sources = extractValidSourcesFromAssets(videoAssets);

const aspectRatio = getAspectRatioFromSources(sources);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is all much cleaner to read 👏

Copy link
Copy Markdown
Contributor

@abeddow91 abeddow91 left a comment

Choose a reason for hiding this comment

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

Fantastic, this looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fronts + curation maintenance Departmental tracking: maintenance work, not a fix or a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants