rework transcoding settings

This commit is contained in:
Luke Pulverenti 2015-07-30 21:52:11 -04:00
parent a2b9ee8ac6
commit 901dab5760
10 changed files with 35 additions and 183 deletions

View File

@ -263,40 +263,29 @@ namespace MediaBrowser.Api.Playback
return returnFirstIfNoIndex ? streams.FirstOrDefault() : null; 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> /// <summary>
/// Gets the number of threads. /// Gets the number of threads.
/// </summary> /// </summary>
/// <returns>System.Int32.</returns> /// <returns>System.Int32.</returns>
protected int GetNumberOfThreads(StreamState state, bool isWebm) protected int GetNumberOfThreads(StreamState state, bool isWebm)
{ {
var threads = ApiEntryPoint.Instance.GetEncodingOptions().EncodingThreadCount;
if (isWebm) if (isWebm)
{ {
// Recommended per docs // Recommended per docs
return Math.Max(Environment.ProcessorCount - 1, 2); return Math.Max(Environment.ProcessorCount - 1, 2);
} }
// Automatic
if (threads == -1)
{
return 0; return 0;
} }
return threads;
}
protected string H264Encoder protected string H264Encoder
{ {
get get
@ -326,77 +315,31 @@ namespace MediaBrowser.Api.Playback
var isVc1 = state.VideoStream != null && var isVc1 = state.VideoStream != null &&
string.Equals(state.VideoStream.Codec, "vc1", StringComparison.OrdinalIgnoreCase); string.Equals(state.VideoStream.Codec, "vc1", StringComparison.OrdinalIgnoreCase);
var qualitySetting = GetQualitySetting();
if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase)) if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
{ {
param = "-preset superfast"; param = "-preset superfast";
switch (qualitySetting)
{
case EncodingQuality.HighSpeed:
param += " -crf 23"; 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)) else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase))
{ {
param = "-preset fast"; param = "-preset fast";
switch (qualitySetting)
{
case EncodingQuality.HighSpeed:
param += " -crf 28"; param += " -crf 28";
break;
case EncodingQuality.HighQuality:
param += " -crf 25";
break;
case EncodingQuality.MaxQuality:
param += " -crf 21";
break;
}
} }
// h264 (h264_qsv) // h264 (h264_qsv)
else if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
{ {
switch (qualitySetting)
{
case EncodingQuality.HighSpeed:
param = "-preset 7"; param = "-preset 7";
break;
case EncodingQuality.HighQuality:
param = "-preset 4";
break;
case EncodingQuality.MaxQuality:
param = "-preset 1";
break;
}
} }
// h264 (libnvenc) // h264 (libnvenc)
else if (string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase))
{ {
switch (qualitySetting)
{
case EncodingQuality.HighSpeed:
param = "-preset high-performance"; param = "-preset high-performance";
break;
case EncodingQuality.HighQuality:
param = "";
break;
case EncodingQuality.MaxQuality:
param = "-preset high-quality";
break;
}
} }
// webm // webm
@ -409,20 +352,7 @@ namespace MediaBrowser.Api.Playback
var qmin = "0"; var qmin = "0";
var qmax = "50"; var qmax = "50";
switch (qualitySetting)
{
case EncodingQuality.HighSpeed:
crf = "10"; crf = "10";
break;
case EncodingQuality.HighQuality:
crf = "6";
break;
case EncodingQuality.MaxQuality:
crf = "4";
break;
default:
throw new ArgumentException("Unrecognized quality setting");
}
if (isVc1) if (isVc1)
{ {

View File

@ -521,42 +521,18 @@ namespace MediaBrowser.MediaEncoding.Encoder
var isVc1 = state.VideoStream != null && var isVc1 = state.VideoStream != null &&
string.Equals(state.VideoStream.Codec, "vc1", StringComparison.OrdinalIgnoreCase); string.Equals(state.VideoStream.Codec, "vc1", StringComparison.OrdinalIgnoreCase);
var qualitySetting = state.Quality;
if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase)) if (string.Equals(videoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
{ {
param = "-preset superfast"; param = "-preset superfast";
switch (qualitySetting)
{
case EncodingQuality.HighSpeed:
param += " -crf 28"; 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)) else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase))
{ {
param = "-preset fast"; param = "-preset fast";
switch (qualitySetting)
{
case EncodingQuality.HighSpeed:
param += " -crf 28"; param += " -crf 28";
break;
case EncodingQuality.HighQuality:
param += " -crf 25";
break;
case EncodingQuality.MaxQuality:
param += " -crf 21";
break;
}
} }
// webm // webm
@ -569,20 +545,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
var qmin = "0"; var qmin = "0";
var qmax = "50"; var qmax = "50";
switch (qualitySetting)
{
case EncodingQuality.HighSpeed:
crf = "10"; crf = "10";
break;
case EncodingQuality.HighQuality:
crf = "6";
break;
case EncodingQuality.MaxQuality:
crf = "4";
break;
default:
throw new ArgumentException("Unrecognized quality setting");
}
if (isVc1) if (isVc1)
{ {

View File

@ -25,7 +25,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
public Stream LogFileStream { get; set; } public Stream LogFileStream { get; set; }
public IProgress<double> Progress { get; set; } public IProgress<double> Progress { get; set; }
public TaskCompletionSource<bool> TaskCompletionSource; public TaskCompletionSource<bool> TaskCompletionSource;
public EncodingQuality Quality { get; set; }
public EncodingJobOptions Options { get; set; } public EncodingJobOptions Options { get; set; }
public string InputContainer { get; set; } public string InputContainer { get; set; }
public MediaSourceInfo MediaSource { get; set; } public MediaSourceInfo MediaSource { get; set; }

View File

@ -96,10 +96,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
TryStreamCopy(state, request); TryStreamCopy(state, request);
state.Quality = options.Context == EncodingContext.Static ?
EncodingQuality.MaxQuality :
GetQualitySetting();
return state; return state;
} }
@ -199,25 +195,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
state.MediaSource = mediaSource; 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() protected EncodingOptions GetEncodingOptions()
{ {
return _config.GetConfiguration<EncodingOptions>("encoding"); return _config.GetConfiguration<EncodingOptions>("encoding");

View File

@ -203,9 +203,6 @@
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingOptions.cs"> <Compile Include="..\MediaBrowser.Model\Configuration\EncodingOptions.cs">
<Link>Configuration\EncodingOptions.cs</Link> <Link>Configuration\EncodingOptions.cs</Link>
</Compile> </Compile>
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingQuality.cs">
<Link>Configuration\EncodingQuality.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Configuration\FanartOptions.cs"> <Compile Include="..\MediaBrowser.Model\Configuration\FanartOptions.cs">
<Link>Configuration\FanartOptions.cs</Link> <Link>Configuration\FanartOptions.cs</Link>
</Compile> </Compile>

View File

@ -168,9 +168,6 @@
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingOptions.cs"> <Compile Include="..\MediaBrowser.Model\Configuration\EncodingOptions.cs">
<Link>Configuration\EncodingOptions.cs</Link> <Link>Configuration\EncodingOptions.cs</Link>
</Compile> </Compile>
<Compile Include="..\MediaBrowser.Model\Configuration\EncodingQuality.cs">
<Link>Configuration\EncodingQuality.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Configuration\FanartOptions.cs"> <Compile Include="..\MediaBrowser.Model\Configuration\FanartOptions.cs">
<Link>Configuration\FanartOptions.cs</Link> <Link>Configuration\FanartOptions.cs</Link>
</Compile> </Compile>

View File

@ -3,7 +3,7 @@ namespace MediaBrowser.Model.Configuration
{ {
public class EncodingOptions public class EncodingOptions
{ {
public EncodingQuality EncodingQuality { get; set; } public int EncodingThreadCount { get; set; }
public string TranscodingTempPath { get; set; } public string TranscodingTempPath { get; set; }
public double DownMixAudioBoost { get; set; } public double DownMixAudioBoost { get; set; }
public string H264Encoder { get; set; } public string H264Encoder { get; set; }
@ -15,9 +15,9 @@ namespace MediaBrowser.Model.Configuration
{ {
H264Encoder = "libx264"; H264Encoder = "libx264";
DownMixAudioBoost = 2; DownMixAudioBoost = 2;
EncodingQuality = EncodingQuality.Auto;
EnableThrottling = true; EnableThrottling = true;
ThrottleThresholdInSeconds = 120; ThrottleThresholdInSeconds = 120;
EncodingThreadCount = -1;
} }
} }
} }

View File

@ -1,10 +0,0 @@
namespace MediaBrowser.Model.Configuration
{
public enum EncodingQuality
{
Auto,
HighSpeed,
HighQuality,
MaxQuality
}
}

View File

@ -159,7 +159,6 @@
<Compile Include="FileOrganization\TvFileOrganizationOptions.cs" /> <Compile Include="FileOrganization\TvFileOrganizationOptions.cs" />
<Compile Include="Configuration\BaseApplicationConfiguration.cs" /> <Compile Include="Configuration\BaseApplicationConfiguration.cs" />
<Compile Include="Configuration\DlnaOptions.cs" /> <Compile Include="Configuration\DlnaOptions.cs" />
<Compile Include="Configuration\EncodingQuality.cs" />
<Compile Include="Configuration\ImageOption.cs" /> <Compile Include="Configuration\ImageOption.cs" />
<Compile Include="Configuration\ImageSavingConvention.cs" /> <Compile Include="Configuration\ImageSavingConvention.cs" />
<Compile Include="LiveTv\LiveTvOptions.cs" /> <Compile Include="LiveTv\LiveTvOptions.cs" />

View File

@ -61,22 +61,22 @@ namespace MediaBrowser.Providers.MediaInfo
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var idString = item.Id.ToString("N"); //var idString = item.Id.ToString("N");
var cachePath = Path.Combine(_appPaths.CachePath, //var cachePath = Path.Combine(_appPaths.CachePath,
"ffprobe-audio", // "ffprobe-audio",
idString.Substring(0, 2), idString, "v" + SchemaVersion + _mediaEncoder.Version + item.DateModified.Ticks.ToString(_usCulture) + ".json"); // idString.Substring(0, 2), idString, "v" + SchemaVersion + _mediaEncoder.Version + item.DateModified.Ticks.ToString(_usCulture) + ".json");
try //try
{ //{
return _json.DeserializeFromFile<Model.MediaInfo.MediaInfo>(cachePath); // return _json.DeserializeFromFile<Model.MediaInfo.MediaInfo>(cachePath);
} //}
catch (FileNotFoundException) //catch (FileNotFoundException)
{ //{
} //}
catch (DirectoryNotFoundException) //catch (DirectoryNotFoundException)
{ //{
} //}
var result = await _mediaEncoder.GetMediaInfo(new MediaInfoRequest var result = await _mediaEncoder.GetMediaInfo(new MediaInfoRequest
{ {
@ -86,8 +86,8 @@ namespace MediaBrowser.Providers.MediaInfo
}, cancellationToken).ConfigureAwait(false); }, cancellationToken).ConfigureAwait(false);
Directory.CreateDirectory(Path.GetDirectoryName(cachePath)); //Directory.CreateDirectory(Path.GetDirectoryName(cachePath));
_json.SerializeToFile(result, cachePath); //_json.SerializeToFile(result, cachePath);
return result; return result;
} }