aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api
diff options
context:
space:
mode:
authorEric Reed <ebr@mediabrowser3.com>2013-03-28 11:58:59 -0400
committerEric Reed <ebr@mediabrowser3.com>2013-03-28 11:58:59 -0400
commit7eabf7e0153d4b3574c44c72d2a8c2a14d867bc2 (patch)
treef0fd89c819bd5ab1dee2b1fd9d245836f68da5f9 /MediaBrowser.Api
parent18ff0098741ee158ac38407e16131d00a98a3412 (diff)
parent20428bfdaf347e11bb15998895a4e3d395b2826b (diff)
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Diffstat (limited to 'MediaBrowser.Api')
-rw-r--r--MediaBrowser.Api/Playback/Hls/BaseHlsService.cs5
-rw-r--r--MediaBrowser.Api/Playback/Hls/VideoHlsService.cs18
-rw-r--r--MediaBrowser.Api/Playback/Progressive/VideoService.cs82
-rw-r--r--MediaBrowser.Api/Playback/StreamRequest.cs14
4 files changed, 75 insertions, 44 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 699d45de3f..eb72f27d41 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; }
@@ -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
diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs
index 7a490cc705..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,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);
- }
+ args += GetOutputSizeParam(state, codec);
+ }
- if (request.Framerate.HasValue)
- {
- args += string.Format(" -r {0}", request.Framerate.Value);
- }
+ if (request.Framerate.HasValue)
+ {
+ args += string.Format(" -r {0}", request.Framerate.Value);
+ }
- // Add the audio bitrate
- var qualityParam = GetVideoQualityParam(request, videoCodec);
+ // Add the audio bitrate
+ var qualityParam = GetVideoQualityParam(request, codec);
- if (!string.IsNullOrEmpty(qualityParam))
- {
- args += " " + qualityParam;
- }
+ if (!string.IsNullOrEmpty(qualityParam))
+ {
+ args += " " + qualityParam;
+ }
- args += " -vsync vfr";
+ args += " -vsync vfr";
+
+ if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
+ {
+ args += " -profile:v" + state.VideoRequest.Profile;
}
- else if (IsH264(state.VideoStream))
+
+ if (!string.IsNullOrEmpty(state.VideoRequest.Level))
+ {
+ args += " -level 3" + state.VideoRequest.Level;
+ }
+
+ if (state.SubtitleStream != null)
{
- // 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";
+ // 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;
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
/// <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; }
}
}