Repository navigation
fix: respect caller format and allow opting out of f_auto - #1097
Conversation
A caller-supplied fetch_format (or its format alias) now replaces the default f_auto:video, with a matching MIME type. An empty source type delivers the asset as-is, without f_auto:video or an extension. VIDEO-21243
✅ Deploy Preview for cld-vp-esm-pages ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for cld-video-player ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| if (callerFormat && callerFormat !== 'auto') { | ||
| // Respect the caller's format instead of adding f_auto:video | ||
| if (!fetchFormat) { | ||
| opts.transformation = mergeTransformations(opts.transformation, { fetch_format: callerFormat }); |
There was a problem hiding this comment.
fetch_format: 'auto:video' or any auto:* passes the !== 'auto' check. The code then treats it as a concrete format. formatToMimeTypeAndTransformation('auto:video') returns an unknown MIME type, so the source gets a wrong type and Video.js may drop it. Before the PR this gave f_auto:video with type video/auto. Fix: use startsWith('auto').
There was a problem hiding this comment.
Good catch. Any value that starts with auto now uses the default path, and the output is the same as on master. I added a test.
| if (!fetchFormat) { | ||
| opts.transformation = mergeTransformations(opts.transformation, { fetch_format: callerFormat }); | ||
| } | ||
| [type] = formatToMimeTypeAndTransformation(callerFormat); |
There was a problem hiding this comment.
The comment says format is an alias of fetch_format, but in url-gen format is a URL key (the file extension, URL_KEYS in backwards/transformation.js), while fetch_format is what emits f_.
Before this PR, transformation: { format: 'mp4' } meant ".mp4 extension". Now it also adds f_mp4. Is that change intended?
There was a problem hiding this comment.
The URL builder ignores format in a transformation component. Object, instance and chained forms all give one f_mp4 and no extension. See the alias tests.
There was a problem hiding this comment.
Yes, intended. In this player, format in transformation did not set the extension before this PR. On master, { format: 'mp4' } gives f_auto:video/sea_turtle, so the key was ignored. Treating it as an alias of fetch_format gives it a meaning without changing existing output. Callers who want the extension can use sourceTypes: ['mp4'].
Jira: VIDEO-21243
Why
The player adds
f_auto:videoto everyautosource, and integrators had no way to opt out. A caller's ownfetch_formatwas chained in front of the default (f_mp4/f_auto:video/...) rather than replacing it, andformatinside a transformation was silently dropped.What changed
fetch_formatreplaces the defaultf_auto:video, and the source MIME type follows it.formatinside a transformation is an alias offetch_format. If both are set,fetch_formatwins.sourceTypes: ['']delivers the asset as-is, with nof_auto:videoand no extension. A bare URL resolves and serves the original file.getTransformationValuetosrc/utils/cloudinary.js.isKeyInTransformationnow uses it and behaves the same.f_auto:video/sea_turtletransformation: { fetch_format: 'mp4' }f_mp4/f_auto:video/sea_turtle,video/autof_mp4/sea_turtle,video/mp4transformation: { format: 'mp4' }f_auto:video/sea_turtle,video/autof_mp4/sea_turtle,video/mp4transformation: { fetch_format: 'auto' }f_auto/f_auto:video/sea_turtlesourceTypes: ['']sea_turtle.(broken),video/sea_turtle,video/autoThe default output is byte-identical. Explicit
sourceTypes(mp4,hls, ...) are unaffected.Not in this PR
raw_transformation: 'f_mp4'still getsf_auto:videoadded.Testing
test/unit/videoSource.test.jscover callerfetch_format/formatandsourceTypes: [''].npm run test:unitpasses (141 tests).