Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CloudinaryVideoPlayer } from '@cloudinary-util/types';
import { getVideoPlayerOptions } from '@cloudinary-util/url-loader';

import { CldVideoPlayerProps } from './CldVideoPlayer.types';
import { getPlayerTransformation } from './getPlayerTransformation';

import { getCloudinaryConfig } from "../../lib/cloudinary";

Expand Down Expand Up @@ -36,6 +37,8 @@ const CldVideoPlayer = (props: CldVideoPlayerProps) => {

const cloudinaryConfig = getCloudinaryConfig(config);
const playerOptions = getVideoPlayerOptions(props, cloudinaryConfig);
playerOptions.transformation = getPlayerTransformation(props, playerOptions.transformation);

const { publicId } = playerOptions;
if ( typeof publicId === 'undefined' ) {
throw new Error('Video Player requires a Public ID or Cloudinary URL - please specify a src prop');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { CloudinaryVideoPlayerOptions } from '@cloudinary-util/types';

import type { CldVideoPlayerProps } from './CldVideoPlayer.types';

/**
* getPlayerTransformation
* @description getVideoPlayerOptions passes the transformation as an array ([{ quality }, ...transformation]).
* The player turns each array item into its own URL step, which leaves an `aspectRatio` alone in
* a step and breaks poster URLs (cloudinary/cloudinary-video-player#1087). When an aspectRatio is
* set and the caller didn't pass an array themselves, combine everything into a single
* transformation object. Players without an aspectRatio keep their existing URLs.
*/

export function getPlayerTransformation(
props: Pick<CldVideoPlayerProps, 'aspectRatio' | 'transformation'>,
transformation: CloudinaryVideoPlayerOptions['transformation']
): CloudinaryVideoPlayerOptions['transformation'] {
if ( props.aspectRatio && !Array.isArray(props.transformation) && Array.isArray(transformation) ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did the browser comparison include a source whose aspect ratio is different from the aspectRatio prop (e.g. a vertical or 4:3 video with aspectRatio="16:9")? Combining ar into the same step as the player's c_limit might change the delivered video's dimensions compared to 7.0.0. Could you compare the video URL dimensions for that case?

@PaulBoye-py PaulBoye-py Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the question, @strausr .

I compared them with a vertical video (1080×1920) and a 4:3 one (1440×1080), both with aspectRatio="16:9", running the published 7.0.0 package against this PR in a 640px-wide player. I measured the delivered files: the video with ffprobe, and the poster by downloading it.

Vertical (9:16):
aspectRatio only: video 1080×1920 in both; poster 400 in 7.0.0, 222×394 with the PR;
with cropMode="fill": video 1080×608 in both; poster 700×394 in both;
with a transformation object: video 1080×1920 in both; poster 400 in 7.0.0, 222×394 with the PR.

4:3:
aspectRatio only: video 1440×1080 in both; poster 400 in 7.0.0, 525×394 with the PR;
with cropMode="fill": video 1440×810 in both; poster 700×394 in both;
with a transformation object: video 1440×1080 in both; poster 400 in 7.0.0, 525×394 with the PR.

Video: the delivered dimensions are the same as 7.0.0 in every case, and also with a 1200px player and on a 2× screen. By default, the player only adds c_limit and the width to the poster URL, not the video URL. ar_16:9 without a crop doesn't resize the video, whether it's in its own step or combined.

Poster: it now loads, and keeps the source's shape inside a 16:9 box of the width the player requests. That width is based on the player's on-screen width and the screen's pixel density: 700 here, 1300 for the same player on a 2× screen.

One difference I found is that with cropMode="fill", if the video is narrower than that requested width, the poster is now scaled up to it, because c_fill and the width are in the same step. In 7.0.0, the separate c_limit step kept it at the source size. For example, the vertical video in a 1200px player gives 1080×608 in 7.0.0 and 1200×675 with this PR. The video itself isn't affected.

return Object.assign({}, ...transformation.filter(Boolean));
}

return transformation;
}
61 changes: 61 additions & 0 deletions next-cloudinary/tests/components/getPlayerTransformation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { describe, it, expect } from 'vitest';
import { getVideoPlayerOptions } from '@cloudinary-util/url-loader';

import { getPlayerTransformation } from '../../src/components/CldVideoPlayer/getPlayerTransformation';

const config = { cloud: { cloudName: 'test' } };

function getTransformation(props) {
const playerOptions = getVideoPlayerOptions(props, config);
return getPlayerTransformation(props, playerOptions.transformation);
}

describe('CldVideoPlayer', () => {
describe('getPlayerTransformation', () => {
it('should keep the transformation array when there is no aspectRatio', () => {
const props = {
src: 'turtle',
transformation: { effect: 'sepia' }
};

const { transformation } = getVideoPlayerOptions(props, config);

expect(getTransformation(props)).toEqual(transformation);
});

it('should combine the transformation into one object when there is an aspectRatio', () => {
expect(getTransformation({
src: 'turtle',
aspectRatio: '16:9',
transformation: { effect: 'sepia' }
})).toEqual({ quality: 'auto', effect: 'sepia' });
});

it('should combine into one object when there is an aspectRatio and no transformation', () => {
expect(getTransformation({
src: 'turtle',
aspectRatio: '16:9'
})).toEqual({ quality: 'auto' });
});

// The crop mode is passed to the player separately, not as part of the transformation
it('should combine into one object with an aspectRatio, crop mode and quality', () => {
expect(getTransformation({
src: 'turtle',
aspectRatio: '16:9',
cropMode: 'fill',
quality: 50
})).toEqual({ quality: 50 });
});

it('should keep the transformation array when the caller passes an array', () => {
const props = {
src: 'turtle',
aspectRatio: '16:9',
transformation: [{ effect: 'sepia' }, { width: 300 }]
};

expect(getTransformation(props)).toEqual([{ quality: 'auto' }, { effect: 'sepia' }, { width: 300 }]);
});
});
});
Loading