added sync cpu settings

This commit is contained in:
Luke Pulverenti 2015-04-09 13:30:18 -04:00
parent b9c656e859
commit 3cb2043028
8 changed files with 38 additions and 26 deletions

View file

@ -334,6 +334,12 @@ namespace MediaBrowser.Api
1000 :
1800000;
// We can really reduce the timeout for apps that are using the newer api
if (!string.IsNullOrWhiteSpace(job.PlaySessionId) && job.Type == TranscodingJobType.Hls)
{
timerDuration = 40000;
}
if (job.KillTimer == null)
{
if (startTimerIfNeeded)

View file

@ -41,6 +41,8 @@ namespace MediaBrowser.Controller.MediaEncoding
public int? SubtitleStreamIndex { get; set; }
public int? MaxRefFrames { get; set; }
public int? MaxVideoBitDepth { get; set; }
public int? CpuCoreLimit { get; set; }
public bool ReadInputAtNativeFramerate { get; set; }
public SubtitleDeliveryMethod SubtitleMethod { get; set; }
/// <summary>

View file

@ -70,10 +70,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
encodingJob.OutputFilePath = GetOutputFilePath(encodingJob);
Directory.CreateDirectory(Path.GetDirectoryName(encodingJob.OutputFilePath));
if (options.Context == EncodingContext.Static && encodingJob.IsInputVideo)
{
encodingJob.ReadInputAtNativeFramerate = true;
}
encodingJob.ReadInputAtNativeFramerate = options.ReadInputAtNativeFramerate;
await AcquireResources(encodingJob, cancellationToken).ConfigureAwait(false);
@ -305,19 +302,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
/// <returns>System.Int32.</returns>
protected int GetNumberOfThreads(EncodingJob job, bool isWebm)
{
// Only need one thread for sync
if (job.Options.Context == EncodingContext.Static)
{
return 1;
}
if (isWebm)
{
// Recommended per docs
return Math.Max(Environment.ProcessorCount - 1, 2);
}
return 0;
return job.Options.CpuCoreLimit ?? 0;
}
protected EncodingQuality GetQualitySetting()

View file

@ -124,10 +124,14 @@ namespace MediaBrowser.MediaEncoding.Encoder
state.InputContainer = mediaSource.Container;
state.InputFileSize = mediaSource.Size;
state.InputBitrate = mediaSource.Bitrate;
state.ReadInputAtNativeFramerate = mediaSource.ReadAtNativeFramerate;
state.RunTimeTicks = mediaSource.RunTimeTicks;
state.RemoteHttpHeaders = mediaSource.RequiredHttpHeaders;
if (mediaSource.ReadAtNativeFramerate)
{
state.ReadInputAtNativeFramerate = true;
}
if (mediaSource.VideoType.HasValue)
{
state.VideoType = mediaSource.VideoType.Value;
@ -148,7 +152,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
state.RemoteHttpHeaders = mediaSource.RequiredHttpHeaders;
state.InputBitrate = mediaSource.Bitrate;
state.InputFileSize = mediaSource.Size;
state.ReadInputAtNativeFramerate = mediaSource.ReadAtNativeFramerate;
if (state.ReadInputAtNativeFramerate ||
mediaSource.Protocol == MediaProtocol.File && string.Equals(mediaSource.Container, "wtv", StringComparison.OrdinalIgnoreCase))

View file

@ -5,5 +5,12 @@ namespace MediaBrowser.Model.Sync
{
public string TemporaryPath { get; set; }
public long UploadSpeedLimitBytes { get; set; }
public int TranscodingCpuCoreLimit { get; set; }
public bool EnableFullSpeedTranscoding { get; set; }
public SyncOptions()
{
TranscodingCpuCoreLimit = 1;
}
}
}

View file

@ -147,6 +147,7 @@ namespace MediaBrowser.Providers.MediaInfo
audio.Artists = data.Artists;
audio.AlbumArtists = data.AlbumArtists;
audio.IndexNumber = data.IndexNumber;
audio.ParentIndexNumber = data.ParentIndexNumber;
audio.ProductionYear = data.ProductionYear;
audio.PremiereDate = data.PremiereDate;

View file

@ -1415,5 +1415,9 @@
"OptionAllowMediaPlaybackTranscodingHelp": "Users will receive friendly messages when content is unplayable based on policy.",
"TabStreaming": "Streaming",
"LabelRemoteClientBitrateLimit": "Remote client bitrate limit (mbps):",
"LabelRemoteClientBitrateLimitHelp": "An optional streaming bitrate limit for all remote clients. This is useful to prevent clients from requesting a higher bitrate than your connection can handle."
"LabelRemoteClientBitrateLimitHelp": "An optional streaming bitrate limit for all remote clients. This is useful to prevent clients from requesting a higher bitrate than your connection can handle.",
"LabelConversionCpuCoreLimit": "CPU core limit:",
"LabelConversionCpuCoreLimitHelp": "Limit the number of CPU cores that will be used during sync conversion.",
"OptionEnableFullSpeedConversion": "Enable full speed conversion",
"OptionEnableFullSpeedConversionHelp": "By default sync conversion is performed at a low speed to reduce resource consumption."
}

View file

@ -456,17 +456,18 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.Progress = 0;
var syncOptions = _config.GetSyncOptions();
var user = _userManager.GetUserById(job.UserId);
var video = item as Video;
if (video != null)
{
await Sync(jobItem, job, video, user, enableConversion, progress, cancellationToken).ConfigureAwait(false);
await Sync(jobItem, job, video, user, enableConversion, syncOptions, progress, cancellationToken).ConfigureAwait(false);
}
else if (item is Audio)
{
await Sync(jobItem, job, (Audio)item, user, enableConversion, progress, cancellationToken).ConfigureAwait(false);
await Sync(jobItem, job, (Audio)item, user, enableConversion, syncOptions, progress, cancellationToken).ConfigureAwait(false);
}
else if (item is Photo)
@ -480,7 +481,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
private async Task Sync(SyncJobItem jobItem, SyncJob job, Video item, User user, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
private async Task Sync(SyncJobItem jobItem, SyncJob job, Video item, User user, bool enableConversion, SyncOptions syncOptions, IProgress<double> progress, CancellationToken cancellationToken)
{
var jobOptions = _syncManager.GetVideoOptions(jobItem, job);
var conversionOptions = new VideoOptions
@ -542,7 +543,9 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.OutputPath = await _mediaEncoder.EncodeVideo(new EncodingJobOptions(streamInfo, conversionOptions.Profile)
{
OutputDirectory = jobItem.TemporaryPath
OutputDirectory = jobItem.TemporaryPath,
CpuCoreLimit = syncOptions.TranscodingCpuCoreLimit,
ReadInputAtNativeFramerate = !syncOptions.EnableFullSpeedTranscoding
}, innerProgress, cancellationToken);
}
@ -677,7 +680,7 @@ namespace MediaBrowser.Server.Implementations.Sync
private const int DatabaseProgressUpdateIntervalSeconds = 2;
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, bool enableConversion, SyncOptions syncOptions, IProgress<double> progress, CancellationToken cancellationToken)
{
var jobOptions = _syncManager.GetAudioOptions(jobItem, job);
var conversionOptions = new AudioOptions
@ -725,7 +728,8 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, conversionOptions.Profile)
{
OutputDirectory = jobItem.TemporaryPath
OutputDirectory = jobItem.TemporaryPath,
CpuCoreLimit = syncOptions.TranscodingCpuCoreLimit
}, innerProgress, cancellationToken);
}