-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve Transcode Quality #832
Changes from 5 commits
df3eb84
c67adf0
f661dab
5c24368
d72e764
9dcabff
921c2bb
5e3d658
7a62999
4a96b00
13a6bf2
b3be1d0
e90142a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ const ( | |
MaxVideoBitrate = 288_000_000 | ||
TrackTypeVideo = "video" | ||
TrackTypeAudio = "audio" | ||
defaultCRF = 27 | ||
) | ||
|
||
type InputVideo struct { | ||
|
@@ -73,13 +74,15 @@ var DefaultProfile360p = EncodedProfile{ | |
Bitrate: 1_000_000, | ||
Width: 640, | ||
Height: 360, | ||
CRF: defaultCRF, | ||
} | ||
var DefaultProfile720p = EncodedProfile{ | ||
Name: "720p0", | ||
FPS: 0, | ||
Bitrate: 4_000_000, | ||
Width: 1280, | ||
Height: 720, | ||
CRF: defaultCRF, | ||
} | ||
|
||
// DefaultTranscodeProfiles defines the default set of encoding profiles to use when none are specified | ||
|
@@ -103,22 +106,27 @@ func SetTranscodeProfiles(inputVideoStats InputVideo, reqTranscodeProfiles []Enc | |
// a single profile that matches the input video's specs with the target bitrate | ||
} else if len(reqTranscodeProfiles) == 1 { | ||
if reqTranscodeProfiles[0].Width == 0 && reqTranscodeProfiles[0].Height == 0 && reqTranscodeProfiles[0].Bitrate != 0 { | ||
transcodeProfiles = GenerateSingleProfileWithTargetBitrate(videoTrack, reqTranscodeProfiles[0].Bitrate) | ||
transcodeProfiles = GenerateSingleProfileWithTargetParams(videoTrack, reqTranscodeProfiles[0]) | ||
return transcodeProfiles, nil | ||
} | ||
} | ||
return reqTranscodeProfiles, nil | ||
} | ||
|
||
func GenerateSingleProfileWithTargetBitrate(videoTrack InputTrack, videoBitrate int64) []EncodedProfile { | ||
func GenerateSingleProfileWithTargetParams(videoTrack InputTrack, videoProfile EncodedProfile) []EncodedProfile { | ||
profiles := make([]EncodedProfile, 0) | ||
var CRF uint = defaultCRF | ||
if videoProfile.CRF != 0 { | ||
CRF = videoProfile.CRF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CRF = 0 is still a valid value (meaning lossless). Are we explicitly saying crf = 0 should never be allowed or should this check for values between 0 and 51? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good point. The problem with Anyway, since as you know, there is no direct correspondence of the the |
||
} | ||
|
||
profiles = append(profiles, EncodedProfile{ | ||
Name: strconv.FormatInt(videoTrack.Height, 10) + "p0", | ||
Bitrate: videoBitrate, | ||
Bitrate: videoProfile.Bitrate, | ||
FPS: 0, | ||
Width: videoTrack.Width, | ||
Height: videoTrack.Height, | ||
CRF: CRF, | ||
}) | ||
return profiles | ||
} | ||
|
@@ -134,7 +142,10 @@ func GetDefaultPlaybackProfiles(video InputTrack) ([]EncodedProfile, error) { | |
// check it here. | ||
lowerQualityThanSrc := profile.Height < video.Height && profile.Bitrate < video.Bitrate | ||
if lowerQualityThanSrc { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we also want this for the rendition that's the same resolution as the source? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that no, because for the same resolution as the source we create a profile in line 157. So, this logic here is (and always was) for the profile resolution lower than source. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh wait, maybe you're right that we should also increase the bitrate in line 157. Will update it there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in 13a6bf2 |
||
relativeBitrate := float64(profile.Width*profile.Height) * (float64(videoBitrate) / float64(video.Width*video.Height)) | ||
// relativeBitrate needs to be slightly higher than the proportional average bitrate of the source video. | ||
// Livepeer network uses bitrate to set max bitrate for encoding, so for the video to look good, we multiply | ||
// it by a factor of 1.2. | ||
relativeBitrate := 1.2 * float64(profile.Width*profile.Height) * (float64(videoBitrate) / float64(video.Width*video.Height)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how did we determine the 1.2 multiplier? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't really. I just know that what we currently have is too low, because we're setting: As described in the doc, I plan to not set it at all, when the Os start to support the |
||
br := math.Min(relativeBitrate, float64(profile.Bitrate)) | ||
profile.Bitrate = int64(br) | ||
profiles = append(profiles, profile) | ||
|
@@ -149,6 +160,7 @@ func GetDefaultPlaybackProfiles(video InputTrack) ([]EncodedProfile, error) { | |
FPS: 0, | ||
Width: nearestEven(video.Width), | ||
Height: nearestEven(video.Height), | ||
CRF: defaultCRF, | ||
}) | ||
return profiles, nil | ||
} | ||
|
@@ -170,6 +182,7 @@ func lowBitrateProfile(video InputTrack) EncodedProfile { | |
Bitrate: bitrate, | ||
Width: nearestEven(video.Width), | ||
Height: nearestEven(video.Height), | ||
CRF: defaultCRF, | ||
} | ||
} | ||
|
||
|
@@ -189,6 +202,7 @@ type EncodedProfile struct { | |
Encoder string `json:"encoder,omitempty"` | ||
ColorDepth int64 `json:"colorDepth,omitempty"` | ||
ChromaFormat int64 `json:"chromaFormat,omitempty"` | ||
CRF uint `json:"crf"` | ||
} | ||
|
||
type OutputVideo struct { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 27? I think ffmpeg default is 23 actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just from some tests. Please check this part of design doc for details. 23 will give way bigger segment size.