Skip to content

Commit 0a93aad

Browse files
authored
Allow to disable b-frames for video codec (#284)
1 parent d30ee7c commit 0a93aad

File tree

7 files changed

+45
-14
lines changed

7 files changed

+45
-14
lines changed

js/jquery.cloudinary.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,11 +1093,11 @@ var slice = [].slice,
10931093
*
10941094
* If the parameter is an object,
10951095
* @param {(string|Object)} param - the video codec as either a String or a Hash
1096-
* @return {string} the video codec string in the format codec:profile:level
1096+
* @return {string} the video codec string in the format codec:profile:level:b_frames
10971097
* @example
1098-
* vc_[ :profile : [level]]
1098+
* vc_[ :profile : [level : [b_frames]]]
10991099
* or
1100-
{ codec: 'h264', profile: 'basic', level: '3.1' }
1100+
{ codec: 'h264', profile: 'basic', level: '3.1', b_frames: false }
11011101
* @ignore
11021102
*/
11031103

@@ -1112,6 +1112,9 @@ var slice = [].slice,
11121112
video += ":" + param['profile'];
11131113
if ('level' in param) {
11141114
video += ":" + param['level'];
1115+
if ('b_frames' in param && param['b_frames'] === false) {
1116+
video += ":bframes_no";
1117+
}
11151118
}
11161119
}
11171120
}

samples/webpack/bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,11 @@
623623
*
624624
* If the parameter is an object,
625625
* @param {(string|Object)} param - the video codec as either a String or a Hash
626-
* @return {string} the video codec string in the format codec:profile:level
626+
* @return {string} the video codec string in the format codec:profile:level:b_frames
627627
* @example
628-
* vc_[ :profile : [level]]
628+
* vc_[ :profile : [level : [b_frames]]]
629629
* or
630-
{ codec: 'h264', profile: 'basic', level: '3.1' }
630+
{ codec: 'h264', profile: 'basic', level: '3.1', b_frames: false }
631631
* @ignore
632632
*/
633633

@@ -642,6 +642,9 @@
642642
video += ":" + param['profile'];
643643
if ('level' in param) {
644644
video += ":" + param['level'];
645+
if ('b_frames' in param && param.b_frames === false) {
646+
video += ":bframes_no";
647+
}
645648
}
646649
}
647650
}

src/parameters.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ class Param {
103103
*
104104
* If the parameter is an object,
105105
* @param {(string|Object)} param - the video codec as either a String or a Hash
106-
* @return {string} the video codec string in the format codec:profile:level
106+
* @return {string} the video codec string in the format codec:profile:level:b_frames
107107
* @example
108-
* vc_[ :profile : [level]]
108+
* vc_[ :profile : [level : [b_frames]]]
109109
* or
110-
{ codec: 'h264', profile: 'basic', level: '3.1' }
110+
{ codec: 'h264', profile: 'basic', level: '3.1', b_frames: false }
111111
* @ignore
112112
*/
113113
static process_video_params(param) {
@@ -121,6 +121,9 @@ class Param {
121121
video += ":" + param.profile;
122122
if ('level' in param) {
123123
video += ":" + param.level;
124+
if ('b_frames' in param && param.b_frames === false) {
125+
video += ":bframes_no";
126+
}
124127
}
125128
}
126129
}

test/spec/automatic/videourlspec.js

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/spec/env/js-folder-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jasmine.getEnv().addReporter(new SpecReporter({
1616
// List of files to test
1717
const files = [
1818
{name: 'canvas-to-blob.min.js', checkSum: "7c7becb6f9ecf2defa663e70a6b3a0f5"},
19-
{name: 'jquery.cloudinary.js', checkSum: "388dffde6d46b70fae4f0dfc254f48c5"},
19+
{name: 'jquery.cloudinary.js', checkSum: "22e7276c8dec1760246a230fd9fa26c3"},
2020
{name: 'jquery.fileupload.js', checkSum: "4bfd85460689a29e314ddfad50c184e0"},
2121
{name: 'jquery.fileupload-image.js', checkSum: "7c40367b00f74b0c7c43bff009dde942"},
2222
{name: 'jquery.fileupload-process.js', checkSum: "840f65232eaf1619ea0aff1ab4f5e444"},

types/cloudinary-core-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ cld.videoTag("movie").setSourceTypes('mp4')
183183
.transformation()
184184
.htmlHeight("100")
185185
.htmlWidth("200")
186-
.videoCodec({ codec: 'h264', profile: 'basic', level: '3.1' })
186+
.videoCodec({ codec: 'h264', profile: 'basic', level: '3.1', b_frames: false })
187187
.audioCodec("aac")
188188
.startOffset(3)
189189
.toHtml();

types/cloudinary-core.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export class Transformation {
239239
underlay(value: string): Transformation; // public id of an uploaded image
240240
variable(name: string, value: any): Transformation;
241241
variables(value: Array<[string, any]>): Transformation;
242-
videoCodec(value: string | Object): Transformation; // Select the video codec and control the video content of the profile used. Can be provided in the form <codec>[:<profile>:[<level>]] to specify specific values to apply for video codec, profile and level, e.g. "h264:baseline:3.1". Also accepts a hash of values such as { codec: 'h264', profile: 'basic', level: '3.1' }
242+
videoCodec(value: string | Object): Transformation; // Select the video codec and control the video content of the profile used. Can be provided in the form <codec>[:<profile>:[<level>:[<:b_frames>]]] to specify specific values to apply for video codec, profile, level and b_frames, e.g. "h264:baseline:3.1:bframes_no". Also accepts a hash of values such as { codec: 'h264', profile: 'basic', level: '3.1', b_frames: false }
243243
videoSampling(value: number | string): Transformation; // Integer - The total number of frames to sample from the original video. String - The number of seconds between each frame to sample from the original video. e.g. 2.3s takes one frame every 2.3 seconds.
244244
width(value: string | number): Transformation; // Number of pixels, width % or "auto" with rounding step
245245
x(value: number): Transformation; // pixels or percent
@@ -373,7 +373,7 @@ export namespace Transformation {
373373
sourceTransformation?: string;
374374
startOffset?: number | string; // Float or string
375375
streamingProfile?: StreamingProfiles
376-
videoCodec?: string | Object; // Select the video codec and control the video content of the profile used. Can be provided in the form <codec>[:<profile>:[<level>]] to specify specific values to apply for video codec, profile and level, e.g. "h264:baseline:3.1". Also accepts a hash of values such as { codec: 'h264', profile: 'basic', level: '3.1' }
376+
videoCodec?: string | Object; // Select the video codec and control the video content of the profile used. Can be provided in the form <codec>[:<profile>:[<level>:[<:b_frames>]]] to specify specific values to apply for video codec, profile, level and b_frames, e.g. "h264:baseline:3.1:bframes_no". Also accepts a hash of values such as { codec: 'h264', profile: 'basic', level: '3.1', b_frames: false }
377377
videoSampling?: number | string; // Integer - The total number of frames to sample from the original video. The frames are spread out over the length of the video, e.g. 20 takes one frame every 5% -- OR -- String - The number of seconds between each frame to sample from the original video. e.g. 2.3s takes one frame every 2.3 seconds.
378378
}
379379
}

0 commit comments

Comments
 (0)