mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-17 19:08:53 -07:00
136 lines
5.0 KiB
C#
136 lines
5.0 KiB
C#
using MediaBrowser.Controller.Configuration;
|
|
using MediaBrowser.Controller.Devices;
|
|
using MediaBrowser.Controller.Dlna;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.MediaEncoding;
|
|
using MediaBrowser.Model.IO;
|
|
using MediaBrowser.Model.Serialization;
|
|
using System;
|
|
using MediaBrowser.Common.IO;
|
|
using MediaBrowser.Controller.IO;
|
|
using MediaBrowser.Controller.Net;
|
|
using MediaBrowser.Model.IO;
|
|
using MediaBrowser.Model.Dlna;
|
|
using MediaBrowser.Model.Services;
|
|
|
|
namespace MediaBrowser.Api.Playback.Hls
|
|
{
|
|
[Route("/Videos/{Id}/live.m3u8", "GET")]
|
|
public class GetLiveHlsStream : VideoStreamRequest
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Class VideoHlsService
|
|
/// </summary>
|
|
public class VideoHlsService : BaseHlsService
|
|
{
|
|
public object Get(GetLiveHlsStream request)
|
|
{
|
|
return ProcessRequest(request, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the audio arguments.
|
|
/// </summary>
|
|
/// <param name="state">The state.</param>
|
|
/// <returns>System.String.</returns>
|
|
protected override string GetAudioArguments(StreamState state)
|
|
{
|
|
var codec = EncodingHelper.GetAudioEncoder(state);
|
|
|
|
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return "-codec:a:0 copy";
|
|
}
|
|
|
|
var args = "-codec:a:0 " + codec;
|
|
|
|
var channels = state.OutputAudioChannels;
|
|
|
|
if (channels.HasValue)
|
|
{
|
|
args += " -ac " + channels.Value;
|
|
}
|
|
|
|
var bitrate = state.OutputAudioBitrate;
|
|
|
|
if (bitrate.HasValue)
|
|
{
|
|
args += " -ab " + bitrate.Value.ToString(UsCulture);
|
|
}
|
|
|
|
args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), true);
|
|
|
|
return args;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the video arguments.
|
|
/// </summary>
|
|
/// <param name="state">The state.</param>
|
|
/// <returns>System.String.</returns>
|
|
protected override string GetVideoArguments(StreamState state)
|
|
{
|
|
var codec = EncodingHelper.GetVideoEncoder(state, ApiEntryPoint.Instance.GetEncodingOptions());
|
|
|
|
var args = "-codec:v:0 " + codec;
|
|
|
|
if (state.EnableMpegtsM2TsMode)
|
|
{
|
|
args += " -mpegts_m2ts_mode 1";
|
|
}
|
|
|
|
// See if we can save come cpu cycles by avoiding encoding
|
|
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
// if h264_mp4toannexb is ever added, do not use it for live tv
|
|
if (state.VideoStream != null && EncodingHelper.IsH264(state.VideoStream) && !string.Equals(state.VideoStream.NalLengthSize, "0", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
args += " -bsf:v h264_mp4toannexb";
|
|
}
|
|
args += " -flags -global_header";
|
|
return args;
|
|
}
|
|
|
|
var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"",
|
|
state.SegmentLength.ToString(UsCulture));
|
|
|
|
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode;
|
|
|
|
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
|
args += " " + EncodingHelper.GetVideoQualityParam(state, EncodingHelper.GetH264Encoder(state, encodingOptions), encodingOptions, GetDefaultH264Preset()) + keyFrameArg;
|
|
|
|
// Add resolution params, if specified
|
|
if (!hasGraphicalSubs)
|
|
{
|
|
args += EncodingHelper.GetOutputSizeParam(state, codec);
|
|
}
|
|
|
|
// This is for internal graphical subs
|
|
if (hasGraphicalSubs)
|
|
{
|
|
args += EncodingHelper.GetGraphicalSubtitleParam(state, codec);
|
|
}
|
|
|
|
args += " -flags -global_header";
|
|
|
|
return args;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the segment file extension.
|
|
/// </summary>
|
|
/// <param name="state">The state.</param>
|
|
/// <returns>System.String.</returns>
|
|
protected override string GetSegmentFileExtension(StreamState state)
|
|
{
|
|
return ".ts";
|
|
}
|
|
|
|
public VideoHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer, IAuthorizationContext authorizationContext) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer, authorizationContext)
|
|
{
|
|
}
|
|
}
|
|
}
|