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

Add nil checks in thumbnail code #1355

Merged
merged 2 commits into from
Aug 12, 2024
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
4 changes: 4 additions & 0 deletions pipeline/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (e *external) HandleStartUploadJob(job *JobInfo) (*HandlerOutput, error) {
}

func generateThumbs(job *JobInfo) {
if job.ThumbnailsTargetURL == nil {
return
}

manifestUrl, err := clients.GetFirstRenditionURL(job.RequestID, job.HlsTargetURL.JoinPath("index.m3u8"))
if err != nil {
log.LogError(job.RequestID, "failed to get rendition URL for mediaconvert thumbs", err)
Expand Down
16 changes: 16 additions & 0 deletions thumbnails/thumbnails.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func thumbWaitBackoff() backoff.BackOff {
}

func getSegmentOffset(mediaPlaylist *m3u8.MediaPlaylist) (int64, error) {
if mediaPlaylist == nil {
return 0, fmt.Errorf("MediaPlaylist is nil")
}

segments := mediaPlaylist.GetAllSegments()
if len(segments) < 1 {
return 0, fmt.Errorf("no segments found for")
Expand All @@ -44,6 +48,10 @@ func getSegmentOffset(mediaPlaylist *m3u8.MediaPlaylist) (int64, error) {
}

func GenerateThumbsVTT(requestID string, input string, output *url.URL) error {
if output == nil {
return fmt.Errorf("output URL is nil")
}

// download and parse the manifest
mediaPlaylist, err := clients.DownloadRenditionManifest(requestID, input)
if err != nil {
Expand Down Expand Up @@ -102,6 +110,10 @@ func GenerateThumbsVTT(requestID string, input string, output *url.URL) error {
}

func GenerateThumb(segmentURI string, input []byte, output *url.URL, segmentOffset int64) error {
if output == nil {
return fmt.Errorf("output URL is nil")
}

tempDir, err := os.MkdirTemp(os.TempDir(), "thumbs-*")
if err != nil {
return fmt.Errorf("failed to make temp dir: %w", err)
Expand Down Expand Up @@ -157,6 +169,10 @@ func GenerateThumbsAndVTT(requestID, input string, output *url.URL) error {
}

func GenerateThumbsFromManifest(requestID, input string, output *url.URL) error {
if output == nil {
return fmt.Errorf("output URL is nil")
}

// parse manifest and generate one thumbnail per segment
mediaPlaylist, err := clients.DownloadRenditionManifest(requestID, input)
if err != nil {
Expand Down
Loading