Skip to content

Commit

Permalink
prepare: effectiveProfile to avoid dimensions shorter than 145 pixels (
Browse files Browse the repository at this point in the history
…#29)

* prepare: effectiveProfile to avoid dimensions shorter than 145 pixels

* Address PR comments

Co-authored-by: Victor Elias <[email protected]>
  • Loading branch information
gioelecerati and victorges authored Jun 14, 2022
1 parent d48ea25 commit 364297c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions task/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
const (
minVideoBitrate = 100_000
absoluteMinVideoBitrate = 5_000
// NVIDIA cards with Turing architecture enforce a minimum width/height of 145 pixels on transcoded videos
minVideoDimensionPixels = 145
)

var allProfiles = []api.Profile{
Expand Down Expand Up @@ -125,8 +127,11 @@ func getPlaybackProfiles(assetVideoSpec *api.AssetVideoSpec) ([]api.Profile, err
return nil, fmt.Errorf("no video track found in asset spec")
}
filtered := make([]api.Profile, 0, len(allProfiles))
for _, profile := range allProfiles {
if profile.Height <= video.Height && profile.Bitrate < int(video.Bitrate) {
for _, baseProfile := range allProfiles {
profile := effectiveProfile(baseProfile, video)
lowerQualityThanSrc := profile.Height <= video.Height && profile.Bitrate < int(video.Bitrate)
compliesToMinSize := profile.Height >= minVideoDimensionPixels && profile.Width >= minVideoDimensionPixels
if lowerQualityThanSrc && compliesToMinSize {
filtered = append(filtered, profile)
}
}
Expand All @@ -136,6 +141,15 @@ func getPlaybackProfiles(assetVideoSpec *api.AssetVideoSpec) ([]api.Profile, err
return filtered, nil
}

func effectiveProfile(profile api.Profile, video *api.AssetTrack) api.Profile {
if video.Width >= video.Height {
profile.Height = profile.Width * video.Height / video.Width
} else {
profile.Width = profile.Height * video.Width / video.Height
}
return profile
}

func lowBitrateProfile(video *api.AssetTrack) api.Profile {
bitrate := int(video.Bitrate / 3)
if bitrate < minVideoBitrate && video.Bitrate > minVideoBitrate {
Expand Down

0 comments on commit 364297c

Please sign in to comment.