Skip to content

Commit

Permalink
manifest: add DISCONTINUITY tags to clip playlist
Browse files Browse the repository at this point in the history
A discontinuity tag is required in the clip playlist so that
it shows the correct duration.
  • Loading branch information
emranemran committed Oct 6, 2023
1 parent 49a28c3 commit 81f9837
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion clients/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions clients/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestItCanGenerateAndWriteManifests(t *testing.T) {
BitsPerSecond: 1,
},
},
false,
)
require.NoError(t, err)

Expand Down Expand Up @@ -212,6 +213,7 @@ func TestCompliantMasterManifestOrdering(t *testing.T) {
BitsPerSecond: 2000000,
},
},
false,
)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion transcode/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 81f9837

Please sign in to comment.