Skip to content

Commit

Permalink
transcode: use nicer names for rendition folders
Browse files Browse the repository at this point in the history
Instead of rendition-* folder names, use the profile name (e.g. 720p,
1080p, etc) as the folder name to make it more user friendly.
  • Loading branch information
emranemran committed Nov 8, 2022
1 parent 0e7b9f1 commit 83be991
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions transcode/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package transcode
import (
"fmt"
"net/url"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -93,7 +94,7 @@ func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL s
for i, profile := range transcodedStats {
// For each profile, add a new entry to the master manifest
masterPlaylist.Append(
fmt.Sprintf("rendition-%d/index.m3u8", i),
path.Join(profile.Name, "index.m3u8"),
&m3u8.MediaPlaylist{
TargetDuration: sourceManifest.TargetDuration,
},
Expand Down Expand Up @@ -128,7 +129,7 @@ func GenerateAndUploadManifests(sourceManifest m3u8.MediaPlaylist, targetOSURL s
renditionPlaylist.Close()

manifestFilename := "index.m3u8"
renditionManifestBaseURL := fmt.Sprintf("%s/rendition-%d", targetOSURL, i)
renditionManifestBaseURL := fmt.Sprintf("%s/%s", targetOSURL, profile.Name)
err = clients.UploadToOSURL(renditionManifestBaseURL, manifestFilename, strings.NewReader(renditionPlaylist.String()))
if err != nil {
return "", fmt.Errorf("failed to upload rendition playlist: %s", err)
Expand Down
14 changes: 13 additions & 1 deletion transcode/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ func RunTranscodeProcess(transcodeRequest TranscodeSegmentRequest, streamName st
}
// Go back to the root directory to set as the output for transcode renditions
targetTranscodedPath := path.Dir(path.Dir(segmentedOutputManifestURL.Path))
// Use the same manifest filename that was used for the segmented manifest
targetTranscodedManifestFilename := path.Base(segmentedOutputManifestURL.String())
// Generate the new output path of the transcoded manifest
targetTranscodedOutputPath := path.Join(targetTranscodedPath, targetTranscodedManifestFilename)
// Generate the manifest output URL from the manifest output path (e.g. s3+https://USER:PASS@storage.googleapis.com/user/hls/index.m3u8)
tpath, err := url.Parse(targetTranscodedOutputPath)
if err != nil {
return outputs, fmt.Errorf("failed to parse targetTranscodedOutputPath: %s", err)
}
targetTranscodedOutputURL := segmentedOutputManifestURL.ResolveReference(tpath)

// Generate the rendition output URL (e.g. s3+https://USER:PASS@storage.googleapis.com/user/hls/)
tout, err := url.Parse(targetTranscodedPath)
if err != nil {
return outputs, fmt.Errorf("failed to parse targetTranscodedPath: %s", err)
Expand Down Expand Up @@ -219,7 +231,7 @@ func transcodeSegment(segment segmentInfo, streamName, manifestID string, transc
return fmt.Errorf("failed to find profile with name %q while parsing rendition segment", transcodedSegment.Name)
}

targetRenditionURL, err := url.JoinPath(targetOSURL.String(), fmt.Sprintf("rendition-%d/", renditionIndex))
targetRenditionURL, err := url.JoinPath(targetOSURL.String(), transcodedSegment.Name)
if err != nil {
return fmt.Errorf("error building rendition segment URL %q: %s", targetRenditionURL, err)
}
Expand Down

0 comments on commit 83be991

Please sign in to comment.