support h264_omx

This commit is contained in:
Luke Pulverenti 2016-06-30 14:59:18 -04:00
parent 4a95ec28f2
commit 52d8ddb050
4 changed files with 69 additions and 51 deletions

View file

@ -286,11 +286,19 @@ namespace MediaBrowser.Api.Playback
protected string GetH264Encoder(StreamState state) protected string GetH264Encoder(StreamState state)
{ {
if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase) ||
string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "h264_qsv", StringComparison.OrdinalIgnoreCase))
{ {
return "h264_qsv"; return "h264_qsv";
}
if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "libnvenc", StringComparison.OrdinalIgnoreCase))
{
return "libnvenc";
}
if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "h264_omx", StringComparison.OrdinalIgnoreCase))
{
return "h264_omx";
} }
return "libx264"; return "libx264";
@ -395,15 +403,18 @@ namespace MediaBrowser.Api.Playback
if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
{ {
param += " -profile:v " + state.VideoRequest.Profile; if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase))
{
// not supported by h264_omx
param += " -profile:v " + state.VideoRequest.Profile;
}
} }
if (!string.IsNullOrEmpty(state.VideoRequest.Level)) if (!string.IsNullOrEmpty(state.VideoRequest.Level))
{ {
var h264Encoder = GetH264Encoder(state);
// h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format // h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format
if (String.Equals(h264Encoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) || String.Equals(h264Encoder, "libnvenc", StringComparison.OrdinalIgnoreCase)) if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) ||
string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase))
{ {
switch (state.VideoRequest.Level) switch (state.VideoRequest.Level)
{ {
@ -438,16 +449,21 @@ namespace MediaBrowser.Api.Playback
param += " -level " + state.VideoRequest.Level; param += " -level " + state.VideoRequest.Level;
break; break;
} }
return param;
} }
else else if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase))
{ {
param += " -level " + state.VideoRequest.Level; param += " -level " + state.VideoRequest.Level;
} }
} }
return "-pix_fmt yuv420p " + param; if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase))
{
param = "-pix_fmt yuv420p " + param;
}
return param;
} }
protected string GetAudioFilterParam(StreamState state, bool isHls) protected string GetAudioFilterParam(StreamState state, bool isHls)
@ -563,14 +579,6 @@ namespace MediaBrowser.Api.Playback
filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam)); filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam));
} }
if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
{
if (filters.Count > 1)
{
//filters[filters.Count - 1] += ":flags=fast_bilinear";
}
}
var output = string.Empty; var output = string.Empty;
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode) if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode)
@ -1650,7 +1658,7 @@ namespace MediaBrowser.Api.Playback
if (!string.IsNullOrWhiteSpace(request.AudioCodec)) if (!string.IsNullOrWhiteSpace(request.AudioCodec))
{ {
state.SupportedAudioCodecs = request.AudioCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToList(); state.SupportedAudioCodecs = request.AudioCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToList();
state.Request.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault(i => MediaEncoder.CanEncodeToAudioCodec(i)) state.Request.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault(i => MediaEncoder.CanEncodeToAudioCodec(i))
?? state.SupportedAudioCodecs.FirstOrDefault(); ?? state.SupportedAudioCodecs.FirstOrDefault();
} }

View file

@ -377,7 +377,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
if (MediaEncoder.SupportsDecoder("h264_qsv")) if (MediaEncoder.SupportsDecoder("h264_qsv"))
{ {
// Seeing stalls and failures with decoding. Not worth it compared to encoding. // Seeing stalls and failures with decoding. Not worth it compared to encoding.
//return "-c:v h264_qsv "; return "-c:v h264_qsv ";
} }
break; break;
case "mpeg2video": case "mpeg2video":
@ -672,17 +672,20 @@ namespace MediaBrowser.MediaEncoding.Encoder
if (!string.IsNullOrEmpty(state.Options.Profile)) if (!string.IsNullOrEmpty(state.Options.Profile))
{ {
param += " -profile:v " + state.Options.Profile; if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase))
{
// not supported by h264_omx
param += " -profile:v " + state.Options.Profile;
}
} }
var levelString = state.Options.Level.HasValue ? state.Options.Level.Value.ToString(CultureInfo.InvariantCulture) : null; var levelString = state.Options.Level.HasValue ? state.Options.Level.Value.ToString(CultureInfo.InvariantCulture) : null;
if (!string.IsNullOrEmpty(levelString)) if (!string.IsNullOrEmpty(levelString))
{ {
var h264Encoder = EncodingJobFactory.GetH264Encoder(state, GetEncodingOptions());
// h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format // h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format
if (String.Equals(h264Encoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) || String.Equals(h264Encoder, "libnvenc", StringComparison.OrdinalIgnoreCase)) if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) ||
string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase))
{ {
switch (levelString) switch (levelString)
{ {
@ -718,13 +721,20 @@ namespace MediaBrowser.MediaEncoding.Encoder
break; break;
} }
} }
else else if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase))
{ {
param += " -level " + levelString; param += " -level " + levelString;
} }
} }
return "-pix_fmt yuv420p " + param; if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase))
{
param = "-pix_fmt yuv420p " + param;
}
return param;
} }
protected string GetVideoBitrateParam(EncodingJob state, string videoCodec) protected string GetVideoBitrateParam(EncodingJob state, string videoCodec)

View file

@ -27,17 +27,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
return new Tuple<List<string>, List<string>>(decoders, encoders); return new Tuple<List<string>, List<string>>(decoders, encoders);
} }
private List<string> GetDecoders(string ffmpegPath) private List<string> GetDecoders(string encoderAppPath)
{ {
string output = string.Empty; string output = string.Empty;
try try
{ {
output = GetFFMpegOutput(ffmpegPath, "-decoders"); output = GetProcessOutput(encoderAppPath, "-decoders");
} }
catch catch
{ {
} }
//_logger.Debug("ffmpeg decoder query result: {0}", output ?? string.Empty);
var found = new List<string>(); var found = new List<string>();
var required = new[] var required = new[]
@ -51,12 +50,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
{ {
var srch = " " + codec + " "; var srch = " " + codec + " ";
if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) == -1) if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1)
{
_logger.Warn("ffmpeg is missing decoder " + codec);
}
else
{ {
_logger.Info("Decoder available: " + codec);
found.Add(codec); found.Add(codec);
} }
} }
@ -64,17 +60,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
return found; return found;
} }
private List<string> GetEncoders(string ffmpegPath) private List<string> GetEncoders(string encoderAppPath)
{ {
string output = null; string output = null;
try try
{ {
output = GetFFMpegOutput(ffmpegPath, "-encoders"); output = GetProcessOutput(encoderAppPath, "-encoders");
} }
catch catch
{ {
} }
//_logger.Debug("ffmpeg encoder query result: {0}", output ?? string.Empty);
var found = new List<string>(); var found = new List<string>();
var required = new[] var required = new[]
@ -89,19 +84,18 @@ namespace MediaBrowser.MediaEncoding.Encoder
"libmp3lame", "libmp3lame",
"libopus", "libopus",
//"libvorbis", //"libvorbis",
"srt" "srt",
"libnvenc",
"h264_qsv"
}; };
foreach (var codec in required) foreach (var codec in required)
{ {
var srch = " " + codec + " "; var srch = " " + codec + " ";
if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) == -1) if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1)
{
_logger.Warn("ffmpeg is missing encoder " + codec);
}
else
{ {
_logger.Info("Encoder available: " + codec);
found.Add(codec); found.Add(codec);
} }
} }
@ -109,7 +103,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
return found; return found;
} }
private string GetFFMpegOutput(string path, string arguments) private string GetProcessOutput(string path, string arguments)
{ {
var process = new Process var process = new Process
{ {
@ -147,7 +141,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
} }
catch (Exception ex1) catch (Exception ex1)
{ {
_logger.ErrorException("Error killing ffmpeg", ex1); _logger.ErrorException("Error killing process", ex1);
} }
throw; throw;

View file

@ -556,13 +556,19 @@ namespace MediaBrowser.MediaEncoding.Encoder
internal static string GetH264Encoder(EncodingJob state, EncodingOptions options) internal static string GetH264Encoder(EncodingJob state, EncodingOptions options)
{ {
if (string.Equals(options.HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(options.HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase) ||
string.Equals(options.HardwareAccelerationType, "h264_qsv", StringComparison.OrdinalIgnoreCase))
{ {
// It's currently failing on live tv return "h264_qsv";
if (state.RunTimeTicks.HasValue) }
{
return "h264_qsv"; if (string.Equals(options.HardwareAccelerationType, "libnvenc", StringComparison.OrdinalIgnoreCase))
} {
return "libnvenc";
}
if (string.Equals(options.HardwareAccelerationType, "h264_omx", StringComparison.OrdinalIgnoreCase))
{
return "h264_omx";
} }
return "libx264"; return "libx264";