mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 18:08:53 -07:00
update audio sync params
This commit is contained in:
parent
508edad222
commit
8eb4c034b4
@ -134,6 +134,7 @@
|
||||
<Compile Include="SearchService.cs" />
|
||||
<Compile Include="Session\SessionsService.cs" />
|
||||
<Compile Include="SimilarItemsHelper.cs" />
|
||||
<Compile Include="SuggestionsService.cs" />
|
||||
<Compile Include="System\ActivityLogService.cs" />
|
||||
<Compile Include="System\ActivityLogWebSocketListener.cs" />
|
||||
<Compile Include="System\SystemService.cs" />
|
||||
|
@ -826,6 +826,11 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||
args += " -ab " + bitrate.Value.ToString(UsCulture);
|
||||
}
|
||||
|
||||
if (state.OutputAudioSampleRate.HasValue)
|
||||
{
|
||||
args += " -ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture);
|
||||
}
|
||||
|
||||
args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), true);
|
||||
|
||||
return args;
|
||||
|
@ -6,10 +6,7 @@ using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Services;
|
||||
|
||||
@ -60,6 +57,11 @@ namespace MediaBrowser.Api.Playback.Hls
|
||||
args += " -ab " + bitrate.Value.ToString(UsCulture);
|
||||
}
|
||||
|
||||
if (state.OutputAudioSampleRate.HasValue)
|
||||
{
|
||||
args += " -ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture);
|
||||
}
|
||||
|
||||
args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), true);
|
||||
|
||||
return args;
|
||||
|
104
MediaBrowser.Api/SuggestionsService.cs
Normal file
104
MediaBrowser.Api/SuggestionsService.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using MediaBrowser.Model.Services;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Library;
|
||||
|
||||
namespace MediaBrowser.Api
|
||||
{
|
||||
[Route("/Users/{UserId}/Suggestions", "GET", Summary = "Gets items based on a query.")]
|
||||
public class GetSuggestedItems : IReturn<QueryResult<BaseItem>>
|
||||
{
|
||||
public string MediaType { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public bool EnableTotalRecordCount { get; set; }
|
||||
public int? StartIndex { get; set; }
|
||||
public int? Limit { get; set; }
|
||||
|
||||
public string[] GetMediaTypes()
|
||||
{
|
||||
return (MediaType ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
public string[] GetIncludeItemTypes()
|
||||
{
|
||||
return (Type ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
}
|
||||
|
||||
public class SuggestionsService : BaseApiService
|
||||
{
|
||||
private readonly IDtoService _dtoService;
|
||||
private readonly IAuthorizationContext _authContext;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public SuggestionsService(IDtoService dtoService, IAuthorizationContext authContext, IUserManager userManager, ILibraryManager libraryManager)
|
||||
{
|
||||
_dtoService = dtoService;
|
||||
_authContext = authContext;
|
||||
_userManager = userManager;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
public async Task<object> Get(GetSuggestedItems request)
|
||||
{
|
||||
var result = await GetResultItems(request).ConfigureAwait(false);
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
private async Task<QueryResult<BaseItemDto>> GetResultItems(GetSuggestedItems request)
|
||||
{
|
||||
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
|
||||
|
||||
var dtoOptions = GetDtoOptions(_authContext, request);
|
||||
var result = GetItems(request, user, dtoOptions);
|
||||
|
||||
var dtoList = await _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user).ConfigureAwait(false);
|
||||
|
||||
if (dtoList == null)
|
||||
{
|
||||
throw new InvalidOperationException("GetBaseItemDtos returned null");
|
||||
}
|
||||
|
||||
return new QueryResult<BaseItemDto>
|
||||
{
|
||||
TotalRecordCount = result.TotalRecordCount,
|
||||
Items = dtoList.ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
private QueryResult<BaseItem> GetItems(GetSuggestedItems request, User user, DtoOptions dtoOptions)
|
||||
{
|
||||
var query = new InternalItemsQuery(user)
|
||||
{
|
||||
SortBy = new string[] { ItemSortBy.Random },
|
||||
MediaTypes = request.GetMediaTypes(),
|
||||
IncludeItemTypes = request.GetIncludeItemTypes(),
|
||||
IsVirtualItem = false,
|
||||
StartIndex = request.StartIndex,
|
||||
Limit = request.Limit,
|
||||
DtoOptions = dtoOptions
|
||||
};
|
||||
|
||||
if (request.EnableTotalRecordCount)
|
||||
{
|
||||
return _libraryManager.GetItemsResult(query);
|
||||
}
|
||||
|
||||
var items = _libraryManager.GetItemList(query).ToArray();
|
||||
|
||||
return new QueryResult<BaseItem>
|
||||
{
|
||||
Items = items
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -137,6 +137,7 @@ namespace MediaBrowser.Api
|
||||
}
|
||||
|
||||
[Route("/Shows/{Id}/Episodes", "GET", Summary = "Gets episodes for a tv season")]
|
||||
[Route("/Shows/Episodes", "GET", Summary = "Gets episodes for a tv season")]
|
||||
public class GetEpisodes : IReturn<ItemsResult>, IHasItemFields, IHasDtoOptions
|
||||
{
|
||||
/// <summary>
|
||||
@ -200,9 +201,11 @@ namespace MediaBrowser.Api
|
||||
[ApiMember(Name = "EnableUserData", Description = "Optional, include user data", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
|
||||
public bool? EnableUserData { get; set; }
|
||||
|
||||
public string SeriesName { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Shows/{Id}/Seasons", "GET", Summary = "Gets seasons for a tv series")]
|
||||
[Route("/Shows/Seasons", "GET", Summary = "Gets seasons for a tv series")]
|
||||
public class GetSeasons : IReturn<ItemsResult>, IHasItemFields, IHasDtoOptions
|
||||
{
|
||||
/// <summary>
|
||||
@ -246,6 +249,7 @@ namespace MediaBrowser.Api
|
||||
[ApiMember(Name = "EnableUserData", Description = "Optional, include user data", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
|
||||
public bool? EnableUserData { get; set; }
|
||||
|
||||
public string SeriesName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -427,11 +431,11 @@ namespace MediaBrowser.Api
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
var series = _libraryManager.GetItemById(request.Id) as Series;
|
||||
var series = GetSeries(request.Id, request.SeriesName, user);
|
||||
|
||||
if (series == null)
|
||||
{
|
||||
throw new ResourceNotFoundException("No series exists with Id " + request.Id);
|
||||
throw new ResourceNotFoundException("Series not found");
|
||||
}
|
||||
|
||||
var seasons = (await series.GetItems(new InternalItemsQuery(user)
|
||||
@ -455,6 +459,26 @@ namespace MediaBrowser.Api
|
||||
};
|
||||
}
|
||||
|
||||
private Series GetSeries(string seriesId, string seriesName, User user)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(seriesId))
|
||||
{
|
||||
return _libraryManager.GetItemById(seriesId) as Series;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(seriesName))
|
||||
{
|
||||
return _libraryManager.GetItemList(new InternalItemsQuery(user)
|
||||
{
|
||||
Name = seriesName,
|
||||
IncludeItemTypes = new string[] { typeof(Series).Name }
|
||||
|
||||
}).OfType<Series>().FirstOrDefault();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<object> Get(GetEpisodes request)
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
@ -474,11 +498,11 @@ namespace MediaBrowser.Api
|
||||
}
|
||||
else if (request.Season.HasValue)
|
||||
{
|
||||
var series = _libraryManager.GetItemById(request.Id) as Series;
|
||||
var series = GetSeries(request.Id, request.SeriesName, user);
|
||||
|
||||
if (series == null)
|
||||
{
|
||||
throw new ResourceNotFoundException("No series exists with Id " + request.Id);
|
||||
throw new ResourceNotFoundException("Series not found");
|
||||
}
|
||||
|
||||
var season = series.GetSeasons(user).FirstOrDefault(i => i.IndexNumber == request.Season.Value);
|
||||
@ -494,11 +518,11 @@ namespace MediaBrowser.Api
|
||||
}
|
||||
else
|
||||
{
|
||||
var series = _libraryManager.GetItemById(request.Id) as Series;
|
||||
var series = GetSeries(request.Id, request.SeriesName, user);
|
||||
|
||||
if (series == null)
|
||||
{
|
||||
throw new ResourceNotFoundException("No series exists with Id " + request.Id);
|
||||
throw new ResourceNotFoundException("Series not found");
|
||||
}
|
||||
|
||||
episodes = series.GetEpisodes(user);
|
||||
|
@ -9,6 +9,7 @@ using MediaBrowser.Model.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Dto;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities.Audio
|
||||
{
|
||||
@ -227,7 +228,39 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||
// Refresh current item
|
||||
await RefreshMetadata(parentRefreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (!refreshOptions.IsAutomated)
|
||||
{
|
||||
await RefreshArtists(refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private async Task RefreshArtists(MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
|
||||
{
|
||||
var artists = AllArtists.Select(i =>
|
||||
{
|
||||
// This should not be necessary but we're seeing some cases of it
|
||||
if (string.IsNullOrWhiteSpace(i))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var artist = LibraryManager.GetArtist(i);
|
||||
|
||||
if (!artist.IsAccessedByName)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return artist;
|
||||
|
||||
}).Where(i => i != null).ToList();
|
||||
|
||||
foreach (var artist in artists)
|
||||
{
|
||||
await artist.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -719,14 +719,15 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
}
|
||||
}
|
||||
// nvenc doesn't decode with param -level set ?!
|
||||
else if (string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase)){
|
||||
else if (string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
//param += "";
|
||||
}
|
||||
else if (!string.Equals(videoEncoder, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
param += " -level " + level;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (string.Equals(videoEncoder, "libx264", StringComparison.OrdinalIgnoreCase))
|
||||
@ -1014,43 +1015,32 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
|
||||
public string GetAudioFilterParam(EncodingJobInfo state, EncodingOptions encodingOptions, bool isHls)
|
||||
{
|
||||
var volParam = string.Empty;
|
||||
var audioSampleRate = string.Empty;
|
||||
|
||||
var channels = state.OutputAudioChannels;
|
||||
|
||||
var filters = new List<string>();
|
||||
|
||||
// Boost volume to 200% when downsampling from 6ch to 2ch
|
||||
if (channels.HasValue && channels.Value <= 2)
|
||||
{
|
||||
if (state.AudioStream != null && state.AudioStream.Channels.HasValue && state.AudioStream.Channels.Value > 5 && !encodingOptions.DownMixAudioBoost.Equals(1))
|
||||
{
|
||||
volParam = ",volume=" + encodingOptions.DownMixAudioBoost.ToString(_usCulture);
|
||||
filters.Add("volume=" + encodingOptions.DownMixAudioBoost.ToString(_usCulture));
|
||||
}
|
||||
}
|
||||
|
||||
if (state.OutputAudioSampleRate.HasValue)
|
||||
{
|
||||
audioSampleRate = state.OutputAudioSampleRate.Value + ":";
|
||||
}
|
||||
|
||||
var adelay = isHls ? "adelay=1," : string.Empty;
|
||||
|
||||
var pts = string.Empty;
|
||||
|
||||
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode && !state.CopyTimestamps)
|
||||
{
|
||||
var seconds = TimeSpan.FromTicks(state.StartTimeTicks ?? 0).TotalSeconds;
|
||||
|
||||
pts = string.Format(",asetpts=PTS-{0}/TB", Math.Round(seconds).ToString(_usCulture));
|
||||
filters.Add(string.Format("asetpts=PTS-{0}/TB", Math.Round(seconds).ToString(_usCulture)));
|
||||
}
|
||||
|
||||
return string.Format("-af \"{0}aresample={1}async={4}{2}{3}\"",
|
||||
if (filters.Count > 0)
|
||||
{
|
||||
return "-af \"" + string.Join(",", filters.ToArray()) + "\"";
|
||||
}
|
||||
|
||||
adelay,
|
||||
audioSampleRate,
|
||||
volParam,
|
||||
pts,
|
||||
state.OutputAudioSync);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1282,7 +1272,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
}
|
||||
|
||||
var videoSizeParam = string.Empty;
|
||||
|
||||
|
||||
if (state.VideoStream != null && state.VideoStream.Width.HasValue && state.VideoStream.Height.HasValue)
|
||||
{
|
||||
videoSizeParam = string.Format("scale={0}:{1}", state.VideoStream.Width.Value.ToString(_usCulture), state.VideoStream.Height.Value.ToString(_usCulture));
|
||||
@ -1569,7 +1559,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
var outputVideoCodec = GetVideoEncoder(state, encodingOptions);
|
||||
|
||||
// Important: If this is ever re-enabled, make sure not to use it with wtv because it breaks seeking
|
||||
if (!string.Equals(state.InputContainer, "wtv", StringComparison.OrdinalIgnoreCase) &&
|
||||
if (!string.Equals(state.InputContainer, "wtv", StringComparison.OrdinalIgnoreCase) &&
|
||||
state.TranscodingType != TranscodingJobType.Progressive &&
|
||||
state.EnableBreakOnNonKeyFrames(outputVideoCodec))
|
||||
{
|
||||
@ -1657,7 +1647,6 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
if (state.ReadInputAtNativeFramerate ||
|
||||
mediaSource.Protocol == MediaProtocol.File && string.Equals(mediaSource.Container, "wtv", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
state.OutputAudioSync = "1000";
|
||||
state.InputVideoSync = "-1";
|
||||
state.InputAudioSync = "1";
|
||||
}
|
||||
@ -1715,7 +1704,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
if (state.SubtitleStream == null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Embed)
|
||||
{
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
// This is tricky to remux in, after converting to dvdsub it's not positioned correctly
|
||||
@ -1985,7 +1974,12 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
args += " -ab " + bitrate.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
|
||||
if (state.OutputAudioSampleRate.HasValue)
|
||||
{
|
||||
args += " -ar " + state.OutputAudioSampleRate.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
args += " " + GetAudioFilterParam(state, encodingOptions, false);
|
||||
|
||||
return args;
|
||||
|
@ -55,7 +55,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
return "-1";
|
||||
}
|
||||
}
|
||||
public string OutputAudioSync = "1";
|
||||
|
||||
public string InputAudioSync { get; set; }
|
||||
public string InputVideoSync { get; set; }
|
||||
public TransportStreamTimestamp InputTimestamp { get; set; }
|
||||
|
@ -664,28 +664,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
|
||||
private bool DetectInterlaced(MediaSourceInfo video, MediaStream videoStream)
|
||||
{
|
||||
var formats = (video.Container ?? string.Empty).Split(',').ToList();
|
||||
var enableInterlacedDection = formats.Contains("vob", StringComparer.OrdinalIgnoreCase) ||
|
||||
formats.Contains("m2ts", StringComparer.OrdinalIgnoreCase) ||
|
||||
formats.Contains("ts", StringComparer.OrdinalIgnoreCase) ||
|
||||
formats.Contains("mpegts", StringComparer.OrdinalIgnoreCase) ||
|
||||
formats.Contains("wtv", StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// If it's mpeg based, assume true
|
||||
if ((videoStream.Codec ?? string.Empty).IndexOf("mpeg", StringComparison.OrdinalIgnoreCase) != -1)
|
||||
{
|
||||
if (enableInterlacedDection)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the video codec is not some form of mpeg, then take a shortcut and limit this to containers that are likely to have interlaced content
|
||||
if (!enableInterlacedDection)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var formats = (video.Container ?? string.Empty).Split(',').ToList();
|
||||
return formats.Contains("vob", StringComparer.OrdinalIgnoreCase) ||
|
||||
formats.Contains("m2ts", StringComparer.OrdinalIgnoreCase) ||
|
||||
formats.Contains("ts", StringComparer.OrdinalIgnoreCase) ||
|
||||
formats.Contains("mpegts", StringComparer.OrdinalIgnoreCase) ||
|
||||
formats.Contains("wtv", StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user