Merge pull request #1369 from teacupx/master

Enable Exynos MFC encoder and fix transcoding bitrate control
This commit is contained in:
dkanada 2019-06-20 16:55:09 -07:00 committed by GitHub
commit dbc2cda9d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 13 deletions

View File

@ -1083,27 +1083,51 @@ namespace MediaBrowser.Controller.MediaEncoding
{
var bitrate = request.VideoBitRate;
// If specific values were requested, then force the caller to supply a bitrate as well
if (request.Height.HasValue && request.Width.HasValue)
{
return bitrate;
}
if (videoStream != null)
{
if (bitrate.HasValue)
{
var inputVideoCodec = videoStream.Codec;
bitrate = ScaleBitrate(bitrate.Value, inputVideoCodec, outputVideoCodec);
var isUpscaling = request.Height.HasValue && videoStream.Height.HasValue &&
request.Height.Value > videoStream.Height.Value && request.Width.HasValue && videoStream.Width.HasValue &&
request.Width.Value > videoStream.Width.Value;
// If a max bitrate was requested, don't let the scaled bitrate exceed it
if (request.VideoBitRate.HasValue)
// Don't allow bitrate increases unless upscaling
if (!isUpscaling)
{
if (bitrate.HasValue && videoStream.BitRate.HasValue)
{
bitrate = Math.Min(bitrate.Value, request.VideoBitRate.Value);
bitrate = GetMinBitrate(videoStream.BitRate.Value, bitrate.Value);
}
}
}
if (bitrate.HasValue)
{
var inputVideoCodec = videoStream.Codec;
bitrate = ScaleBitrate(bitrate.Value, inputVideoCodec, outputVideoCodec);
// If a max bitrate was requested, don't let the scaled bitrate exceed it
if (request.VideoBitRate.HasValue)
{
bitrate = Math.Min(bitrate.Value, request.VideoBitRate.Value);
}
}
return bitrate;
}
private int GetMinBitrate(int sourceBitrate, int requestedBitrate)
{
// these values were chosen from testing to improve low bitrate streams
if (sourceBitrate <= 2000000)
{
sourceBitrate = Convert.ToInt32(sourceBitrate * 2.5);
}
else if (sourceBitrate <= 3000000)
{
sourceBitrate = Convert.ToInt32(sourceBitrate * 2);
}
var bitrate = Math.Min(sourceBitrate, requestedBitrate);
return bitrate;
}

View File

@ -207,6 +207,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
"hevc_omx",
"h264_vaapi",
"hevc_vaapi",
"h264_v4l2m2m",
"ac3"
};