add hls segmenter fmp4 streaming mode (#2468)
* add streaming mode segmenter fmp4 * allow hevc channel preview
This commit is contained in:
@@ -4,6 +4,7 @@ using ErsatzTV.Application.MediaItems;
|
||||
using ErsatzTV.Application.Troubleshooting;
|
||||
using ErsatzTV.Application.Troubleshooting.Queries;
|
||||
using ErsatzTV.Core;
|
||||
using ErsatzTV.Core.Domain;
|
||||
using ErsatzTV.Core.Interfaces.FFmpeg;
|
||||
using ErsatzTV.Core.Interfaces.Metadata;
|
||||
using ErsatzTV.Core.Interfaces.Troubleshooting;
|
||||
@@ -27,6 +28,8 @@ public class TroubleshootController(
|
||||
[FromQuery]
|
||||
int ffmpegProfile,
|
||||
[FromQuery]
|
||||
StreamingMode streamingMode,
|
||||
[FromQuery]
|
||||
List<int> watermark,
|
||||
[FromQuery]
|
||||
List<int> graphicsElement,
|
||||
@@ -42,6 +45,7 @@ public class TroubleshootController(
|
||||
|
||||
Either<BaseError, PlayoutItemResult> result = await mediator.Send(
|
||||
new PrepareTroubleshootingPlayback(
|
||||
streamingMode,
|
||||
mediaItem,
|
||||
ffmpegProfile,
|
||||
watermark,
|
||||
@@ -125,6 +129,8 @@ public class TroubleshootController(
|
||||
[FromQuery]
|
||||
int ffmpegProfile,
|
||||
[FromQuery]
|
||||
StreamingMode streamingMode,
|
||||
[FromQuery]
|
||||
List<int> watermark,
|
||||
[FromQuery]
|
||||
List<int> graphicsElement,
|
||||
@@ -135,7 +141,7 @@ public class TroubleshootController(
|
||||
Option<int> ss = seekSeconds > 0 ? seekSeconds : Option<int>.None;
|
||||
|
||||
Option<string> maybeArchivePath = await mediator.Send(
|
||||
new ArchiveTroubleshootingResults(mediaItem, ffmpegProfile, watermark, graphicsElement, ss),
|
||||
new ArchiveTroubleshootingResults(mediaItem, ffmpegProfile, streamingMode, watermark, graphicsElement, ss),
|
||||
cancellationToken);
|
||||
|
||||
foreach (string archivePath in maybeArchivePath)
|
||||
|
||||
@@ -10,6 +10,7 @@ using ErsatzTV.Application.Streaming;
|
||||
using ErsatzTV.Application.Subtitles;
|
||||
using ErsatzTV.Application.Subtitles.Queries;
|
||||
using ErsatzTV.Core;
|
||||
using ErsatzTV.Core.Domain;
|
||||
using ErsatzTV.Core.FFmpeg;
|
||||
using ErsatzTV.Core.Interfaces.FFmpeg;
|
||||
using ErsatzTV.Core.Interfaces.Streaming;
|
||||
@@ -281,7 +282,7 @@ public class InternalController : ControllerBase
|
||||
{
|
||||
var request = new GetPlayoutItemProcessByChannelNumber(
|
||||
channelNumber,
|
||||
mode,
|
||||
StreamingMode.TransportStream,
|
||||
DateTimeOffset.Now,
|
||||
false,
|
||||
true,
|
||||
|
||||
@@ -205,6 +205,9 @@ public class IptvController : ControllerBase
|
||||
case StreamingMode.HttpLiveStreamingSegmenter:
|
||||
mode = "segmenter";
|
||||
break;
|
||||
case StreamingMode.HttpLiveStreamingSegmenterFmp4:
|
||||
mode = "segmenter-fmp4";
|
||||
break;
|
||||
case StreamingMode.HttpLiveStreamingSegmenterV2:
|
||||
mode = "segmenter-v2";
|
||||
break;
|
||||
@@ -217,6 +220,7 @@ public class IptvController : ControllerBase
|
||||
switch (mode)
|
||||
{
|
||||
case "segmenter":
|
||||
case "segmenter-fmp4":
|
||||
case "segmenter-v2":
|
||||
_logger.LogDebug(
|
||||
"Maybe starting ffmpeg session for channel {Channel}, mode {Mode}",
|
||||
|
||||
@@ -140,6 +140,7 @@ else
|
||||
<MudSelectItem Value="@(StreamingMode.TransportStream)">MPEG-TS (Legacy)</MudSelectItem>
|
||||
<MudSelectItem Value="@(StreamingMode.HttpLiveStreamingDirect)">HLS Direct</MudSelectItem>
|
||||
<MudSelectItem Value="@(StreamingMode.HttpLiveStreamingSegmenter)">HLS Segmenter</MudSelectItem>
|
||||
<MudSelectItem Value="@(StreamingMode.HttpLiveStreamingSegmenterFmp4)">HLS Segmenter (fmp4)</MudSelectItem>
|
||||
<MudSelectItem Value="@(StreamingMode.HttpLiveStreamingSegmenterV2)">HLS Segmenter V2</MudSelectItem>
|
||||
</MudSelect>
|
||||
</MudStack>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
@using ErsatzTV.Core.Interfaces.FFmpeg
|
||||
@implements IDisposable
|
||||
@inject IDialogService Dialog
|
||||
@inject IJSRuntime JsRuntime
|
||||
@inject IMediator Mediator
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IFFmpegSegmenterService SegmenterService
|
||||
@@ -74,7 +75,7 @@
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
<div style="align-items: center; display: flex;">
|
||||
@if (CanPreviewChannel(context))
|
||||
@if (_channelsThatCanPreview.Contains(context.Id))
|
||||
{
|
||||
<MudTooltip Text="Preview Channel">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.PlayCircle"
|
||||
@@ -82,9 +83,19 @@
|
||||
</MudIconButton>
|
||||
</MudTooltip>
|
||||
}
|
||||
else if (CanPreviewChannel(context) && !_ffmpegProfilesThatCanPreview[context.FFmpegProfileId])
|
||||
{
|
||||
<MudTooltip Text="Channel preview requires FFmpeg Profile compatible with this browser">
|
||||
<div style="height: 48px; width: 48px; align-items: center; display: flex; justify-content: center">
|
||||
<!--suppress CssUnresolvedCustomProperty -->
|
||||
<MudIcon Icon="@Icons.Material.Filled.PlayCircle" Style="color: var(--mud-palette-error-lighten);">
|
||||
</MudIcon>
|
||||
</div>
|
||||
</MudTooltip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTooltip Text="Channel preview requires playout, MPEG-TS/HLS Segmenter, and H264/AAC">
|
||||
<MudTooltip Text="Channel preview requires playout, MPEG-TS/HLS Segmenter, and compatible FFmpeg Profile">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.PlayCircle" Disabled="true">
|
||||
</MudIconButton>
|
||||
</MudTooltip>
|
||||
@@ -127,6 +138,8 @@
|
||||
|
||||
private MudTable<ChannelViewModel> _table;
|
||||
private List<FFmpegProfileViewModel> _ffmpegProfiles = [];
|
||||
private readonly System.Collections.Generic.HashSet<int> _channelsThatCanPreview = [];
|
||||
private readonly Dictionary<int, bool> _ffmpegProfilesThatCanPreview = [];
|
||||
|
||||
private int _rowsPerPage = 10;
|
||||
|
||||
@@ -186,10 +199,36 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
Option<FFmpegProfileViewModel> maybeProfile = Optional(_ffmpegProfiles.Find(p => p.Id == channel.FFmpegProfileId));
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<bool> CanPreviewFFmpegProfile(int ffmpegProfileId)
|
||||
{
|
||||
Option<FFmpegProfileViewModel> maybeProfile = Optional(_ffmpegProfiles.Find(p => p.Id == ffmpegProfileId));
|
||||
foreach (FFmpegProfileViewModel profile in maybeProfile)
|
||||
{
|
||||
return profile.VideoFormat is FFmpegProfileVideoFormat.H264 && profile.AudioFormat is FFmpegProfileAudioFormat.Aac;
|
||||
string videoCodec = profile.VideoFormat switch
|
||||
{
|
||||
FFmpegProfileVideoFormat.Hevc => "hvc1.1.6.L93.B0",
|
||||
FFmpegProfileVideoFormat.H264 => "avc1.4D4028",
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
string audioCodec = profile.AudioFormat switch
|
||||
{
|
||||
FFmpegProfileAudioFormat.Ac3 => "ac-3",
|
||||
FFmpegProfileAudioFormat.Aac => "mp4a.40.2",
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
//Console.WriteLine($"Checking video format {videoCodec} and audio format {audioCodec}");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(videoCodec) || string.IsNullOrWhiteSpace(audioCodec))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return await BrowserSupportsCodec($"{videoCodec}, {audioCodec}");
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -197,36 +236,28 @@
|
||||
|
||||
private async Task PreviewChannel(ChannelViewModel channel)
|
||||
{
|
||||
if (!CanPreviewChannel(channel))
|
||||
if (!CanPreviewChannel(channel) || !await CanPreviewFFmpegProfile(channel.FFmpegProfileId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Option<FFmpegProfileViewModel> maybeProfile = Optional(_ffmpegProfiles.Find(p => p.Id == channel.FFmpegProfileId));
|
||||
foreach (FFmpegProfileViewModel profile in maybeProfile)
|
||||
var uri = new UriBuilder(NavigationManager.ToAbsoluteUri(NavigationManager.Uri));
|
||||
uri.Path = uri.Path.Replace("/channels", $"/iptv/channel/{channel.Number}.m3u8");
|
||||
uri.Query = channel.StreamingMode switch
|
||||
{
|
||||
if (profile.VideoFormat == FFmpegProfileVideoFormat.Hevc)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StreamingMode.HttpLiveStreamingSegmenterV2 => "?mode=segmenter-v2",
|
||||
StreamingMode.HttpLiveStreamingSegmenterFmp4 => "?mode=segmenter-fmp4",
|
||||
_ => "?mode=segmenter"
|
||||
};
|
||||
|
||||
var uri = new UriBuilder(NavigationManager.ToAbsoluteUri(NavigationManager.Uri));
|
||||
uri.Path = uri.Path.Replace("/channels", $"/iptv/channel/{channel.Number}.m3u8");
|
||||
uri.Query = channel.StreamingMode switch
|
||||
{
|
||||
StreamingMode.HttpLiveStreamingSegmenterV2 => "?mode=segmenter-v2",
|
||||
_ => "?mode=segmenter"
|
||||
};
|
||||
|
||||
if (JwtHelper.IsEnabled)
|
||||
{
|
||||
uri.Query += $"&access_token={JwtHelper.GenerateToken()}";
|
||||
}
|
||||
|
||||
var parameters = new DialogParameters { { "StreamUri", uri.ToString() } };
|
||||
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraLarge };
|
||||
await Dialog.ShowAsync<ChannelPreviewDialog>("Channel Preview", parameters, options);
|
||||
if (JwtHelper.IsEnabled)
|
||||
{
|
||||
uri.Query += $"&access_token={JwtHelper.GenerateToken()}";
|
||||
}
|
||||
|
||||
var parameters = new DialogParameters { { "StreamUri", uri.ToString() } };
|
||||
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraLarge };
|
||||
await Dialog.ShowAsync<ChannelPreviewDialog>("Channel Preview", parameters, options);
|
||||
}
|
||||
|
||||
private async Task DeleteChannelAsync(ChannelViewModel channel)
|
||||
@@ -253,10 +284,16 @@
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
List<ChannelViewModel> channels = await Mediator.Send(new GetAllChannels(), cancellationToken);
|
||||
IOrderedEnumerable<ChannelViewModel> sorted = channels.OrderBy(c => decimal.Parse(c.Number, CultureInfo.InvariantCulture));
|
||||
// TODO: properly page this data
|
||||
IOrderedEnumerable<ChannelViewModel> sorted = channels.OrderBy(c => decimal.Parse(c.Number, CultureInfo.InvariantCulture))
|
||||
.Skip(state.Page * state.PageSize)
|
||||
.Take(state.PageSize)
|
||||
.OrderBy(c => decimal.Parse(c.Number, CultureInfo.InvariantCulture));
|
||||
|
||||
CultureInfo[] allCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
|
||||
var processedChannels = new List<ChannelViewModel>();
|
||||
_channelsThatCanPreview.Clear();
|
||||
_ffmpegProfilesThatCanPreview.Clear();
|
||||
foreach (ChannelViewModel channel in sorted)
|
||||
{
|
||||
Option<CultureInfo> maybeCultureInfo = allCultures.Find(ci => string.Equals(
|
||||
@@ -267,13 +304,23 @@
|
||||
maybeCultureInfo.Match(
|
||||
cultureInfo => processedChannels.Add(channel with { PreferredAudioLanguageCode = cultureInfo.EnglishName }),
|
||||
() => processedChannels.Add(channel));
|
||||
|
||||
if (!_ffmpegProfilesThatCanPreview.TryGetValue(channel.FFmpegProfileId, out bool canPreviewFFmpegProfile))
|
||||
{
|
||||
canPreviewFFmpegProfile = await CanPreviewFFmpegProfile(channel.FFmpegProfileId);
|
||||
_ffmpegProfilesThatCanPreview.Add(channel.FFmpegProfileId, canPreviewFFmpegProfile);
|
||||
}
|
||||
|
||||
if (CanPreviewChannel(channel) && canPreviewFFmpegProfile)
|
||||
{
|
||||
_channelsThatCanPreview.Add(channel.Id);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: properly page this data
|
||||
return new TableData<ChannelViewModel>
|
||||
{
|
||||
TotalItems = channels.Count,
|
||||
Items = processedChannels.Skip(state.Page * state.PageSize).Take(state.PageSize)
|
||||
Items = processedChannels
|
||||
};
|
||||
}
|
||||
|
||||
@@ -281,9 +328,15 @@
|
||||
{
|
||||
StreamingMode.HttpLiveStreamingDirect => "HLS Direct",
|
||||
StreamingMode.HttpLiveStreamingSegmenter => "HLS Segmenter",
|
||||
StreamingMode.HttpLiveStreamingSegmenterFmp4 => "HLS Segmenter (fmp4)",
|
||||
StreamingMode.HttpLiveStreamingSegmenterV2 => "HLS Segmenter V2",
|
||||
StreamingMode.TransportStreamHybrid => "MPEG-TS",
|
||||
_ => "MPEG-TS (Legacy)"
|
||||
};
|
||||
|
||||
private async Task<bool> BrowserSupportsCodec(string codecString)
|
||||
{
|
||||
return await JsRuntime.InvokeAsync<bool>("mediaSourceSupports", codecString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,6 +55,15 @@
|
||||
}
|
||||
</MudSelect>
|
||||
</MudStack>
|
||||
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
|
||||
<div class="d-flex">
|
||||
<MudText>Streaming Mode</MudText>
|
||||
</div>
|
||||
<MudSelect @bind-Value="_streamingMode" For="@(() => _streamingMode)">
|
||||
<MudSelectItem Value="@(StreamingMode.HttpLiveStreamingSegmenter)">HLS Segmenter</MudSelectItem>
|
||||
<MudSelectItem Value="@(StreamingMode.HttpLiveStreamingSegmenterFmp4)">HLS Segmenter (fmp4)</MudSelectItem>
|
||||
</MudSelect>
|
||||
</MudStack>
|
||||
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
|
||||
<div class="d-flex">
|
||||
<MudText>Subtitle</MudText>
|
||||
@@ -144,6 +153,7 @@
|
||||
private readonly List<SubtitleViewModel> _subtitleStreams = [];
|
||||
private readonly List<GraphicsElementViewModel> _graphicsElements = [];
|
||||
private MediaItemInfo _info;
|
||||
private StreamingMode _streamingMode = StreamingMode.HttpLiveStreamingSegmenter;
|
||||
private int _ffmpegProfileId;
|
||||
private IEnumerable<string> _watermarkNames = new System.Collections.Generic.HashSet<string>();
|
||||
private IEnumerable<string> _graphicsElementNames = new System.Collections.Generic.HashSet<string>();
|
||||
@@ -213,7 +223,7 @@
|
||||
{
|
||||
var uri = new UriBuilder(NavigationManager.ToAbsoluteUri(NavigationManager.Uri));
|
||||
uri.Path = uri.Path.Replace("/system/troubleshooting/playback", "/api/troubleshoot/playback.m3u8");
|
||||
uri.Query = $"?mediaItem={MediaItemId}&ffmpegProfile={_ffmpegProfileId}&seekSeconds={_seekSeconds}";
|
||||
uri.Query = $"?mediaItem={MediaItemId}&ffmpegProfile={_ffmpegProfileId}&streamingMode={(int)_streamingMode}&seekSeconds={_seekSeconds}";
|
||||
foreach (string watermarkName in _watermarkNames)
|
||||
{
|
||||
foreach (WatermarkViewModel watermark in _watermarks.Where(wm => wm.Name == watermarkName))
|
||||
@@ -271,7 +281,7 @@
|
||||
|
||||
private async Task DownloadResults()
|
||||
{
|
||||
var uri = $"api/troubleshoot/playback/archive?mediaItem={MediaItemId ?? 0}&ffmpegProfile={_ffmpegProfileId}&seekSeconds={_seekSeconds}";
|
||||
var uri = $"api/troubleshoot/playback/archive?mediaItem={MediaItemId ?? 0}&ffmpegProfile={_ffmpegProfileId}&streamingMode={(int)_streamingMode}&seekSeconds={_seekSeconds}";
|
||||
|
||||
foreach (string watermarkName in _watermarkNames)
|
||||
{
|
||||
|
||||
@@ -55,6 +55,13 @@
|
||||
$("h3").addClass("mud-typography mud-typography-h5");
|
||||
}
|
||||
|
||||
function mediaSourceSupports(codecString) {
|
||||
if (window.MediaSource && MediaSource.isTypeSupported) {
|
||||
return MediaSource.isTypeSupported('video/mp4; codecs="' + codecString + '"');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function previewChannel(uri) {
|
||||
var video = document.getElementById('video');
|
||||
if (Hls.isSupported()) {
|
||||
|
||||
Reference in New Issue
Block a user