validate encoder presence
This commit is contained in:
parent
97446d04df
commit
79887b2c34
|
@ -286,28 +286,41 @@ namespace MediaBrowser.Api.Playback
|
||||||
|
|
||||||
protected string GetH264Encoder(StreamState state)
|
protected string GetH264Encoder(StreamState state)
|
||||||
{
|
{
|
||||||
|
var defaultEncoder = "libx264";
|
||||||
|
|
||||||
// Only use alternative encoders for video files.
|
// Only use alternative encoders for video files.
|
||||||
// When using concat with folder rips, if the mfx session fails to initialize, ffmpeg will be stuck retrying and will not exit gracefully
|
// When using concat with folder rips, if the mfx session fails to initialize, ffmpeg will be stuck retrying and will not exit gracefully
|
||||||
// Since transcoding of folder rips is expiremental anyway, it's not worth adding additional variables such as this.
|
// Since transcoding of folder rips is expiremental anyway, it's not worth adding additional variables such as this.
|
||||||
if (state.VideoType == VideoType.VideoFile)
|
if (state.VideoType == VideoType.VideoFile)
|
||||||
{
|
{
|
||||||
if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase) ||
|
var hwType = ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType;
|
||||||
string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
|
||||||
|
if (string.Equals(hwType, "qsv", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
string.Equals(hwType, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return "h264_qsv";
|
return GetAvailableEncoder("h264_qsv", defaultEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "nvenc", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(hwType, "nvenc", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return "h264_nvenc";
|
return GetAvailableEncoder("h264_nvenc", defaultEncoder);
|
||||||
}
|
}
|
||||||
if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(hwType, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return "h264_omx";
|
return GetAvailableEncoder("h264_omx", defaultEncoder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "libx264";
|
return defaultEncoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetAvailableEncoder(string preferredEncoder, string defaultEncoder)
|
||||||
|
{
|
||||||
|
if (MediaEncoder.SupportsEncoder(preferredEncoder))
|
||||||
|
{
|
||||||
|
return preferredEncoder;
|
||||||
|
}
|
||||||
|
return defaultEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -80,7 +80,10 @@ namespace MediaBrowser.Api.Playback
|
||||||
{
|
{
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
if (userAgent.IndexOf("cfnetwork", StringComparison.OrdinalIgnoreCase) != -1)
|
if (userAgent.IndexOf("cfnetwork", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||||
|
userAgent.IndexOf("ipad", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||||
|
userAgent.IndexOf("iphone", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||||
|
userAgent.IndexOf("ipod", StringComparison.OrdinalIgnoreCase) != -1)
|
||||||
{
|
{
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,5 +133,6 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
Task Init();
|
Task Init();
|
||||||
|
|
||||||
Task UpdateEncoderPath(string path, string pathType);
|
Task UpdateEncoderPath(string path, string pathType);
|
||||||
|
bool SupportsEncoder(string encoder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
"srt",
|
"srt",
|
||||||
"h264_nvenc",
|
"h264_nvenc",
|
||||||
"h264_qsv",
|
"h264_qsv",
|
||||||
|
"h264_omx",
|
||||||
"ac3"
|
"ac3"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -522,10 +522,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name of the output video codec
|
/// Gets the name of the output video codec
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="state">The state.</param>
|
|
||||||
/// <param name="options">The options.</param>
|
|
||||||
/// <returns>System.String.</returns>
|
/// <returns>System.String.</returns>
|
||||||
internal static string GetVideoEncoder(EncodingJob state, EncodingOptions options)
|
internal static string GetVideoEncoder(IMediaEncoder mediaEncoder, EncodingJob state, EncodingOptions options)
|
||||||
{
|
{
|
||||||
var codec = state.OutputVideoCodec;
|
var codec = state.OutputVideoCodec;
|
||||||
|
|
||||||
|
@ -533,7 +531,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
{
|
{
|
||||||
if (string.Equals(codec, "h264", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(codec, "h264", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return GetH264Encoder(state, options);
|
return GetH264Encoder(mediaEncoder, state, options);
|
||||||
}
|
}
|
||||||
if (string.Equals(codec, "vpx", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(codec, "vpx", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
|
@ -554,24 +552,43 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
return "copy";
|
return "copy";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetH264Encoder(EncodingJob state, EncodingOptions options)
|
private static string GetAvailableEncoder(IMediaEncoder mediaEncoder, string preferredEncoder, string defaultEncoder)
|
||||||
{
|
{
|
||||||
if (string.Equals(options.HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase) ||
|
if (mediaEncoder.SupportsEncoder(preferredEncoder))
|
||||||
string.Equals(options.HardwareAccelerationType, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
{
|
||||||
return "h264_qsv";
|
return preferredEncoder;
|
||||||
|
}
|
||||||
|
return defaultEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.Equals(options.HardwareAccelerationType, "nvenc", StringComparison.OrdinalIgnoreCase))
|
internal static string GetH264Encoder(IMediaEncoder mediaEncoder, EncodingJob state, EncodingOptions options)
|
||||||
{
|
{
|
||||||
return "h264_nvenc";
|
var defaultEncoder = "libx264";
|
||||||
}
|
|
||||||
if (string.Equals(options.HardwareAccelerationType, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
// Only use alternative encoders for video files.
|
||||||
|
// When using concat with folder rips, if the mfx session fails to initialize, ffmpeg will be stuck retrying and will not exit gracefully
|
||||||
|
// Since transcoding of folder rips is expiremental anyway, it's not worth adding additional variables such as this.
|
||||||
|
if (state.VideoType == VideoType.VideoFile)
|
||||||
{
|
{
|
||||||
return "h264_omx";
|
var hwType = options.HardwareAccelerationType;
|
||||||
|
|
||||||
|
if (string.Equals(hwType, "qsv", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
string.Equals(hwType, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return GetAvailableEncoder(mediaEncoder, "h264_qsv", defaultEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "libx264";
|
if (string.Equals(hwType, "nvenc", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return GetAvailableEncoder(mediaEncoder, "h264_nvenc", defaultEncoder);
|
||||||
|
}
|
||||||
|
if (string.Equals(hwType, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return GetAvailableEncoder(mediaEncoder, "h264_omx", defaultEncoder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool CanStreamCopyVideo(EncodingJobOptions request, MediaStream videoStream)
|
internal static bool CanStreamCopyVideo(EncodingJobOptions request, MediaStream videoStream)
|
||||||
|
|
|
@ -392,9 +392,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
//_logger.Info("Supported decoders: {0}", string.Join(",", list.ToArray()));
|
//_logger.Info("Supported decoders: {0}", string.Join(",", list.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SupportsEncoder(string decoder)
|
public bool SupportsEncoder(string encoder)
|
||||||
{
|
{
|
||||||
return _encoders.Contains(decoder, StringComparer.OrdinalIgnoreCase);
|
return _encoders.Contains(encoder, StringComparer.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SupportsDecoder(string decoder)
|
public bool SupportsDecoder(string decoder)
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
protected override async Task<string> GetCommandLineArguments(EncodingJob state)
|
protected override async Task<string> GetCommandLineArguments(EncodingJob state)
|
||||||
{
|
{
|
||||||
// Get the output codec name
|
// Get the output codec name
|
||||||
var videoCodec = EncodingJobFactory.GetVideoEncoder(state, GetEncodingOptions());
|
var videoCodec = EncodingJobFactory.GetVideoEncoder(MediaEncoder, state, GetEncodingOptions());
|
||||||
|
|
||||||
var format = string.Empty;
|
var format = string.Empty;
|
||||||
var keyFrame = string.Empty;
|
var keyFrame = string.Empty;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user