Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for encoding with libx265 and hevc_nvenc #1433

Merged
merged 2 commits into from Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Expand Up @@ -28,6 +28,7 @@
- [DrPandemic](https://github.com/drpandemic)
- [joern-h](https://github.com/joern-h)
- [Khinenw](https://github.com/HelloWorld017)
- [fhriley](https://github.com/fhriley)

# Emby Contributors

Expand Down
7 changes: 6 additions & 1 deletion MediaBrowser.Api/Playback/BaseStreamingService.cs
Expand Up @@ -154,7 +154,12 @@ private string GetOutputFilePath(StreamState state, EncodingOptions encodingOpti
return Path.Combine(folder, filename + ext);
}

protected virtual string GetDefaultH264Preset() => "superfast";
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");

protected virtual string GetDefaultEncoderPreset()
{
return "superfast";
}

private async Task AcquireResources(StreamState state, CancellationTokenSource cancellationTokenSource)
{
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Api/Playback/Hls/BaseHlsService.cs
Expand Up @@ -304,7 +304,7 @@ protected override string GetCommandLineArguments(string outputPath, EncodingOpt
return args;
}

protected override string GetDefaultH264Preset()
protected override string GetDefaultEncoderPreset()
{
return "veryfast";
}
Expand Down
10 changes: 7 additions & 3 deletions MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs
Expand Up @@ -895,9 +895,13 @@ protected override string GetVideoArguments(StreamState state, EncodingOptions e
// See if we can save come cpu cycles by avoiding encoding
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
{
if (state.VideoStream != null && EncodingHelper.IsH264(state.VideoStream) && !string.Equals(state.VideoStream.NalLengthSize, "0", StringComparison.OrdinalIgnoreCase))
if (state.VideoStream != null && !string.Equals(state.VideoStream.NalLengthSize, "0", StringComparison.OrdinalIgnoreCase))
{
args += " -bsf:v h264_mp4toannexb";
string bitStreamArgs = EncodingHelper.GetBitStreamArgs(state.VideoStream);
if (!string.IsNullOrEmpty(bitStreamArgs))
{
args += " " + bitStreamArgs;
}
}

//args += " -flags -global_header";
Expand All @@ -909,7 +913,7 @@ protected override string GetVideoArguments(StreamState state, EncodingOptions e

var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;

args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultH264Preset()) + keyFrameArg;
args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultEncoderPreset()) + keyFrameArg;

//args += " -mixed-refs 0 -refs 3 -x264opts b_pyramid=0:weightb=0:weightp=0";

Expand Down
10 changes: 7 additions & 3 deletions MediaBrowser.Api/Playback/Hls/VideoHlsService.cs
Expand Up @@ -92,10 +92,14 @@ protected override string GetVideoArguments(StreamState state, EncodingOptions e
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
{
// if h264_mp4toannexb is ever added, do not use it for live tv
if (state.VideoStream != null && EncodingHelper.IsH264(state.VideoStream) &&
if (state.VideoStream != null &&
!string.Equals(state.VideoStream.NalLengthSize, "0", StringComparison.OrdinalIgnoreCase))
{
args += " -bsf:v h264_mp4toannexb";
string bitStreamArgs = EncodingHelper.GetBitStreamArgs(state.VideoStream);
if (!string.IsNullOrEmpty(bitStreamArgs))
{
args += " " + bitStreamArgs;
}
}
}
else
Expand All @@ -105,7 +109,7 @@ protected override string GetVideoArguments(StreamState state, EncodingOptions e

var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;

args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultH264Preset()) + keyFrameArg;
args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultEncoderPreset()) + keyFrameArg;

// Add resolution params, if specified
if (!hasGraphicalSubs)
Expand Down
Expand Up @@ -77,7 +77,8 @@ protected override string GetOutputFileExtension(StreamState state)
{
var videoCodec = state.VideoRequest.VideoCodec;

if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase) ||
string.Equals(videoCodec, "h265", StringComparison.OrdinalIgnoreCase))
{
return ".ts";
}
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Api/Playback/Progressive/VideoService.cs
Expand Up @@ -120,7 +120,7 @@ public Task<object> Head(GetVideoStream request)

protected override string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding)
{
return EncodingHelper.GetProgressiveVideoFullCommandLine(state, encodingOptions, outputPath, GetDefaultH264Preset());
return EncodingHelper.GetProgressiveVideoFullCommandLine(state, encodingOptions, outputPath, GetDefaultEncoderPreset());
}
}
}