Skip to content
Merged
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
9 changes: 9 additions & 0 deletions fixtures/content/content.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"width": 180,
"height": 320,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v1/init-0.m4s",
"initBytes": 826,
"segments": [
Expand Down Expand Up @@ -47,6 +48,7 @@
"width": 270,
"height": 480,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v1/init-1.m4s",
"initBytes": 826,
"segments": [
Expand Down Expand Up @@ -79,6 +81,7 @@
"width": 360,
"height": 640,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v1/init-2.m4s",
"initBytes": 828,
"segments": [
Expand Down Expand Up @@ -154,6 +157,7 @@
"width": 180,
"height": 320,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v2/init-0.m4s",
"initBytes": 826,
"segments": [
Expand Down Expand Up @@ -186,6 +190,7 @@
"width": 270,
"height": 480,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v2/init-1.m4s",
"initBytes": 826,
"segments": [
Expand Down Expand Up @@ -218,6 +223,7 @@
"width": 360,
"height": 640,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v2/init-2.m4s",
"initBytes": 828,
"segments": [
Expand Down Expand Up @@ -293,6 +299,7 @@
"width": 180,
"height": 320,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v3/init-0.m4s",
"initBytes": 826,
"segments": [
Expand Down Expand Up @@ -325,6 +332,7 @@
"width": 270,
"height": 480,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v3/init-1.m4s",
"initBytes": 826,
"segments": [
Expand Down Expand Up @@ -357,6 +365,7 @@
"width": 360,
"height": 640,
"codec": "avc1",
"frameRateFps": 30,
"initUrl": "/media/v3/init-2.m4s",
"initBytes": 828,
"segments": [
Expand Down
8 changes: 8 additions & 0 deletions src/dashjs/SFVDashAssetResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ function formatTemplate(template, representationId, number, bandwidth, time) {
}
);
}
function frameRateFpsOf(frameRate) {
if (frameRate == null) return undefined;
const [numerator, denominator = 1] = String(frameRate).split('/').map(Number);
const fps = numerator / denominator;
return Number.isFinite(fps) && fps > 0 ? fps : undefined;
}

function segmentsOf(template, durationS) {
if (!template || !template.SegmentTimeline?.S?.length)
throw new Error('SegmentTimeline required');
Expand Down Expand Up @@ -108,6 +115,7 @@ export class SFVDashAssetResolver {
width: rep.width,
height: rep.height,
codec: rep.codecs ?? set.codecs,
frameRateFps: frameRateFpsOf(rep.frameRate ?? set.frameRate),
mimeType: rep.mimeType ?? set.mimeType ?? `${type}/mp4`,
initUrl: url(template.initialization),
segments: timeline.map(s => ({
Expand Down
6 changes: 4 additions & 2 deletions src/media/SFVMediaCatalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ export class SFVMediaCatalog {
getRepresentations(videoId, mediaType = 'video') {
this.#assertAvailable(videoId);
const reps = this.#video(videoId).representations[mediaType] ?? [];
return reps.map(({ id, bitrateKbps, width, height, codec }) => ({
return reps.map(({ id, bitrateKbps, width, height, codec, frameRateFps }) => ({
id,
bitrateKbps,
width,
height,
codec
codec,
frameRateFps
}));
}
getSegments(videoId, mediaType = 'video', representationId) {
Expand Down Expand Up @@ -97,6 +98,7 @@ export class SFVMediaCatalog {
width: r.width,
height: r.height,
codec: r.codec,
frameRateFps: r.frameRateFps,
segments: r.segments.map(s => ({
index: s.index,
startS: s.startS,
Expand Down
12 changes: 9 additions & 3 deletions src/output/SFVPlaybackMetricsCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ function knownSegments(video) {
return video.representations?.video?.[0]?.segments ?? [];
}

function bitrateFor(video, representationId) {
function representationProperties(video, representationId) {
const rep = video.representations?.video?.find(r => String(r.id) === String(representationId));
return finite(rep?.bitrateKbps) ? rep.bitrateKbps : null;
return {
bitrate_kbps: finite(rep?.bitrateKbps) ? rep.bitrateKbps : null,
width: finite(rep?.width) ? rep.width : null,
height: finite(rep?.height) ? rep.height : null,
codec: rep?.codec ?? null,
frame_rate_fps: finite(rep?.frameRateFps) ? rep.frameRateFps : null
};
}

function appendMap(allEvents) {
Expand Down Expand Up @@ -87,7 +93,7 @@ function progressForVideo(video, playbackEvents, assignments) {
intervals.push({
video_id: video.videoId,
representation_id: representationId,
bitrate_kbps: bitrateFor(video, representationId),
...representationProperties(video, representationId),
segment_index: seg.index,
start_at_s: startTime,
end_at_s: endTime,
Expand Down
18 changes: 18 additions & 0 deletions test/manifest-base-uri.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,21 @@ test('manifest directory rather than page origin is the base URI', () => {
const result = resolver.parse('v42', new TextEncoder().encode('<MPD/>'), url);
assert.equal(result.dashManifest.baseUri, 'https://cdn.example.test/feed/item42/');
});

test('frame rate comes from the adaptation set or representation', () => {
const url = 'https://cdn.example.test/feed/item42/index.mpd';
const parseWithFrameRate = (setFrameRate, representationFrameRate) => {
const mpd = fakeDashParser();
const set = mpd.Period[0].AdaptationSet[0];
set.frameRate = setFrameRate;
set.Representation[0].frameRate = representationFrameRate;
const resolver = new SFVDashAssetResolver({ parseDashManifest: () => mpd });
const result = resolver.parse('v42', new TextEncoder().encode('<MPD/>'), url);
return result.video.representations.video[0].frameRateFps;
};
assert.equal(parseWithFrameRate('30/1'), 30);
assert.equal(parseWithFrameRate(30), 30);
assert.equal(parseWithFrameRate('30/1', '25'), 25);
assert.ok(Math.abs(parseWithFrameRate('30000/1001') - 29.97) < 0.01);
assert.equal(parseWithFrameRate(), undefined);
});
15 changes: 15 additions & 0 deletions test/playback-metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,18 @@ test('prefetched and appended but never played segments contribute zero played d
assert.equal(m.per_video.v2.representation_intervals.length, 0);
close(m.per_video.v1.representation_played_duration_s['0'], 1);
});

test('representation intervals hold the bitrate, resolution, codec and frame rate', () => {
const m = calculatePlaybackMetrics({
dataset,
allEvents: [appended('v1', 0, '2', 0)],
playbackEvents: [started('v1', 0), sample('v1', 1, 1)],
endTimeS: 1
});
const interval = m.per_video.v1.representation_intervals[0];
assert.equal(interval.bitrate_kbps, 650);
assert.equal(interval.width, 360);
assert.equal(interval.height, 640);
assert.equal(interval.codec, 'avc1');
assert.equal(interval.frame_rate_fps, 30);
});
Loading