|
|
|
@ -265,9 +265,15 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
double startSeconds = 0;
|
|
|
|
|
var lengths = GetSegmentLengths(state);
|
|
|
|
|
|
|
|
|
|
if (requestedIndex >= lengths.Length)
|
|
|
|
|
{
|
|
|
|
|
var msg = string.Format("Invalid segment index requested: {0} - Segment count: {1}", requestedIndex, lengths.Length);
|
|
|
|
|
throw new ArgumentException(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < requestedIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
startSeconds += lengths[requestedIndex];
|
|
|
|
|
startSeconds += lengths[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var position = TimeSpan.FromSeconds(startSeconds).Ticks;
|
|
|
|
@ -279,9 +285,15 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
double startSeconds = 0;
|
|
|
|
|
var lengths = GetSegmentLengths(state);
|
|
|
|
|
|
|
|
|
|
if (requestedIndex >= lengths.Length)
|
|
|
|
|
{
|
|
|
|
|
var msg = string.Format("Invalid segment index requested: {0} - Segment count: {1}", requestedIndex, lengths.Length);
|
|
|
|
|
throw new ArgumentException(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i <= requestedIndex; i++)
|
|
|
|
|
{
|
|
|
|
|
startSeconds += lengths[requestedIndex];
|
|
|
|
|
startSeconds += lengths[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var position = TimeSpan.FromSeconds(startSeconds).Ticks;
|
|
|
|
@ -348,6 +360,8 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Debug("Deleting partial HLS file {0}", file.FullName);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
FileSystem.DeleteFile(file.FullName);
|
|
|
|
@ -723,7 +737,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
|
|
|
|
|
foreach (var length in segmentLengths)
|
|
|
|
|
{
|
|
|
|
|
builder.AppendLine("#EXTINF:" + length.ToString("0.0000", UsCulture) + ",");
|
|
|
|
|
builder.AppendLine("#EXTINF:" + length.ToString("0.0000", UsCulture) + ", nodesc");
|
|
|
|
|
|
|
|
|
|
builder.AppendLine(string.Format("hls1/{0}/{1}{2}{3}",
|
|
|
|
|
|
|
|
|
@ -826,7 +840,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
args += " -bsf:v h264_mp4toannexb";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args += " -flags -global_header";
|
|
|
|
|
//args += " -flags -global_header";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -851,7 +865,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
args += GetGraphicalSubtitleParam(state, codec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args += " -flags -global_header";
|
|
|
|
|
//args += " -flags -global_header";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EnableCopyTs(state) && args.IndexOf("-copyts", StringComparison.OrdinalIgnoreCase) == -1)
|
|
|
|
@ -875,27 +889,25 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
var inputModifier = GetInputModifier(state, false);
|
|
|
|
|
|
|
|
|
|
// If isEncoding is true we're actually starting ffmpeg
|
|
|
|
|
var startNumberParam = isEncoding ? GetStartNumber(state).ToString(UsCulture) : "0";
|
|
|
|
|
|
|
|
|
|
var toTimeParam = string.Empty;
|
|
|
|
|
var timestampOffsetParam = string.Empty;
|
|
|
|
|
|
|
|
|
|
if (state.IsOutputVideo && !EnableCopyTs(state) && !string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase) && (state.Request.StartTimeTicks ?? 0) > 0)
|
|
|
|
|
{
|
|
|
|
|
timestampOffsetParam = " -output_ts_offset " + MediaEncoder.GetTimeParameter(state.Request.StartTimeTicks ?? 0);
|
|
|
|
|
}
|
|
|
|
|
var startNumber = GetStartNumber(state);
|
|
|
|
|
var startNumberParam = isEncoding ? startNumber.ToString(UsCulture) : "0";
|
|
|
|
|
|
|
|
|
|
var mapArgs = state.IsOutputVideo ? GetMapArgs(state) : string.Empty;
|
|
|
|
|
var enableSplittingOnNonKeyFrames = string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase) && false;
|
|
|
|
|
var useGenericSegmenter = true;
|
|
|
|
|
|
|
|
|
|
// TODO: check libavformat version for 57 50.100 and use -hls_flags split_by_time
|
|
|
|
|
var hlsProtocolSupportsSplittingByTime = false;
|
|
|
|
|
|
|
|
|
|
if (enableSplittingOnNonKeyFrames && !hlsProtocolSupportsSplittingByTime)
|
|
|
|
|
if (useGenericSegmenter)
|
|
|
|
|
{
|
|
|
|
|
var outputTsArg = Path.Combine(Path.GetDirectoryName(outputPath), Path.GetFileNameWithoutExtension(outputPath)) + "%d" + GetSegmentFileExtension(state);
|
|
|
|
|
|
|
|
|
|
return string.Format("{0} {10} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -segment_time {6} -break_non_keyframes 1 -segment_format mpegts -segment_list_type m3u8 -segment_start_number {7} -segment_list \"{8}\" -y \"{9}\"",
|
|
|
|
|
var timeDeltaParam = String.Empty;
|
|
|
|
|
|
|
|
|
|
if (isEncoding && startNumber > 0)
|
|
|
|
|
{
|
|
|
|
|
var startTime = state.SegmentLength * startNumber;
|
|
|
|
|
timeDeltaParam = string.Format("-segment_time_delta -{0}", startTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Format("{0} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -segment_time {6} {10} -individual_header_trailer 0 -segment_format mpegts -segment_list_type m3u8 -segment_start_number {7} -segment_list \"{8}\" -y \"{9}\"",
|
|
|
|
|
inputModifier,
|
|
|
|
|
GetInputArgument(state),
|
|
|
|
|
threads,
|
|
|
|
@ -906,27 +918,21 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
startNumberParam,
|
|
|
|
|
outputPath,
|
|
|
|
|
outputTsArg,
|
|
|
|
|
toTimeParam
|
|
|
|
|
).Trim();
|
|
|
|
|
timeDeltaParam
|
|
|
|
|
).Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var splitByTime = hlsProtocolSupportsSplittingByTime && enableSplittingOnNonKeyFrames;
|
|
|
|
|
var splitByTimeArg = splitByTime ? " -hls_flags split_by_time" : "";
|
|
|
|
|
|
|
|
|
|
return string.Format("{0}{12} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4}{5} {6} -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -hls_time {7}{8} -start_number {9} -hls_list_size {10} -y \"{11}\"",
|
|
|
|
|
return string.Format("{0} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -hls_time {6} -individual_header_trailer 0 -start_number {7} -hls_list_size {8} -y \"{9}\"",
|
|
|
|
|
inputModifier,
|
|
|
|
|
GetInputArgument(state),
|
|
|
|
|
threads,
|
|
|
|
|
mapArgs,
|
|
|
|
|
GetVideoArguments(state),
|
|
|
|
|
timestampOffsetParam,
|
|
|
|
|
GetAudioArguments(state),
|
|
|
|
|
state.SegmentLength.ToString(UsCulture),
|
|
|
|
|
splitByTimeArg,
|
|
|
|
|
startNumberParam,
|
|
|
|
|
state.HlsListSize.ToString(UsCulture),
|
|
|
|
|
outputPath,
|
|
|
|
|
toTimeParam
|
|
|
|
|
outputPath
|
|
|
|
|
).Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|