mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-02-20 03:22:54 +00:00
Merge branch 'master' into h265
This commit is contained in:
@@ -613,7 +613,9 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
}
|
||||
|
||||
// TODO: Perhaps also use original_size=1920x800 ??
|
||||
return string.Format("subtitles=filename='{0}'{1}{2}{3}",
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"subtitles=filename='{0}'{1}{2}",
|
||||
_mediaEncoder.EscapeSubtitleFilterPath(subtitlePath),
|
||||
charsetParam,
|
||||
// fallbackFontParam,
|
||||
@@ -622,7 +624,9 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
|
||||
var mediaPath = state.MediaPath ?? string.Empty;
|
||||
|
||||
return string.Format("subtitles='{0}:si={1}'{2}",
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"subtitles='{0}:si={1}'{2}",
|
||||
_mediaEncoder.EscapeSubtitleFilterPath(mediaPath),
|
||||
state.InternalSubtitleStreamOffset.ToString(_usCulture),
|
||||
// fallbackFontParam,
|
||||
@@ -1135,27 +1139,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -374,14 +374,14 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BaseRequest.Static || string.Equals(OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (BaseRequest.Static
|
||||
|| string.Equals(OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (AudioStream != null)
|
||||
{
|
||||
return AudioStream.SampleRate;
|
||||
}
|
||||
}
|
||||
|
||||
else if (BaseRequest.AudioSampleRate.HasValue)
|
||||
{
|
||||
// Don't exceed what the encoder supports
|
||||
@@ -397,7 +397,8 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BaseRequest.Static || string.Equals(OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (BaseRequest.Static
|
||||
|| string.Equals(OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (AudioStream != null)
|
||||
{
|
||||
@@ -405,13 +406,6 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
}
|
||||
}
|
||||
|
||||
//else if (BaseRequest.AudioSampleRate.HasValue)
|
||||
//{
|
||||
// // Don't exceed what the encoder supports
|
||||
// // Seeing issues of attempting to encode to 88200
|
||||
// return Math.Min(44100, BaseRequest.AudioSampleRate.Value);
|
||||
//}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -446,7 +440,8 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (BaseRequest.Static
|
||||
|| string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return VideoStream?.BitDepth;
|
||||
}
|
||||
@@ -463,7 +458,8 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (BaseRequest.Static
|
||||
|| string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return VideoStream?.RefFrames;
|
||||
}
|
||||
@@ -479,7 +475,8 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (BaseRequest.Static
|
||||
|| string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return VideoStream == null ? null : (VideoStream.AverageFrameRate ?? VideoStream.RealFrameRate);
|
||||
}
|
||||
@@ -545,7 +542,8 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (BaseRequest.Static
|
||||
|| string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return VideoStream?.CodecTag;
|
||||
}
|
||||
@@ -558,7 +556,8 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (BaseRequest.Static
|
||||
|| string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return VideoStream?.IsAnamorphic;
|
||||
}
|
||||
@@ -571,14 +570,12 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
var codec = OutputVideoCodec;
|
||||
|
||||
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return VideoStream?.Codec;
|
||||
}
|
||||
|
||||
return codec;
|
||||
return OutputVideoCodec;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,14 +583,12 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
var codec = OutputAudioCodec;
|
||||
|
||||
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return AudioStream?.Codec;
|
||||
}
|
||||
|
||||
return codec;
|
||||
return OutputAudioCodec;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,7 +596,8 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BaseRequest.Static || string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
if (BaseRequest.Static
|
||||
|| string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return VideoStream?.IsInterlaced;
|
||||
}
|
||||
@@ -636,6 +632,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
return GetMediaStreamCount(MediaStreamType.Video, int.MaxValue);
|
||||
}
|
||||
|
||||
return GetMediaStreamCount(MediaStreamType.Video, 1);
|
||||
}
|
||||
}
|
||||
@@ -648,17 +645,12 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
return GetMediaStreamCount(MediaStreamType.Audio, int.MaxValue);
|
||||
}
|
||||
|
||||
return GetMediaStreamCount(MediaStreamType.Audio, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public int HlsListSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public int HlsListSize => 0;
|
||||
|
||||
private int? GetMediaStreamCount(MediaStreamType type, int limit)
|
||||
{
|
||||
@@ -677,10 +669,6 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
Progress.Report(percentComplete.Value);
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -18,10 +19,11 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async void StartStreamingLog(EncodingJobInfo state, Stream source, Stream target)
|
||||
public async Task StartStreamingLog(EncodingJobInfo state, Stream source, Stream target)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (target)
|
||||
using (var reader = new StreamReader(source))
|
||||
{
|
||||
while (!reader.EndOfStream && reader.BaseStream.CanRead)
|
||||
@@ -97,8 +99,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||
{
|
||||
var currentMs = startMs + val.TotalMilliseconds;
|
||||
|
||||
var percentVal = currentMs / totalMs;
|
||||
percent = 100 * percentVal;
|
||||
percent = 100.0 * currentMs / totalMs;
|
||||
|
||||
transcodingPosition = val;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user