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>
|
||||
/// Gets the user agent param.
|
||||
/// </summary>
|
||||
|
|
|
@ -119,7 +119,10 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||
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
|
||||
{
|
||||
|
|
|
@ -146,9 +146,11 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||
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;
|
||||
|
@ -187,14 +189,11 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||
|
||||
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
|
||||
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);
|
||||
args += string.Format(" -b:v {0}", bitrate.Value.ToString(UsCulture));
|
||||
}
|
||||
|
||||
// Add resolution params, if specified
|
||||
|
|
|
@ -93,9 +93,11 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|||
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);
|
||||
|
|
|
@ -236,9 +236,11 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|||
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;
|
||||
|
@ -283,16 +285,13 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|||
else if (videoCodec.Equals("mpeg4", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
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
|
||||
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;
|
||||
args += " -b:v " + bitrate.Value.ToString(UsCulture);
|
||||
}
|
||||
|
||||
return args.Trim();
|
||||
|
|
Loading…
Reference in New Issue
Block a user