mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-06-23 15:30:56 -04:00
better bitrate syncing
This commit is contained in:
parent
87c4d447f8
commit
a5fa31cf94
@ -659,6 +659,32 @@ namespace MediaBrowser.Api.Playback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int? GetVideoBitrateParam(StreamState state)
|
||||||
|
{
|
||||||
|
if (state.VideoRequest.VideoBitRate.HasValue)
|
||||||
|
{
|
||||||
|
// Make sure we don't request a bitrate higher than the source
|
||||||
|
var currentBitrate = state.VideoStream == null ? state.VideoRequest.VideoBitRate.Value : state.VideoStream.BitRate ?? state.VideoRequest.VideoBitRate.Value;
|
||||||
|
|
||||||
|
return Math.Min(currentBitrate, state.VideoRequest.VideoBitRate.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int? GetAudioBitrateParam(StreamState state)
|
||||||
|
{
|
||||||
|
if (state.Request.AudioBitRate.HasValue)
|
||||||
|
{
|
||||||
|
// Make sure we don't request a bitrate higher than the source
|
||||||
|
var currentBitrate = state.AudioStream == null ? state.Request.AudioBitRate.Value : state.AudioStream.BitRate ?? state.Request.AudioBitRate.Value;
|
||||||
|
|
||||||
|
return Math.Min(currentBitrate, state.Request.AudioBitRate.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the user agent param.
|
/// Gets the user agent param.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -119,7 +119,10 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
await WaitForMinimumSegmentCount(playlist, 3).ConfigureAwait(false);
|
await WaitForMinimumSegmentCount(playlist, 3).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var playlistText = GetMasterPlaylistFileText(playlist, state.VideoRequest.VideoBitRate.Value + state.Request.AudioBitRate.Value);
|
var audioBitrate = GetAudioBitrateParam(state) ?? 0;
|
||||||
|
var videoBitrate = GetVideoBitrateParam(state) ?? 0;
|
||||||
|
|
||||||
|
var playlistText = GetMasterPlaylistFileText(playlist, videoBitrate + audioBitrate);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -146,9 +146,11 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
args += " -ar " + state.Request.AudioSampleRate.Value;
|
args += " -ar " + state.Request.AudioSampleRate.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.Request.AudioBitRate.HasValue)
|
var bitrate = GetAudioBitrateParam(state);
|
||||||
|
|
||||||
|
if (bitrate.HasValue)
|
||||||
{
|
{
|
||||||
args += " -ab " + state.Request.AudioBitRate.Value;
|
args += " -ab " + bitrate.Value.ToString(UsCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
var volParam = string.Empty;
|
var volParam = string.Empty;
|
||||||
@ -187,14 +189,11 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
|
|
||||||
var args = "-codec:v:0 " + codec + " -preset superfast" + keyFrameArg;
|
var args = "-codec:v:0 " + codec + " -preset superfast" + keyFrameArg;
|
||||||
|
|
||||||
if (state.VideoRequest.VideoBitRate.HasValue)
|
var bitrate = GetVideoBitrateParam(state);
|
||||||
|
|
||||||
|
if (bitrate.HasValue)
|
||||||
{
|
{
|
||||||
// Make sure we don't request a bitrate higher than the source
|
args += string.Format(" -b:v {0}", bitrate.Value.ToString(UsCulture));
|
||||||
var currentBitrate = state.VideoStream == null ? state.VideoRequest.VideoBitRate.Value : state.VideoStream.BitRate ?? state.VideoRequest.VideoBitRate.Value;
|
|
||||||
|
|
||||||
var bitrate = Math.Min(currentBitrate, state.VideoRequest.VideoBitRate.Value);
|
|
||||||
|
|
||||||
args += string.Format(" -b:v {0}", bitrate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add resolution params, if specified
|
// Add resolution params, if specified
|
||||||
|
@ -93,9 +93,11 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|||||||
audioTranscodeParams.Add("-strict experimental");
|
audioTranscodeParams.Add("-strict experimental");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.AudioBitRate.HasValue)
|
var bitrate = GetAudioBitrateParam(state);
|
||||||
|
|
||||||
|
if (bitrate.HasValue)
|
||||||
{
|
{
|
||||||
audioTranscodeParams.Add("-ab " + request.AudioBitRate.Value);
|
audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(UsCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
var channels = GetNumAudioChannelsParam(request, state.AudioStream);
|
var channels = GetNumAudioChannelsParam(request, state.AudioStream);
|
||||||
|
@ -236,9 +236,11 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|||||||
args += " -ar " + request.AudioSampleRate.Value;
|
args += " -ar " + request.AudioSampleRate.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.AudioBitRate.HasValue)
|
var bitrate = GetAudioBitrateParam(state);
|
||||||
|
|
||||||
|
if (bitrate.HasValue)
|
||||||
{
|
{
|
||||||
args += " -ab " + request.AudioBitRate.Value;
|
args += " -ab " + bitrate.Value.ToString(UsCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
var volParam = string.Empty;
|
var volParam = string.Empty;
|
||||||
@ -283,16 +285,13 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|||||||
else if (videoCodec.Equals("mpeg4", StringComparison.OrdinalIgnoreCase))
|
else if (videoCodec.Equals("mpeg4", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
args = "-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -bf 2";
|
args = "-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -bf 2";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.VideoRequest.VideoBitRate.HasValue)
|
var bitrate = GetVideoBitrateParam(state);
|
||||||
|
|
||||||
|
if (bitrate.HasValue)
|
||||||
{
|
{
|
||||||
// Make sure we don't request a bitrate higher than the source
|
args += " -b:v " + bitrate.Value.ToString(UsCulture);
|
||||||
var currentBitrate = state.VideoStream == null ? state.VideoRequest.VideoBitRate.Value : state.VideoStream.BitRate ?? state.VideoRequest.VideoBitRate.Value;
|
|
||||||
|
|
||||||
var bitrate = Math.Min(currentBitrate, state.VideoRequest.VideoBitRate.Value);
|
|
||||||
|
|
||||||
args += " -b:v " + bitrate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return args.Trim();
|
return args.Trim();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user