This commit is contained in:
Eric Reed 2013-03-28 11:58:59 -04:00
commit 7eabf7e015
8 changed files with 87 additions and 56 deletions

View File

@ -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();

View File

@ -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; }
@ -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)
{
@ -154,6 +156,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

View File

@ -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,42 +113,62 @@ namespace MediaBrowser.Api.Playback.Progressive
/// Gets video arguments to pass to ffmpeg
/// </summary>
/// <param name="state">The state.</param>
/// <param name="videoCodec">The video codec.</param>
/// <param name="codec">The video codec.</param>
/// <returns>System.String.</returns>
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 (codec.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";
args += GetOutputSizeParam(state, codec);
}
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, codec);
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;
}
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;

View File

@ -135,5 +135,19 @@ namespace MediaBrowser.Api.Playback
/// <value>The framerate.</value>
[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; }
/// <summary>
/// Gets or sets the profile.
/// </summary>
/// <value>The profile.</value>
[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; }
/// <summary>
/// Gets or sets the level.
/// </summary>
/// <value>The level.</value>
[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; }
}
}

View File

@ -88,13 +88,13 @@ namespace MediaBrowser.ServerApplication.EntryPoints
void _taskManager_TaskCompleted(object sender, GenericEventArgs<TaskResult> 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);
}
/// <summary>
@ -164,7 +164,7 @@ namespace MediaBrowser.ServerApplication.EntryPoints
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
void kernel_HasPendingRestartChanged(object sender, EventArgs e)
{
_serverManager.SendWebSocketMessage("HasPendingRestartChanged", _appHost.GetSystemInfo());
_serverManager.SendWebSocketMessage("RestartRequired", _appHost.GetSystemInfo());
}
/// <summary>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.61</version>
<version>3.0.62</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.61" />
<dependency id="MediaBrowser.Common" version="3.0.62" />
<dependency id="NLog" version="2.0.0.2000" />
<dependency id="ServiceStack.Text" version="3.9.38" />
<dependency id="protobuf-net" version="2.0.0.621" />

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.61</version>
<version>3.0.62</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.61</version>
<version>3.0.62</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.61" />
<dependency id="MediaBrowser.Common" version="3.0.62" />
</dependencies>
</metadata>
<files>