From 81f983783a1d3cfee2fa3e357e20872bdfd73443 Mon Sep 17 00:00:00 2001 From: emranemran Date: Fri, 6 Oct 2023 17:07:12 -0400 Subject: [PATCH] manifest: add DISCONTINUITY tags to clip playlist A discontinuity tag is required in the clip playlist so that it shows the correct duration. --- clients/manifest.go | 8 +++++++- clients/manifest_test.go | 2 ++ transcode/transcode.go | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clients/manifest.go b/clients/manifest.go index d0225e26..2fce62fe 100644 --- a/clients/manifest.go +++ b/clients/manifest.go @@ -98,7 +98,7 @@ func GetSourceSegmentURLs(sourceManifestURL string, manifest m3u8.MediaPlaylist) // Generate a Master manifest, plus one Rendition manifest for each Profile we're transcoding, then write them to storage // Returns the master manifest URL on success -func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL string, transcodedStats []*video.RenditionStats) (string, error) { +func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL string, transcodedStats []*video.RenditionStats, isClip bool) (string, error) { // Generate the master + rendition output manifests masterPlaylist := m3u8.NewMasterPlaylist() @@ -146,6 +146,12 @@ func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL s } } + if isClip { + _, totalSegs := video.GetTotalDurationAndSegments(renditionPlaylist) + renditionPlaylist.Segments[1].Discontinuity = true + renditionPlaylist.Segments[totalSegs-1].Discontinuity = true + } + // Write #EXT-X-ENDLIST renditionPlaylist.Close() diff --git a/clients/manifest_test.go b/clients/manifest_test.go index b2bc574b..c9a8cb90 100644 --- a/clients/manifest_test.go +++ b/clients/manifest_test.go @@ -146,6 +146,7 @@ func TestItCanGenerateAndWriteManifests(t *testing.T) { BitsPerSecond: 1, }, }, + false, ) require.NoError(t, err) @@ -212,6 +213,7 @@ func TestCompliantMasterManifestOrdering(t *testing.T) { BitsPerSecond: 2000000, }, }, + false, ) require.NoError(t, err) diff --git a/transcode/transcode.go b/transcode/transcode.go index 31274df4..2cce63af 100644 --- a/transcode/transcode.go +++ b/transcode/transcode.go @@ -166,7 +166,7 @@ func RunTranscodeProcess(transcodeRequest TranscodeSegmentRequest, streamName st } // Build the manifests and push them to storage - manifestURL, err := clients.GenerateAndUploadManifests(sourceManifest, hlsTargetURL.String(), transcodedStats) + manifestURL, err := clients.GenerateAndUploadManifests(sourceManifest, hlsTargetURL.String(), transcodedStats, transcodeRequest.IsClip) if err != nil { return outputs, segmentsCount, err }