Skip to content

Commit 4c5687d

Browse files
Add support for videoEdit.preview() (#298)
1 parent c9986ba commit 4c5687d

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

__TESTS__/unit/actions/VideoEdit.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,16 @@ describe('Tests for Transformation Action -- VideoEdit', () => {
116116

117117
expect(url).toBe('https://res.cloudinary.com/demo/video/upload/e_volume:10/sample');
118118
});
119+
120+
it('Tests a preview transformation for a video', () => {
121+
const url = createNewVideo('sample')
122+
.videoEdit(
123+
VideoEdit.preview()
124+
.duration(5)
125+
.minimumSegmentDuration(1)
126+
.maximumSegments(10)
127+
).toString();
128+
129+
expect(url).toContain('e_preview:duration_5.0:min_seg_dur_1.0:max_seg_10');
130+
});
119131
});

src/actions/videoEdit.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import TrimAction from './videoEdit/TrimAction';
22
import ConcatenateAction from './videoEdit/ConcatenateAction';
33
import VolumeAction from "./videoEdit/VolumeAction";
44
import {VideoSource} from "../values/source/sourceTypes/VideoSource";
5+
import {PreviewAction} from "./videoEdit/PreviewAction";
56

67
/**
78
* Methods for editing a video.
@@ -53,7 +54,20 @@ function volume(volumeValue: string | number): VolumeAction{
5354
return new VolumeAction(volumeValue);
5455
}
5556

56-
export declare type videoEditType = VolumeAction | TrimAction | ConcatenateAction;
57+
/**
58+
* @description A video preview is a short excerpt from a video that can be used to engage your audience and help them select the video content that interests them.
59+
*
60+
* <b>Learn more</b>: {@link https://cloudinary.com/documentation/video_manipulation_and_delivery#generate_an_ai_based_video_preview |
61+
* Create a video preview}
62+
*
63+
* @memberOf Actions.VideoEdit
64+
* @return {Actions.VideoEdit.PreviewAction}
65+
*/
66+
function preview(): PreviewAction{
67+
return new PreviewAction();
68+
}
69+
70+
export declare type videoEditType = VolumeAction | TrimAction | ConcatenateAction | PreviewAction;
5771

58-
const VideoEdit = {concatenate, trim, volume};
59-
export {VideoEdit, concatenate, trim, volume};
72+
const VideoEdit = {concatenate, trim, volume, preview};
73+
export {VideoEdit, concatenate, trim, volume, preview};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {Action} from "../../internal/Action";
2+
import {toFloatAsString} from "../../internal/utils/toFloatAsString";
3+
4+
/**
5+
* @description Class for creating a preview of a video
6+
* @memberOf Actions.VideoEdit
7+
* @extend {SDK.Action}
8+
*/
9+
class PreviewAction extends Action {
10+
private _minSeg: string | number;
11+
private _maxSeg: string | number;
12+
private _duration: string | number;
13+
14+
constructor() {
15+
super();
16+
}
17+
18+
/**
19+
* @description Control the duration of the video segments
20+
* @param {string|number} minSegDuration The duration of a video segment
21+
* @return {this}
22+
*/
23+
minimumSegmentDuration(minSegDuration: string | number): this {
24+
this._minSeg = minSegDuration;
25+
return this;
26+
}
27+
28+
/**
29+
* @description Control the number of the video segments
30+
* @param {string|number} maxSeg The number of the video segments.
31+
* @return {this}
32+
*/
33+
maximumSegments(maxSeg: string | number): this {
34+
this._maxSeg = maxSeg;
35+
return this;
36+
}
37+
38+
/**
39+
* @description control the length of the generated preview
40+
* @param {string|number} duration The duration in seconds such as 1.2, or 5.0
41+
* @return {this}
42+
*/
43+
duration(duration: string | number): this {
44+
this._duration = duration;
45+
return this;
46+
}
47+
48+
toString(): string {
49+
return [
50+
'e_preview',
51+
this._duration && `duration_${toFloatAsString(this._duration)}`,
52+
this._minSeg && `min_seg_dur_${toFloatAsString(this._minSeg)}`,
53+
this._maxSeg && `max_seg_${toFloatAsString(this._maxSeg)}`
54+
].filter((a) => a).join(':');
55+
}
56+
}
57+
58+
export {PreviewAction};

0 commit comments

Comments
 (0)