From 0c58d536e01df9d2a5c9a3986686c988cf467baa Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 28 Mar 2013 01:19:58 -0400 Subject: [PATCH 1/5] fixing merge issue --- .../EntryPoints/WebSocketEvents.cs | 6 +++--- Nuget/MediaBrowser.Common.Internal.nuspec | 4 ++-- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs b/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs index 2ee3193dc9..50d625739b 100644 --- a/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs +++ b/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs @@ -88,13 +88,13 @@ namespace MediaBrowser.ServerApplication.EntryPoints void _taskManager_TaskCompleted(object sender, GenericEventArgs e) { - _serverManager.SendWebSocketMessage("ScheduledTaskEndExecute", e.Argument); + _serverManager.SendWebSocketMessage("ScheduledTaskEnded", e.Argument); } void _taskManager_TaskExecuting(object sender, EventArgs e) { var task = (IScheduledTask) sender; - _serverManager.SendWebSocketMessage("ScheduledTaskBeginExecute", task.Name); + _serverManager.SendWebSocketMessage("ScheduledTaskStarted", task.Name); } /// @@ -164,7 +164,7 @@ namespace MediaBrowser.ServerApplication.EntryPoints /// The instance containing the event data. void kernel_HasPendingRestartChanged(object sender, EventArgs e) { - _serverManager.SendWebSocketMessage("HasPendingRestartChanged", _appHost.GetSystemInfo()); + _serverManager.SendWebSocketMessage("RestartRequired", _appHost.GetSystemInfo()); } /// diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 19b811fe98..fbbddc5f31 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.61 + 3.0.62 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 78a4fbbad3..34c9463da3 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.61 + 3.0.62 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 4a9693e7fe..0d554fb46f 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.61 + 3.0.62 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - + From 071e13fb4cb0543ea17836a3969d536842860a91 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 28 Mar 2013 10:42:03 -0400 Subject: [PATCH 2/5] added profile and level params for hls --- MediaBrowser.Api/Playback/Hls/VideoHlsService.cs | 14 ++++++++++++-- MediaBrowser.Api/Playback/StreamRequest.cs | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 699d45de3f..4931383b67 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -8,14 +8,14 @@ using ServiceStack.ServiceHost; namespace MediaBrowser.Api.Playback.Hls { [Route("/Videos/{Id}/stream.m3u8", "GET")] - [ServiceStack.ServiceHost.Api(Description = "Gets a video stream using HTTP live streaming.")] + [Api(Description = "Gets a video stream using HTTP live streaming.")] public class GetHlsVideoStream : VideoStreamRequest { } [Route("/Videos/{Id}/segments/{SegmentId}/stream.ts", "GET")] - [ServiceStack.ServiceHost.Api(Description = "Gets an Http live streaming segment file. Internal use only.")] + [Api(Description = "Gets an Http live streaming segment file. Internal use only.")] public class GetHlsVideoSegment { public string Id { get; set; } @@ -154,6 +154,16 @@ namespace MediaBrowser.Api.Playback.Hls args += " -vsync vfr"; + if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) + { + args += " -profile:v " + state.VideoRequest.Profile; + } + + if (!string.IsNullOrEmpty(state.VideoRequest.Level)) + { + args += " -level 3 " + state.VideoRequest.Level; + } + if (state.SubtitleStream != null) { // This is for internal graphical subs diff --git a/MediaBrowser.Api/Playback/StreamRequest.cs b/MediaBrowser.Api/Playback/StreamRequest.cs index a0b0a1a72d..d4da11e3f3 100644 --- a/MediaBrowser.Api/Playback/StreamRequest.cs +++ b/MediaBrowser.Api/Playback/StreamRequest.cs @@ -135,5 +135,19 @@ namespace MediaBrowser.Api.Playback /// The framerate. [ApiMember(Name = "Framerate", Description = "Optional. A specific video framerate to encode to, e.g. 23.976. Generally this should be omitted unless the device has specific requirements.", IsRequired = false, DataType = "double", ParameterType = "query", Verb = "GET")] public double? Framerate { get; set; } + + /// + /// Gets or sets the profile. + /// + /// The profile. + [ApiMember(Name = "Profile", Description = "Optional. Specify a specific h264 profile, e.g. main, baseline, high.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string Profile { get; set; } + + /// + /// Gets or sets the level. + /// + /// The level. + [ApiMember(Name = "Level", Description = "Optional. Specify a level for the h264 profile, e.g. 3, 3.1.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string Level { get; set; } } } From 8b9d333608b18dfde8278df30a90dfc9daeb42ff Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 28 Mar 2013 10:48:56 -0400 Subject: [PATCH 3/5] added profile and level to progressive streaming --- MediaBrowser.Api/Playback/Progressive/VideoService.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index 7a490cc705..d6514bacb9 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -156,6 +156,17 @@ namespace MediaBrowser.Api.Playback.Progressive } args += " -vsync vfr"; + + if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) + { + args += " -profile:v " + state.VideoRequest.Profile; + } + + if (!string.IsNullOrEmpty(state.VideoRequest.Level)) + { + args += " -level 3 " + state.VideoRequest.Level; + } + } else if (IsH264(state.VideoStream)) { From a59d1f4f70a20eda164814ecb776eaf07ad02435 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 28 Mar 2013 11:22:05 -0400 Subject: [PATCH 4/5] added keyframes to progressive streaming --- .../Playback/Hls/BaseHlsService.cs | 5 +- .../Playback/Hls/VideoHlsService.cs | 4 +- .../Playback/Progressive/VideoService.cs | 72 +++++++++---------- 3 files changed, 40 insertions(+), 41 deletions(-) diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 6004129860..b1879b8d23 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -178,9 +178,7 @@ namespace MediaBrowser.Api.Playback.Hls var probeSize = Kernel.Instance.FFMpegManager.GetProbeSizeArgument(state.Item); - const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,0),gte(t,prev_forced_t+5))"; - - return string.Format("{0} {1} -i {2}{3} -threads 0 {4} {5} {6}{7} -f ssegment -segment_list_flags +live -segment_time 10 -segment_list \"{8}\" \"{9}\"", + return string.Format("{0} {1} -i {2}{3} -threads 0 {4} {5} {6} -f ssegment -segment_list_flags +live -segment_time 10 -segment_list \"{7}\" \"{8}\"", probeSize, GetFastSeekCommandLineParameter(state.Request), GetInputArgument(state.Item, state.IsoMount), @@ -188,7 +186,6 @@ namespace MediaBrowser.Api.Playback.Hls GetMapArgs(state), GetVideoArguments(state), GetAudioArguments(state), - keyFrameArg, outputPath, segmentOutputPath ).Trim(); diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 4931383b67..04b84f791d 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -115,7 +115,9 @@ namespace MediaBrowser.Api.Playback.Hls return IsH264(state.VideoStream) ? "-codec:v:0 copy -bsf h264_mp4toannexb" : "-codec:v:0 copy"; } - var args = "-codec:v:0 " + codec + " -preset superfast"; + const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,0),gte(t,prev_forced_t+5))"; + + var args = "-codec:v:0 " + codec + " -preset superfast" + keyFrameArg; if (state.VideoRequest.VideoBitRate.HasValue) { diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index d6514bacb9..45056d8176 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -131,47 +131,47 @@ namespace MediaBrowser.Api.Playback.Progressive { var args = "-vcodec " + videoCodec; + // See if we can save come cpu cycles by avoiding encoding + if (videoCodec.Equals("copy", StringComparison.OrdinalIgnoreCase)) + { + return IsH264(state.VideoStream) ? args + " -bsf h264_mp4toannexb" : args; + } + + const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,0),gte(t,prev_forced_t+2))"; + + args += keyFrameArg; + var request = state.VideoRequest; - // If we're encoding video, add additional params - if (!videoCodec.Equals("copy", StringComparison.OrdinalIgnoreCase)) + // Add resolution params, if specified + if (request.Width.HasValue || request.Height.HasValue || request.MaxHeight.HasValue || request.MaxWidth.HasValue) { - // Add resolution params, if specified - if (request.Width.HasValue || request.Height.HasValue || request.MaxHeight.HasValue || request.MaxWidth.HasValue) - { - args += GetOutputSizeParam(state, videoCodec); - } - - if (request.Framerate.HasValue) - { - args += string.Format(" -r {0}", request.Framerate.Value); - } - - // Add the audio bitrate - var qualityParam = GetVideoQualityParam(request, videoCodec); - - if (!string.IsNullOrEmpty(qualityParam)) - { - args += " " + qualityParam; - } - - args += " -vsync vfr"; - - if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) - { - args += " -profile:v " + state.VideoRequest.Profile; - } - - if (!string.IsNullOrEmpty(state.VideoRequest.Level)) - { - args += " -level 3 " + state.VideoRequest.Level; - } - + args += GetOutputSizeParam(state, videoCodec); } - else if (IsH264(state.VideoStream)) + + if (request.Framerate.HasValue) { - // FFmpeg will fail to convert and give h264 bitstream malformated error if it isn't used when converting mp4 to transport stream. - args += " -bsf h264_mp4toannexb"; + args += string.Format(" -r {0}", request.Framerate.Value); + } + + // Add the audio bitrate + var qualityParam = GetVideoQualityParam(request, videoCodec); + + if (!string.IsNullOrEmpty(qualityParam)) + { + args += " " + qualityParam; + } + + args += " -vsync vfr"; + + if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) + { + args += " -profile:v " + state.VideoRequest.Profile; + } + + if (!string.IsNullOrEmpty(state.VideoRequest.Level)) + { + args += " -level 3 " + state.VideoRequest.Level; } return args; From 20428bfdaf347e11bb15998895a4e3d395b2826b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 28 Mar 2013 11:52:26 -0400 Subject: [PATCH 5/5] re-organized streaming parameters --- .../Playback/Hls/VideoHlsService.cs | 4 +- .../Playback/Progressive/VideoService.cs | 39 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 04b84f791d..eb72f27d41 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -158,12 +158,12 @@ namespace MediaBrowser.Api.Playback.Hls if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) { - args += " -profile:v " + state.VideoRequest.Profile; + args += " -profile:v" + state.VideoRequest.Profile; } if (!string.IsNullOrEmpty(state.VideoRequest.Level)) { - args += " -level 3 " + state.VideoRequest.Level; + args += " -level 3" + state.VideoRequest.Level; } if (state.SubtitleStream != null) diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index 45056d8176..b30a14ecc8 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -81,17 +81,6 @@ namespace MediaBrowser.Api.Playback.Progressive // Get the output codec name var videoCodec = GetVideoCodec(state.VideoRequest); - var graphicalSubtitleParam = string.Empty; - - if (state.SubtitleStream != null) - { - // This is for internal graphical subs - if (!state.SubtitleStream.IsExternal && (state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 || state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1)) - { - graphicalSubtitleParam = GetInternalGraphicalSubtitleParam(state, videoCodec); - } - } - var format = string.Empty; var keyFrame = string.Empty; @@ -106,7 +95,7 @@ namespace MediaBrowser.Api.Playback.Progressive keyFrame = " -g " + Math.Round(framerate); } - return string.Format("{0} {1} -i {2}{3}{4} -threads 0 {5} {6}{7} {8}{9} \"{10}\"", + return string.Format("{0} {1} -i {2}{3}{4} -threads 0 {5} {6} {7}{8} \"{9}\"", probeSize, GetFastSeekCommandLineParameter(state.Request), GetInputArgument(video, state.IsoMount), @@ -114,7 +103,6 @@ namespace MediaBrowser.Api.Playback.Progressive keyFrame, GetMapArgs(state), GetVideoArguments(state, videoCodec), - graphicalSubtitleParam, GetAudioArguments(state), format, outputPath @@ -125,14 +113,14 @@ namespace MediaBrowser.Api.Playback.Progressive /// Gets video arguments to pass to ffmpeg /// /// The state. - /// The video codec. + /// The video codec. /// System.String. - private string GetVideoArguments(StreamState state, string videoCodec) + private string GetVideoArguments(StreamState state, string codec) { - var args = "-vcodec " + videoCodec; + var args = "-vcodec " + codec; // See if we can save come cpu cycles by avoiding encoding - if (videoCodec.Equals("copy", StringComparison.OrdinalIgnoreCase)) + if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase)) { return IsH264(state.VideoStream) ? args + " -bsf h264_mp4toannexb" : args; } @@ -146,7 +134,7 @@ namespace MediaBrowser.Api.Playback.Progressive // Add resolution params, if specified if (request.Width.HasValue || request.Height.HasValue || request.MaxHeight.HasValue || request.MaxWidth.HasValue) { - args += GetOutputSizeParam(state, videoCodec); + args += GetOutputSizeParam(state, codec); } if (request.Framerate.HasValue) @@ -155,7 +143,7 @@ namespace MediaBrowser.Api.Playback.Progressive } // Add the audio bitrate - var qualityParam = GetVideoQualityParam(request, videoCodec); + var qualityParam = GetVideoQualityParam(request, codec); if (!string.IsNullOrEmpty(qualityParam)) { @@ -166,12 +154,21 @@ namespace MediaBrowser.Api.Playback.Progressive if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) { - args += " -profile:v " + state.VideoRequest.Profile; + args += " -profile:v" + state.VideoRequest.Profile; } if (!string.IsNullOrEmpty(state.VideoRequest.Level)) { - args += " -level 3 " + state.VideoRequest.Level; + args += " -level 3" + state.VideoRequest.Level; + } + + if (state.SubtitleStream != null) + { + // This is for internal graphical subs + if (!state.SubtitleStream.IsExternal && (state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 || state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1)) + { + args += GetInternalGraphicalSubtitleParam(state, codec); + } } return args;