add remote streaming capabilities

This commit is contained in:
Luke Pulverenti 2013-05-01 16:07:20 -04:00
parent f9ec1ce37f
commit e9cfa6cd26
6 changed files with 73 additions and 12 deletions

View File

@ -166,6 +166,11 @@ namespace MediaBrowser.Api.Playback
{
var args = string.Empty;
if (state.Item.LocationType == LocationType.Remote)
{
return string.Empty;
}
if (state.VideoStream != null)
{
args += string.Format("-map 0:{0}", state.VideoStream.Index);
@ -179,6 +184,7 @@ namespace MediaBrowser.Api.Playback
{
args += string.Format(" -map 0:{0}", state.AudioStream.Index);
}
else
{
args += " -map -0:a";
@ -268,8 +274,20 @@ namespace MediaBrowser.Api.Playback
// Need to perform calculations manually
// Try to account for bad media info
var currentHeight = state.VideoStream.Height ?? request.MaxHeight ?? request.Height ?? 0;
var currentWidth = state.VideoStream.Width ?? request.MaxWidth ?? request.Width ?? 0;
var currentHeight = request.MaxHeight ?? request.Height ?? 0;
var currentWidth = request.MaxWidth ?? request.Width ?? 0;
if (state.VideoStream != null)
{
if (state.VideoStream.Height.HasValue)
{
currentHeight = state.VideoStream.Height.Value;
}
if (state.VideoStream.Width.HasValue)
{
currentWidth = state.VideoStream.Width.Value;
}
}
var outputSize = DrawingUtils.Resize(currentWidth, currentHeight, request.Width, request.Height, request.MaxWidth, request.MaxHeight);
@ -603,6 +621,21 @@ namespace MediaBrowser.Api.Playback
}
}
/// <summary>
/// Gets the user agent param.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
protected string GetUserAgentParam(BaseItem item)
{
if (item.Path.IndexOf("apple.com", StringComparison.OrdinalIgnoreCase) != -1)
{
return "-user-agent \"QuickTime/7.6.2\"";
}
return string.Empty;
}
/// <summary>
/// Processes the exited.
/// </summary>
@ -704,7 +737,6 @@ namespace MediaBrowser.Api.Playback
state.AudioStream = GetMediaStream(media.MediaStreams, null, MediaStreamType.Audio, true);
}
return state;
}

View File

@ -194,8 +194,9 @@ namespace MediaBrowser.Api.Playback.Hls
var probeSize = GetProbeSizeArgument(state.Item);
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}\"",
return string.Format("{0} {1} {2} -i {3}{4} -threads 0 {5} {6} {7} -f ssegment -segment_list_flags +live -segment_time 10 -segment_list \"{8}\" \"{9}\"",
probeSize,
GetUserAgentParam(state.Item),
GetFastSeekCommandLineParameter(state.Request),
GetInputArgument(state.Item, state.IsoMount),
GetSlowSeekCommandLineParameter(state.Request),

View File

@ -108,10 +108,11 @@ namespace MediaBrowser.Api.Playback.Progressive
format = " -f mp4 -movflags frag_keyframe+empty_moov";
}
var threads = videoCodec.Equals("libvpx", StringComparison.OrdinalIgnoreCase) ? 2 : 0;
var threads = 0;
return string.Format("{0} {1} -i {2}{3}{4} {5} {6} -threads {7} {8}{9} \"{10}\"",
return string.Format("{0} {1} {2} -i {3}{4}{5} {6} {7} -threads {8} {9}{10} \"{11}\"",
probeSize,
GetUserAgentParam(state.Item),
GetFastSeekCommandLineParameter(state.Request),
GetInputArgument(video, state.IsoMount),
GetSlowSeekCommandLineParameter(state.Request),
@ -139,7 +140,7 @@ namespace MediaBrowser.Api.Playback.Progressive
// 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;
return state.VideoStream != null && 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))";

View File

@ -99,6 +99,10 @@ namespace MediaBrowser.Common.MediaInfo
/// <summary>
/// The DVD
/// </summary>
Dvd
Dvd,
/// <summary>
/// The URL
/// </summary>
Url
}
}

View File

@ -47,6 +47,14 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
}
}
break;
case VideoType.VideoFile:
{
if (video.LocationType == LocationType.Remote)
{
type = InputType.Url;
}
break;
}
}
return inputPath;

View File

@ -310,6 +310,9 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
case InputType.Bluray:
inputPath = GetBlurayInputArgument(inputFiles[0]);
break;
case InputType.Url:
inputPath = GetHttpInputArgument(inputFiles);
break;
default:
throw new ArgumentException("Unrecognized InputType");
}
@ -317,6 +320,18 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
return inputPath;
}
/// <summary>
/// Gets the HTTP input argument.
/// </summary>
/// <param name="inputFiles">The input files.</param>
/// <returns>System.String.</returns>
private string GetHttpInputArgument(string[] inputFiles)
{
var url = inputFiles[0];
return string.Format("\"{0}\"", url);
}
/// <summary>
/// Gets the probe size argument.
/// </summary>
@ -1005,7 +1020,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
/// </summary>
/// <param name="path">The path.</param>
/// <returns>System.String.</returns>
public string GetFileInputArgument(string path)
private string GetFileInputArgument(string path)
{
return string.Format("file:\"{0}\"", path);
}
@ -1015,7 +1030,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
/// </summary>
/// <param name="playableStreamFiles">The playable stream files.</param>
/// <returns>System.String.</returns>
public string GetConcatInputArgument(string[] playableStreamFiles)
private string GetConcatInputArgument(string[] playableStreamFiles)
{
// Get all streams
// If there's more than one we'll need to use the concat command
@ -1027,7 +1042,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
}
// Determine the input path for video files
return string.Format("file:\"{0}\"", playableStreamFiles[0]);
return GetFileInputArgument(playableStreamFiles[0]);
}
/// <summary>
@ -1035,7 +1050,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
/// </summary>
/// <param name="blurayRoot">The bluray root.</param>
/// <returns>System.String.</returns>
public string GetBlurayInputArgument(string blurayRoot)
private string GetBlurayInputArgument(string blurayRoot)
{
return string.Format("bluray:\"{0}\"", blurayRoot);
}