diff --git a/MediaBrowser.Api/Playback/Hls/MpegDashService.cs b/MediaBrowser.Api/Playback/Hls/MpegDashService.cs index c8ccdf0715..3e4d611a8c 100644 --- a/MediaBrowser.Api/Playback/Hls/MpegDashService.cs +++ b/MediaBrowser.Api/Playback/Hls/MpegDashService.cs @@ -38,8 +38,8 @@ namespace MediaBrowser.Api.Playback.Hls } } - [Route("/Videos/{Id}/dash/{SegmentId}.ts", "GET")] - [Route("/Videos/{Id}/dash/{SegmentId}.mp4", "GET")] + [Route("/Videos/{Id}/dash/audio/{SegmentId}.m4s", "GET")] + [Route("/Videos/{Id}/dash/video/{SegmentId}.m4s", "GET")] public class GetDashSegment : VideoStreamRequest { /// @@ -111,50 +111,62 @@ namespace MediaBrowser.Api.Playback.Hls builder.Append(""); - var profile = string.Equals(GetSegmentFileExtension(state), ".ts", StringComparison.OrdinalIgnoreCase) - ? "urn:mpeg:dash:profile:mp2t-simple:2011" - : "urn:mpeg:dash:profile:mp2t-simple:2011"; - builder.AppendFormat( - "", - duration, - state.SegmentLength.ToString(CultureInfo.InvariantCulture)); + "", + duration); - builder.Append(""); + builder.Append(""); builder.Append(""); - builder.AppendFormat("", duration); - builder.Append(""); + builder.Append(""); + builder.Append(GetVideoAdaptationSet(state)); + builder.Append(GetAudioAdaptationSet(state)); + builder.Append(""); - builder.Append(""); + builder.Append(""); - var lang = state.AudioStream != null ? state.AudioStream.Language : null; - if (string.IsNullOrWhiteSpace(lang)) lang = "und"; + return builder.ToString(); + } - builder.AppendFormat("", lang); + private string GetVideoAdaptationSet(StreamState state) + { + var builder = new StringBuilder(); - builder.Append(GetRepresentationOpenElement(state, lang)); + builder.Append(""); + builder.Append(GetVideoRepresentationOpenElement(state)); - AppendSegmentList(state, builder); + AppendSegmentList(state, builder, "video"); builder.Append(""); builder.Append(""); - builder.Append(""); - builder.Append(""); + return builder.ToString(); + } + + private string GetAudioAdaptationSet(StreamState state) + { + var builder = new StringBuilder(); + builder.Append(""); + builder.Append(GetAudioRepresentationOpenElement(state)); + + builder.Append(""); + + AppendSegmentList(state, builder, "audio"); + + builder.Append(""); + builder.Append(""); + return builder.ToString(); } - private string GetRepresentationOpenElement(StreamState state, string language) + private string GetVideoRepresentationOpenElement(StreamState state) { - var codecs = GetVideoCodecDescriptor(state) + "," + GetAudioCodecDescriptor(state); + var codecs = GetVideoCodecDescriptor(state); - var mime = string.Equals(GetSegmentFileExtension(state), ".ts", StringComparison.OrdinalIgnoreCase) - ? "video/mp2t" - : "video/mp4"; + var mime = "video/mp4"; - var xml = ""); - + builder.Append(""); while (seconds > 0) { - var segmentUrl = string.Format("dash/{0}{1}{2}", + var segmentUrl = string.Format("dash/{3}/{0}{1}{2}", index.ToString(UsCulture), extension, - SecurityElement.Escape(queryString)); + SecurityElement.Escape(queryString), + type); if (index == 0) { @@ -298,7 +327,7 @@ namespace MediaBrowser.Api.Playback.Hls var state = await GetState(request, cancellationToken).ConfigureAwait(false); - var playlistPath = Path.ChangeExtension(state.OutputFilePath, ".m3u8"); + var playlistPath = Path.ChangeExtension(state.OutputFilePath, ".mpd"); var segmentExtension = GetSegmentFileExtension(state); @@ -309,6 +338,7 @@ namespace MediaBrowser.Api.Playback.Hls if (File.Exists(segmentPath)) { + job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType); return await GetSegmentResult(playlistPath, segmentPath, index, segmentLength, job, cancellationToken).ConfigureAwait(false); } @@ -317,6 +347,7 @@ namespace MediaBrowser.Api.Playback.Hls { if (File.Exists(segmentPath)) { + job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType); return await GetSegmentResult(playlistPath, segmentPath, index, segmentLength, job, cancellationToken).ConfigureAwait(false); } else @@ -632,23 +663,14 @@ namespace MediaBrowser.Api.Playback.Hls var inputModifier = GetInputModifier(state); - // If isEncoding is true we're actually starting ffmpeg - var startNumberParam = isEncoding ? GetStartNumber(state).ToString(UsCulture) : "0"; - - var segmentFilename = Path.GetFileNameWithoutExtension(outputPath) + "%03d" + GetSegmentFileExtension(state); - - var args = string.Format("{0} {1} -map_metadata -1 -threads {2} {3} {4} -copyts {5} -f ssegment -segment_time {6} -segment_list_size {8} -segment_list \"{9}\" {10}", + var args = string.Format("{0} {1} -map_metadata -1 -threads {2} {3} {4} -copyts {5} -f dash -use_template 0 -min_seg_duration 2000 \"{6}\"", inputModifier, GetInputArgument(transcodingJobId, state), threads, GetMapArgs(state), GetVideoArguments(state), GetAudioArguments(state), - state.SegmentLength.ToString(UsCulture), - startNumberParam, - state.HlsListSize.ToString(UsCulture), - outputPath, - segmentFilename + outputPath ).Trim(); return args; @@ -661,7 +683,7 @@ namespace MediaBrowser.Api.Playback.Hls /// System.String. protected override string GetSegmentFileExtension(StreamState state) { - return ".mp4"; + return ".m4s"; } protected override TranscodingJobType TranscodingJobType