made HLS 64k stream optional
This commit is contained in:
parent
5c3fcaf049
commit
83dd13cc7c
|
@ -123,7 +123,17 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
var audioBitrate = GetAudioBitrateParam(state) ?? 0;
|
var audioBitrate = GetAudioBitrateParam(state) ?? 0;
|
||||||
var videoBitrate = GetVideoBitrateParam(state) ?? 0;
|
var videoBitrate = GetVideoBitrateParam(state) ?? 0;
|
||||||
|
|
||||||
var playlistText = GetMasterPlaylistFileText(playlist, videoBitrate + audioBitrate);
|
var appendBaselineStream = false;
|
||||||
|
var baselineStreamBitrate = 64000;
|
||||||
|
|
||||||
|
var hlsVideoRequest = state.VideoRequest as GetHlsVideoStream;
|
||||||
|
if (hlsVideoRequest != null)
|
||||||
|
{
|
||||||
|
appendBaselineStream = hlsVideoRequest.AppendBaselineStream;
|
||||||
|
baselineStreamBitrate = hlsVideoRequest.BaselineStreamAudioBitRate ?? baselineStreamBitrate;
|
||||||
|
}
|
||||||
|
|
||||||
|
var playlistText = GetMasterPlaylistFileText(playlist, videoBitrate + audioBitrate, appendBaselineStream, baselineStreamBitrate);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -135,7 +145,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetMasterPlaylistFileText(string firstPlaylist, int bitrate)
|
private string GetMasterPlaylistFileText(string firstPlaylist, int bitrate, bool includeBaselineStream, int baselineStreamBitrate)
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
|
@ -150,9 +160,12 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
builder.AppendLine(playlistUrl);
|
builder.AppendLine(playlistUrl);
|
||||||
|
|
||||||
// Low bitrate stream
|
// Low bitrate stream
|
||||||
builder.AppendLine("#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=64000");
|
if (includeBaselineStream)
|
||||||
|
{
|
||||||
|
builder.AppendLine("#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" + baselineStreamBitrate.ToString(UsCulture));
|
||||||
playlistUrl = "hls/" + Path.GetFileName(firstPlaylist).Replace(".m3u8", "-low/stream.m3u8");
|
playlistUrl = "hls/" + Path.GetFileName(firstPlaylist).Replace(".m3u8", "-low/stream.m3u8");
|
||||||
builder.AppendLine(playlistUrl);
|
builder.AppendLine(playlistUrl);
|
||||||
|
}
|
||||||
|
|
||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
@ -246,16 +259,23 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
outputPath
|
outputPath
|
||||||
).Trim();
|
).Trim();
|
||||||
|
|
||||||
if (state.Item is Video)
|
var hlsVideoRequest = state.VideoRequest as GetHlsVideoStream;
|
||||||
|
|
||||||
|
if (hlsVideoRequest != null)
|
||||||
|
{
|
||||||
|
if (hlsVideoRequest.AppendBaselineStream && state.Item is Video)
|
||||||
{
|
{
|
||||||
var lowBitratePath = Path.Combine(Path.GetDirectoryName(outputPath), Path.GetFileNameWithoutExtension(outputPath) + "-low.m3u8");
|
var lowBitratePath = Path.Combine(Path.GetDirectoryName(outputPath), Path.GetFileNameWithoutExtension(outputPath) + "-low.m3u8");
|
||||||
|
|
||||||
var lowBitrateParams = string.Format(" -threads 0 -vn -codec:a:0 libmp3lame -ac 2 -ab 32000 -hls_time 10 -start_number 0 -hls_list_size 1440 \"{0}\"",
|
var bitrate = hlsVideoRequest.BaselineStreamAudioBitRate ?? 64000;
|
||||||
|
|
||||||
|
var lowBitrateParams = string.Format(" -threads 0 -vn -codec:a:0 libmp3lame -ac 2 -ab {1} -hls_time 10 -start_number 0 -hls_list_size 1440 \"{0}\"",
|
||||||
lowBitratePath,
|
lowBitratePath,
|
||||||
state.AudioStream.Index);
|
bitrate / 2);
|
||||||
|
|
||||||
args += " " + lowBitrateParams;
|
args += " " + lowBitrateParams;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,11 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||||
[Api(Description = "Gets a video stream using HTTP live streaming.")]
|
[Api(Description = "Gets a video stream using HTTP live streaming.")]
|
||||||
public class GetHlsVideoStream : VideoStreamRequest
|
public class GetHlsVideoStream : VideoStreamRequest
|
||||||
{
|
{
|
||||||
|
[ApiMember(Name = "BaselineStreamAudioBitRate", Description = "Optional. Specify the audio bitrate for the baseline stream.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
||||||
|
public int? BaselineStreamAudioBitRate { get; set; }
|
||||||
|
|
||||||
|
[ApiMember(Name = "AppendBaselineStream", Description = "Optional. Whether or not to include a baseline audio-only stream in the master playlist.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
|
||||||
|
public bool AppendBaselineStream { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -77,6 +77,18 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The level.</value>
|
/// <value>The level.</value>
|
||||||
public string Level { get; set; }
|
public string Level { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the baseline stream audio bit rate.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The baseline stream audio bit rate.</value>
|
||||||
|
public int? BaselineStreamAudioBitRate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether [append baseline stream].
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if [append baseline stream]; otherwise, <c>false</c>.</value>
|
||||||
|
public bool AppendBaselineStream { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user