Fix the int overflow issue in encoder bufsize

This commit is contained in:
nyanmisaka 2022-06-15 23:27:49 +08:00
parent 1b8a251991
commit 255f5a6707
2 changed files with 4 additions and 3 deletions

View file

@ -216,7 +216,7 @@ namespace Jellyfin.Api.Helpers
var sdrVideoUrl = ReplaceProfile(playlistUrl, "hevc", string.Join(',', requestedVideoProfiles), "main"); var sdrVideoUrl = ReplaceProfile(playlistUrl, "hevc", string.Join(',', requestedVideoProfiles), "main");
sdrVideoUrl += "&AllowVideoStreamCopy=false"; sdrVideoUrl += "&AllowVideoStreamCopy=false";
var sdrOutputVideoBitrate = _encodingHelper.GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, state.OutputVideoCodec) ?? 0; var sdrOutputVideoBitrate = _encodingHelper.GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, state.OutputVideoCodec);
var sdrOutputAudioBitrate = _encodingHelper.GetAudioBitrateParam(state.VideoRequest, state.AudioStream) ?? 0; var sdrOutputAudioBitrate = _encodingHelper.GetAudioBitrateParam(state.VideoRequest, state.AudioStream) ?? 0;
var sdrTotalBitrate = sdrOutputAudioBitrate + sdrOutputVideoBitrate; var sdrTotalBitrate = sdrOutputAudioBitrate + sdrOutputVideoBitrate;

View file

@ -1893,7 +1893,7 @@ namespace MediaBrowser.Controller.MediaEncoding
return request.EnableAutoStreamCopy; return request.EnableAutoStreamCopy;
} }
public int? GetVideoBitrateParamValue(BaseEncodingJobOptions request, MediaStream videoStream, string outputVideoCodec) public int GetVideoBitrateParamValue(BaseEncodingJobOptions request, MediaStream videoStream, string outputVideoCodec)
{ {
var bitrate = request.VideoBitRate; var bitrate = request.VideoBitRate;
@ -1925,7 +1925,8 @@ namespace MediaBrowser.Controller.MediaEncoding
} }
} }
return bitrate; // Cap the max target bitrate to intMax/2 to satisify the bufsize=bitrate*2.
return Math.Min(bitrate ?? 0, int.MaxValue / 2);
} }
private int GetMinBitrate(int sourceBitrate, int requestedBitrate) private int GetMinBitrate(int sourceBitrate, int requestedBitrate)