Skip to content

Commit cd75be1

Browse files
feat: add support for a frame-rate attribute (#159)
* feat: add support for a frame-rate attribute * docs: fix typo in comment
1 parent 269e406 commit cd75be1

19 files changed

+129
-68
lines changed

src/parseAttributes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { parseDivisionValue } from './utils/string';
12
import { from } from './utils/list';
23
import { parseDuration, parseDate } from './utils/time';
34

@@ -131,6 +132,18 @@ export const parsers = {
131132
return parseInt(value, 10);
132133
},
133134

135+
/**
136+
* Specifies the frame rate of the representation
137+
*
138+
* @param {string} value
139+
* value of attribute as a string
140+
* @return {number}
141+
* The parsed frame rate
142+
*/
143+
frameRate(value) {
144+
return parseDivisionValue(value);
145+
},
146+
134147
/**
135148
* Specifies the number of the first Media Segment in this Representation in the Period
136149
*

src/toM3u8.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ export const formatVideoPlaylist = ({
296296
segments
297297
};
298298

299+
if (attributes.frameRate) {
300+
playlist.attributes['FRAME-RATE'] = attributes.frameRate;
301+
}
302+
299303
if (attributes.contentProtection) {
300304
playlist.contentProtection = attributes.contentProtection;
301305
}

src/utils/string.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Converts the provided string that may contain a division operation to a number.
3+
*
4+
* @param {string} value - the provided string value
5+
*
6+
* @return {number} the parsed string value
7+
*/
8+
export const parseDivisionValue = (value) => {
9+
return parseFloat(value.split('/').reduce((prev, current) => prev / current));
10+
};

test/manifests/608-captions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const parsedManifest = {
3636
'AUDIO': 'audio',
3737
'BANDWIDTH': 449000,
3838
'CODECS': 'avc1.420015',
39+
'FRAME-RATE': 23.976,
3940
'NAME': '482',
4041
'PROGRAM-ID': 1,
4142
'RESOLUTION': {

test/manifests/708-captions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const parsedManifest = {
3737
'AUDIO': 'audio',
3838
'BANDWIDTH': 449000,
3939
'CODECS': 'avc1.420015',
40+
'FRAME-RATE': 23.976,
4041
'NAME': '482',
4142
'PROGRAM-ID': 1,
4243
'RESOLUTION': {

test/manifests/location.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const parsedManifest = {
2222
'AUDIO': 'audio',
2323
'BANDWIDTH': 449000,
2424
'CODECS': 'avc1.420015',
25+
'FRAME-RATE': 23.976,
2526
'NAME': '482',
2627
'PROGRAM-ID': 1,
2728
'RESOLUTION': {

test/manifests/locations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const parsedManifest = {
2323
'AUDIO': 'audio',
2424
'BANDWIDTH': 449000,
2525
'CODECS': 'avc1.420015',
26+
'FRAME-RATE': 23.976,
2627
'NAME': '482',
2728
'PROGRAM-ID': 1,
2829
'RESOLUTION': {

test/manifests/maat_vtt_segmentTemplate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ export const parsedManifest = {
406406
'NAME': '482',
407407
'AUDIO': 'audio',
408408
'SUBTITLES': 'subs',
409+
'FRAME-RATE': 23.976,
409410
'RESOLUTION': {
410411
width: 482,
411412
height: 270
@@ -487,6 +488,7 @@ export const parsedManifest = {
487488
'NAME': '720',
488489
'AUDIO': 'audio',
489490
'SUBTITLES': 'subs',
491+
'FRAME-RATE': 23.976,
490492
'RESOLUTION': {
491493
width: 720,
492494
height: 404

test/manifests/multiperiod-dynamic.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -613,16 +613,17 @@ export const parsedManifest = {
613613
playlists: [
614614
{
615615
attributes: {
616-
'NAME': 'default_video2000_0_1280x720',
617616
'AUDIO': 'audio',
618-
'SUBTITLES': 'subs',
617+
'BANDWIDTH': 2008000,
618+
'CODECS': 'avc1.4d001f',
619+
'FRAME-RATE': 29.97,
620+
'NAME': 'default_video2000_0_1280x720',
621+
'PROGRAM-ID': 1,
619622
'RESOLUTION': {
620-
width: 1280,
621-
height: 720
623+
height: 720,
624+
width: 1280
622625
},
623-
'CODECS': 'avc1.4d001f',
624-
'BANDWIDTH': 2008000,
625-
'PROGRAM-ID': 1
626+
'SUBTITLES': 'subs'
626627
},
627628
uri: '',
628629
endList: false,
@@ -905,16 +906,17 @@ export const parsedManifest = {
905906
},
906907
{
907908
attributes: {
908-
'NAME': 'default_video1200_1_960x540',
909909
'AUDIO': 'audio',
910-
'SUBTITLES': 'subs',
910+
'BANDWIDTH': 1195000,
911+
'CODECS': 'avc1.4d001f',
912+
'FRAME-RATE': 29.97,
913+
'NAME': 'default_video1200_1_960x540',
914+
'PROGRAM-ID': 1,
911915
'RESOLUTION': {
912-
width: 960,
913-
height: 540
916+
height: 540,
917+
width: 960
914918
},
915-
'CODECS': 'avc1.4d001f',
916-
'BANDWIDTH': 1195000,
917-
'PROGRAM-ID': 1
919+
'SUBTITLES': 'subs'
918920
},
919921
uri: '',
920922
endList: false,
@@ -1197,16 +1199,17 @@ export const parsedManifest = {
11971199
},
11981200
{
11991201
attributes: {
1200-
'NAME': 'default_video900_1_640x360',
12011202
'AUDIO': 'audio',
1202-
'SUBTITLES': 'subs',
1203+
'BANDWIDTH': 884000,
1204+
'CODECS': 'avc1.4d001e',
1205+
'FRAME-RATE': 29.97,
1206+
'NAME': 'default_video900_1_640x360',
1207+
'PROGRAM-ID': 1,
12031208
'RESOLUTION': {
1204-
width: 640,
1205-
height: 360
1209+
height: 360,
1210+
width: 640
12061211
},
1207-
'CODECS': 'avc1.4d001e',
1208-
'BANDWIDTH': 884000,
1209-
'PROGRAM-ID': 1
1212+
'SUBTITLES': 'subs'
12101213
},
12111214
uri: '',
12121215
endList: false,

test/manifests/multiperiod-segment-list.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const parsedManifest = {
1515
'AUDIO': 'audio',
1616
'BANDWIDTH': 449000,
1717
'CODECS': 'avc1.420015',
18+
'FRAME-RATE': 23.976,
1819
'NAME': '482',
1920
'PROGRAM-ID': 1,
2021
'RESOLUTION': {

0 commit comments

Comments
 (0)