Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable source playback for storj recordings #858

Merged
merged 1 commit into from
Sep 13, 2023
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
37 changes: 24 additions & 13 deletions pipeline/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,34 @@
return
}

sourceURL, err := url.Parse(job.SourceFile)
if err != nil {
log.LogError(job.RequestID, "unable to parse source url for source playback", err)
return
}

Check warning on line 167 in pipeline/ffmpeg.go

View check run for this annotation

Codecov / codecov/patch

pipeline/ffmpeg.go#L165-L167

Added lines #L165 - L167 were not covered by tests

prefix := ""
if clients.IsHLSInput(sourceURL) {
for k, v := range f.sourcePlaybackHosts {
if strings.HasPrefix(job.SourceFile, k) {
prefix = strings.Replace(job.SourceFile, k, v, 1)
break
}
}
if prefix == "" {
log.Log(job.RequestID, "no source playback prefix found", "host", sourceURL.Host)
return
}

Check warning on line 180 in pipeline/ffmpeg.go

View check run for this annotation

Codecov / codecov/patch

pipeline/ffmpeg.go#L178-L180

Added lines #L178 - L180 were not covered by tests
}

segmentingPath := strings.Split(segmentingTargetURL.Path, "/")
if len(segmentingPath) < 3 || segmentingPath[1] == "" {
log.Log(job.RequestID, "unable to find bucket for source playback", "segmentingTargetURL", segmentingTargetURL)
return
}
// assume bucket is second element in slice (first element should be an empty string as the path has a leading slash)
segmentingBucket := segmentingPath[1]
if job.HlsTargetURL == nil || !strings.Contains(job.HlsTargetURL.String(), "/"+segmentingBucket+"/") {
if (job.HlsTargetURL == nil || !strings.Contains(job.HlsTargetURL.String(), "/"+segmentingBucket+"/")) && prefix == "" {
log.Log(job.RequestID, "source playback not available, not a studio job", "segmentingTargetURL", segmentingTargetURL)
return
}
Expand All @@ -187,19 +207,10 @@
return
}

sourceURL, err := url.Parse(job.SourceFile)
if err != nil {
log.LogError(job.RequestID, "unable to parse source url for source playback", err)
return
}

prefix := f.sourcePlaybackHosts[sourceURL.Host]
if clients.IsHLSInput(sourceURL) && prefix == "" {
log.Log(job.RequestID, "no source playback prefix found", "host", sourceURL.Host)
return
if prefix == "" {
prefix = "/" + path.Join(segmentingPath[2:]...)
}

sourceMaster.Append(prefix+"/"+path.Join(segmentingPath[2:]...), &m3u8.MediaPlaylist{}, m3u8.VariantParams{
sourceMaster.Append(prefix, &m3u8.MediaPlaylist{}, m3u8.VariantParams{
Bandwidth: uint32(videoTrack.Bitrate),
Resolution: fmt.Sprintf("%dx%d", videoTrack.Width, videoTrack.Height),
Name: fmt.Sprintf("%dp", videoTrack.Height),
Expand Down
32 changes: 29 additions & 3 deletions pipeline/ffmpeg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func Test_sendSourcePlayback(t *testing.T) {
}
ff := ffmpeg{
sourcePlaybackHosts: map[string]string{
"lp-us-catalyst-recordings-monster.storage.googleapis.com": "//recordings-cdn.lp-playback.monster/hls",
"http://lp-us-catalyst-recordings-monster.storage.googleapis.com/foo": "//recordings-cdn.lp-playback.monster/hls",
"https://link.storjshare.io/raw/jvnqoncawzmc3lb7tstb5ut3d7va/catalyst-recordings-monster/hls": "//link.storjshare.io/raw/jvnqoncawzmc3lb7tstb5ut3d7va/catalyst-recordings-monster/hls",
"https://link.storjshare.io/raw/jvnqoncawzmc3lb7tstb5ut3d7vb/catalyst-recordings-monster/hls": "//recordings-cdn.lp-playback.monster/hls",
},
}

Expand Down Expand Up @@ -101,12 +103,36 @@ func Test_sendSourcePlayback(t *testing.T) {
job: &JobInfo{
SegmentingTargetURL: segmentingTargetURL,
UploadJobPayload: UploadJobPayload{
SourceFile: "http://lp-us-catalyst-recordings-monster.storage.googleapis.com/foo/bar",
SourceFile: "http://lp-us-catalyst-recordings-monster.storage.googleapis.com/foo/bar/output.m3u8",
HlsTargetURL: mustParseUrl("/bucket/foo", t),
},
},
shouldWriteSourcePlaylist: true,
expectedRendition: "//recordings-cdn.lp-playback.monster/hls/path",
expectedRendition: "//recordings-cdn.lp-playback.monster/hls/bar/output.m3u8",
},
{
name: "host mapping - storj",
job: &JobInfo{
SegmentingTargetURL: "https://link.storjshare.io/raw/jvnqoncawzmc3lb7tstb5ut3d7va/catalyst-recordings-monster/hls/e88briv8dl7rzg8o-test/3c446cbe-3ca9-4eba-84a9-68b38305d67a/output.m3u8",
UploadJobPayload: UploadJobPayload{
SourceFile: "https://link.storjshare.io/raw/jvnqoncawzmc3lb7tstb5ut3d7va/catalyst-recordings-monster/hls/e88briv8dl7rzg8o-test/3c446cbe-3ca9-4eba-84a9-68b38305d67a/output.m3u8",
HlsTargetURL: mustParseUrl("/bucket/foo", t),
},
},
shouldWriteSourcePlaylist: true,
expectedRendition: "//link.storjshare.io/raw/jvnqoncawzmc3lb7tstb5ut3d7va/catalyst-recordings-monster/hls/e88briv8dl7rzg8o-test/3c446cbe-3ca9-4eba-84a9-68b38305d67a/output.m3u8",
},
{
name: "host mapping - storj cdn",
job: &JobInfo{
SegmentingTargetURL: "https://link.storjshare.io/raw/jvnqoncawzmc3lb7tstb5ut3d7vb/catalyst-recordings-monster/hls/e88briv8dl7rzg8o-test/3c446cbe-3ca9-4eba-84a9-68b38305d67a/output.m3u8",
UploadJobPayload: UploadJobPayload{
SourceFile: "https://link.storjshare.io/raw/jvnqoncawzmc3lb7tstb5ut3d7vb/catalyst-recordings-monster/hls/e88briv8dl7rzg8o-test/3c446cbe-3ca9-4eba-84a9-68b38305d67a/output.m3u8",
HlsTargetURL: mustParseUrl("/bucket/foo", t),
},
},
shouldWriteSourcePlaylist: true,
expectedRendition: "//recordings-cdn.lp-playback.monster/hls/e88briv8dl7rzg8o-test/3c446cbe-3ca9-4eba-84a9-68b38305d67a/output.m3u8",
},
{
name: "not standard bucket - no source playback",
Expand Down
Loading