update params when stream copying

This commit is contained in:
Luke Pulverenti 2015-12-12 10:42:00 -05:00
parent d3a97e63f0
commit 049c13cec1
3 changed files with 31 additions and 44 deletions

View File

@ -2178,6 +2178,19 @@ namespace MediaBrowser.Api.Playback
inputModifier += " " + videoDecoder;
}
if (state.VideoRequest != null)
{
var videoCodec = GetVideoEncoder(state);
// See if we can save come cpu cycles by avoiding encoding
if (string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
if (string.Equals(state.OutputContainer, "mkv", StringComparison.OrdinalIgnoreCase))
{
inputModifier += " -noaccurate_seek";
}
}
}
return inputModifier;
}

View File

@ -291,25 +291,6 @@ namespace MediaBrowser.Api.Playback.Hls
private double[] GetSegmentLengths(StreamState state)
{
var result = new List<double>();
if (state.VideoRequest != null)
{
var encoder = GetVideoEncoder(state);
if (string.Equals(encoder, "copy", StringComparison.OrdinalIgnoreCase))
{
var videoStream = state.VideoStream;
if (videoStream.KeyFrames != null && videoStream.KeyFrames.Count > 0)
{
foreach (var frame in videoStream.KeyFrames)
{
var seconds = TimeSpan.FromMilliseconds(frame).TotalSeconds;
seconds -= result.Sum();
result.Add(seconds);
}
return result.ToArray();
}
}
}
var ticks = state.RunTimeTicks ?? 0;
@ -936,27 +917,8 @@ namespace MediaBrowser.Api.Playback.Hls
protected override bool CanStreamCopyVideo(VideoStreamRequest request, MediaStream videoStream)
{
if (videoStream.KeyFrames == null || videoStream.KeyFrames.Count == 0)
{
Logger.Debug("Cannot stream copy video due to missing keyframe info");
return false;
}
var previousSegment = 0;
foreach (var frame in videoStream.KeyFrames)
{
var length = frame - previousSegment;
// Don't allow really long segments because this could result in long download times
if (length > 10000)
{
Logger.Debug("Cannot stream copy video due to long segment length of {0}ms", length);
return false;
}
previousSegment = frame;
}
return base.CanStreamCopyVideo(request, videoStream);
return false;
//return base.CanStreamCopyVideo(request, videoStream);
}
}
}

View File

@ -100,6 +100,7 @@ namespace MediaBrowser.Api.Playback.Progressive
{
// Comparison: https://github.com/jansmolders86/mediacenterjs/blob/master/lib/transcoding/desktop.js
format = " -f mp4 -movflags frag_keyframe+empty_moov";
//format = " -avoid_negative_ts disabled -start_at_zero -copyts -f mp4 -movflags frag_keyframe+empty_moov";
}
var threads = GetNumberOfThreads(state, string.Equals(videoCodec, "libvpx", StringComparison.OrdinalIgnoreCase));
@ -135,11 +136,22 @@ namespace MediaBrowser.Api.Playback.Progressive
}
// See if we can save come cpu cycles by avoiding encoding
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
{
return state.VideoStream != null && IsH264(state.VideoStream) && string.Equals(state.OutputContainer, "ts", StringComparison.OrdinalIgnoreCase) ?
args + " -bsf:v h264_mp4toannexb" :
args;
var isOutputMkv = string.Equals(state.OutputContainer, "mkv", StringComparison.OrdinalIgnoreCase);
if (isOutputMkv)
{
//args += " -copyts -avoid_negative_ts disabled -start_at_zero";
}
if (state.VideoStream != null && IsH264(state.VideoStream) &&
(string.Equals(state.OutputContainer, "ts", StringComparison.OrdinalIgnoreCase) || isOutputMkv))
{
args += " -bsf:v h264_mp4toannexb";
}
return args;
}
var keyFrameArg = string.Format(" -force_key_frames expr:gte(t,n_forced*{0})",