rework transcoding settings
This commit is contained in:
parent
a2b9ee8ac6
commit
901dab5760
|
@ -263,40 +263,29 @@ namespace MediaBrowser.Api.Playback
|
|||
return returnFirstIfNoIndex ? streams.FirstOrDefault() : null;
|
||||
}
|
||||
|
||||
protected EncodingQuality GetQualitySetting()
|
||||
{
|
||||
var quality = ApiEntryPoint.Instance.GetEncodingOptions().EncodingQuality;
|
||||
|
||||
if (quality == EncodingQuality.Auto)
|
||||
{
|
||||
var cpuCount = Environment.ProcessorCount;
|
||||
|
||||
if (cpuCount >= 4)
|
||||
{
|
||||
//return EncodingQuality.HighQuality;
|
||||
}
|
||||
|
||||
return EncodingQuality.HighSpeed;
|
||||
}
|
||||
|
||||
return quality;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of threads.
|
||||
/// </summary>
|
||||
/// <returns>System.Int32.</returns>
|
||||
protected int GetNumberOfThreads(StreamState state, bool isWebm)
|
||||
{
|
||||
var threads = ApiEntryPoint.Instance.GetEncodingOptions().EncodingThreadCount;
|
||||
|
||||
if (isWebm)
|
||||
{
|
||||
// Recommended per docs
|
||||
return Math.Max(Environment.ProcessorCount - 1, 2);
|
||||
}
|
||||
|
||||
// Automatic
|
||||
if (threads == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return threads;
|
||||
}
|
||||
|
||||
protected string H264Encoder
|
||||
{
|
||||
get
|
||||
|
@ -326,77 +315,31 @@ namespace MediaBrowser.Api.Playback
|
|||
var isVc1 = state.VideoStream != null &&
|
||||
string.Equals(state.VideoStream.Codec, "vc1", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
var qualitySetting = GetQualitySetting();
|
||||
|
||||
if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
param = "-preset superfast";
|
||||
|
||||
switch (qualitySetting)
|
||||
{
|
||||
case EncodingQuality.HighSpeed:
|
||||
param += " -crf 23";
|
||||
break;
|
||||
case EncodingQuality.HighQuality:
|
||||
param += " -crf 20";
|
||||
break;
|
||||
case EncodingQuality.MaxQuality:
|
||||
param += " -crf 18";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
param = "-preset fast";
|
||||
|
||||
switch (qualitySetting)
|
||||
{
|
||||
case EncodingQuality.HighSpeed:
|
||||
param += " -crf 28";
|
||||
break;
|
||||
case EncodingQuality.HighQuality:
|
||||
param += " -crf 25";
|
||||
break;
|
||||
case EncodingQuality.MaxQuality:
|
||||
param += " -crf 21";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// h264 (h264_qsv)
|
||||
else if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
switch (qualitySetting)
|
||||
{
|
||||
case EncodingQuality.HighSpeed:
|
||||
param = "-preset 7";
|
||||
break;
|
||||
case EncodingQuality.HighQuality:
|
||||
param = "-preset 4";
|
||||
break;
|
||||
case EncodingQuality.MaxQuality:
|
||||
param = "-preset 1";
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// h264 (libnvenc)
|
||||
else if (string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
switch (qualitySetting)
|
||||
{
|
||||
case EncodingQuality.HighSpeed:
|
||||
param = "-preset high-performance";
|
||||
break;
|
||||
case EncodingQuality.HighQuality:
|
||||
param = "";
|
||||
break;
|
||||
case EncodingQuality.MaxQuality:
|
||||
param = "-preset high-quality";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// webm
|
||||
|
@ -409,20 +352,7 @@ namespace MediaBrowser.Api.Playback
|
|||
var qmin = "0";
|
||||
var qmax = "50";
|
||||
|
||||
switch (qualitySetting)
|
||||
{
|
||||
case EncodingQuality.HighSpeed:
|
||||
crf = "10";
|
||||
break;
|
||||
case EncodingQuality.HighQuality:
|
||||
crf = "6";
|
||||
break;
|
||||
case EncodingQuality.MaxQuality:
|
||||
crf = "4";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unrecognized quality setting");
|
||||
}
|
||||
|
||||
if (isVc1)
|
||||
{
|
||||
|
|
|
@ -521,42 +521,18 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
|||
var isVc1 = state.VideoStream != null &&
|
||||
string.Equals(state.VideoStream.Codec, "vc1", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
var qualitySetting = state.Quality;
|
||||
|
||||
if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
param = "-preset superfast";
|
||||
|
||||
switch (qualitySetting)
|
||||
{
|
||||
case EncodingQuality.HighSpeed:
|
||||
param += " -crf 28";
|
||||
break;
|
||||
case EncodingQuality.HighQuality:
|
||||
param += " -crf 25";
|
||||
break;
|
||||
case EncodingQuality.MaxQuality:
|
||||
param += " -crf 21";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
param = "-preset fast";
|
||||
|
||||
switch (qualitySetting)
|
||||
{
|
||||
case EncodingQuality.HighSpeed:
|
||||
param += " -crf 28";
|
||||
break;
|
||||
case EncodingQuality.HighQuality:
|
||||
param += " -crf 25";
|
||||
break;
|
||||
case EncodingQuality.MaxQuality:
|
||||
param += " -crf 21";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// webm
|
||||
|
@ -569,20 +545,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
|||
var qmin = "0";
|
||||
var qmax = "50";
|
||||
|
||||
switch (qualitySetting)
|
||||
{
|
||||
case EncodingQuality.HighSpeed:
|
||||
crf = "10";
|
||||
break;
|
||||
case EncodingQuality.HighQuality:
|
||||
crf = "6";
|
||||
break;
|
||||
case EncodingQuality.MaxQuality:
|
||||
crf = "4";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unrecognized quality setting");
|
||||
}
|
||||
|
||||
if (isVc1)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
|||
public Stream LogFileStream { get; set; }
|
||||
public IProgress<double> Progress { get; set; }
|
||||
public TaskCompletionSource<bool> TaskCompletionSource;
|
||||
public EncodingQuality Quality { get; set; }
|
||||
public EncodingJobOptions Options { get; set; }
|
||||
public string InputContainer { get; set; }
|
||||
public MediaSourceInfo MediaSource { get; set; }
|
||||
|
|
|
@ -96,10 +96,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
|||
|
||||
TryStreamCopy(state, request);
|
||||
|
||||
state.Quality = options.Context == EncodingContext.Static ?
|
||||
EncodingQuality.MaxQuality :
|
||||
GetQualitySetting();
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -199,25 +195,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
|||
state.MediaSource = mediaSource;
|
||||
}
|
||||
|
||||
protected EncodingQuality GetQualitySetting()
|
||||
{
|
||||
var quality = GetEncodingOptions().EncodingQuality;
|
||||
|
||||
if (quality == EncodingQuality.Auto)
|
||||
{
|
||||
var cpuCount = Environment.ProcessorCount;
|
||||
|
||||
if (cpuCount >= 4)
|
||||
{
|
||||
//return EncodingQuality.HighQuality;
|
||||
}
|
||||
|
||||
return EncodingQuality.HighSpeed;
|
||||
}
|
||||
|
||||
return quality;
|
||||
}
|
||||
|
||||
protected EncodingOptions GetEncodingOptions()
|
||||
{
|
||||
return _config.GetConfiguration<EncodingOptions>("encoding");
|
||||
|
|
|
@ -203,9 +203,6 @@
|
|||
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingOptions.cs">
|
||||
<Link>Configuration\EncodingOptions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingQuality.cs">
|
||||
<Link>Configuration\EncodingQuality.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MediaBrowser.Model\Configuration\FanartOptions.cs">
|
||||
<Link>Configuration\FanartOptions.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -168,9 +168,6 @@
|
|||
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingOptions.cs">
|
||||
<Link>Configuration\EncodingOptions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingQuality.cs">
|
||||
<Link>Configuration\EncodingQuality.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MediaBrowser.Model\Configuration\FanartOptions.cs">
|
||||
<Link>Configuration\FanartOptions.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace MediaBrowser.Model.Configuration
|
|||
{
|
||||
public class EncodingOptions
|
||||
{
|
||||
public EncodingQuality EncodingQuality { get; set; }
|
||||
public int EncodingThreadCount { get; set; }
|
||||
public string TranscodingTempPath { get; set; }
|
||||
public double DownMixAudioBoost { get; set; }
|
||||
public string H264Encoder { get; set; }
|
||||
|
@ -15,9 +15,9 @@ namespace MediaBrowser.Model.Configuration
|
|||
{
|
||||
H264Encoder = "libx264";
|
||||
DownMixAudioBoost = 2;
|
||||
EncodingQuality = EncodingQuality.Auto;
|
||||
EnableThrottling = true;
|
||||
ThrottleThresholdInSeconds = 120;
|
||||
EncodingThreadCount = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
namespace MediaBrowser.Model.Configuration
|
||||
{
|
||||
public enum EncodingQuality
|
||||
{
|
||||
Auto,
|
||||
HighSpeed,
|
||||
HighQuality,
|
||||
MaxQuality
|
||||
}
|
||||
}
|
|
@ -159,7 +159,6 @@
|
|||
<Compile Include="FileOrganization\TvFileOrganizationOptions.cs" />
|
||||
<Compile Include="Configuration\BaseApplicationConfiguration.cs" />
|
||||
<Compile Include="Configuration\DlnaOptions.cs" />
|
||||
<Compile Include="Configuration\EncodingQuality.cs" />
|
||||
<Compile Include="Configuration\ImageOption.cs" />
|
||||
<Compile Include="Configuration\ImageSavingConvention.cs" />
|
||||
<Compile Include="LiveTv\LiveTvOptions.cs" />
|
||||
|
|
|
@ -61,22 +61,22 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var idString = item.Id.ToString("N");
|
||||
var cachePath = Path.Combine(_appPaths.CachePath,
|
||||
"ffprobe-audio",
|
||||
idString.Substring(0, 2), idString, "v" + SchemaVersion + _mediaEncoder.Version + item.DateModified.Ticks.ToString(_usCulture) + ".json");
|
||||
//var idString = item.Id.ToString("N");
|
||||
//var cachePath = Path.Combine(_appPaths.CachePath,
|
||||
// "ffprobe-audio",
|
||||
// idString.Substring(0, 2), idString, "v" + SchemaVersion + _mediaEncoder.Version + item.DateModified.Ticks.ToString(_usCulture) + ".json");
|
||||
|
||||
try
|
||||
{
|
||||
return _json.DeserializeFromFile<Model.MediaInfo.MediaInfo>(cachePath);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
//try
|
||||
//{
|
||||
// return _json.DeserializeFromFile<Model.MediaInfo.MediaInfo>(cachePath);
|
||||
//}
|
||||
//catch (FileNotFoundException)
|
||||
//{
|
||||
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
}
|
||||
//}
|
||||
//catch (DirectoryNotFoundException)
|
||||
//{
|
||||
//}
|
||||
|
||||
var result = await _mediaEncoder.GetMediaInfo(new MediaInfoRequest
|
||||
{
|
||||
|
@ -86,8 +86,8 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(cachePath));
|
||||
_json.SerializeToFile(result, cachePath);
|
||||
//Directory.CreateDirectory(Path.GetDirectoryName(cachePath));
|
||||
//_json.SerializeToFile(result, cachePath);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user