From e80fcabae557334140256b57705fb9a8baac394b Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 14 Oct 2023 17:36:06 -0400 Subject: [PATCH] Trickplay thumbnails (#169) * Trickplay thumbnails * Changelog * Comment --- CHANGELOG.md | 2 + .../components/Services/Dash/DashManifest.bs | 80 +++++++++++++++++++ playlet-lib/src/source/services/XmlObject.bs | 3 +- 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60abd367..1945f007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Local DASH manifest generation - This adds support for multi languages audio tracks + - Also adds thumbnails/preview in trick play mode + - Known issue: thumbnails might appear cropped/misaligned at the end of videos. This will be addressed in a later release. ### Fixed diff --git a/playlet-lib/src/components/Services/Dash/DashManifest.bs b/playlet-lib/src/components/Services/Dash/DashManifest.bs index 3e718bc2..67ccf715 100644 --- a/playlet-lib/src/components/Services/Dash/DashManifest.bs +++ b/playlet-lib/src/components/Services/Dash/DashManifest.bs @@ -28,6 +28,7 @@ class DashManifest videoMimeTypes = m.getMimeTypes(videoStreams) audioSets = m.getMimeTypeLanguageCombos(audioStreams) + storyboards = metadata.storyboards xml = new XmlObject() @@ -178,6 +179,85 @@ class DashManifest id += 1 end for + ' https://developer.roku.com/en-ca/docs/developer-program/media-playback/trick-mode/hls-and-dash.md#dash-standard-thumbnail-tiles + for each storyboard in storyboards + interval = ValidInt(storyboard.interval) + if interval = 0 + LogWarn("Invalid storyboard interval=0") + continue for + end if + + templateUrl = storyboard.templateUrl + if templateUrl.Instr("$M") = -1 + LogWarn("Invalid storyboard url: url does not contain $M:", templateUrl) + continue for + end if + + storyboardWidth = storyboard.storyboardWidth + storyboardHeight = storyboard.storyboardHeight + storyboardCount = storyboard.storyboardCount + tileWidthInPixels = storyboard.width + tileHeightInPixels = storyboard.height + totalTileCount = storyboard.count + + ' For the last page, the image height might be smaller than the storyboard height + if storyboardCount = 1 + storyboardHeight = totalTileCount \ storyboardWidth + if totalTileCount mod storyboardWidth > 0 + storyboardHeight += 1 + end if + end if + + intervalInSeconds = interval \ 1000 + + ' Youtube template uses the var $M for tile pages + ' DASH-IF uses $Number$ in the SegmentTemplate + ' https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf + url = templateUrl.replace("$M", "$Number$") + + tilesPerPage = storyboardWidth * storyboardHeight + duration = tilesPerPage * intervalInSeconds + + storyboardWidthInPixels = tileWidthInPixels * storyboardWidth + storyboardHeightInPixels = tileHeightInPixels * storyboardHeight + + ' Bandwidth is kind of a guess... + bandwidth = ((storyboardWidthInPixels * storyboardHeightInPixels * 0.5) / duration) + + if xml.Node("AdaptationSet", { + "id": `${id}`, + "mimeType": "image/jpeg", + "contentType": "image" + }) + xml.Node("SegmentTemplate", { + "media": url, + "duration": duration, + "startNumber": 0 + }) + xml.End() + + if xml.Node("Representation", { + "id": `thumbnails_${id}`, + "bandwidth": bandwidth, + "width": storyboardWidthInPixels, + "height": storyboardHeightInPixels + }) + + xml.Node("EssentialProperty", { + "schemeIdUri": "http://dashif.org/guidelines/thumbnail_tile", + "value": `${storyboardWidth}x${storyboardHeight}` + }) + xml.End() + + xml.End() + end if + + xml.End() + end if + + id += 1 + end for + xml.End() end if xml.End() diff --git a/playlet-lib/src/source/services/XmlObject.bs b/playlet-lib/src/source/services/XmlObject.bs index 077862c9..07d327f3 100644 --- a/playlet-lib/src/source/services/XmlObject.bs +++ b/playlet-lib/src/source/services/XmlObject.bs @@ -55,7 +55,8 @@ class XmlObject if node.attributes <> invalid for each key in node.attributes.keys() - xmlString += ` ${key}="${node.attributes[key]}"` + value = m.XmlEscape(`${node.attributes[key]}`) + xmlString += ` ${key}="${value}"` end for end if