mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 03:26:07 +02:00
Add accurate bitrate reporting for ffmpeg jobs
This commit is contained in:
parent
db9c02fffd
commit
9ac5d5417b
2 changed files with 28 additions and 4 deletions
|
@ -192,13 +192,13 @@ namespace MediaBrowser.Api
|
||||||
|
|
||||||
_activeTranscodingJobs.Add(job);
|
_activeTranscodingJobs.Add(job);
|
||||||
|
|
||||||
ReportTranscodingProgress(job, state, null, null, null, null);
|
ReportTranscodingProgress(job, state, null, null, null, null, null);
|
||||||
|
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReportTranscodingProgress(TranscodingJob job, StreamState state, TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded)
|
public void ReportTranscodingProgress(TranscodingJob job, StreamState state, TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded, int? bitRate)
|
||||||
{
|
{
|
||||||
var ticks = transcodingPosition.HasValue ? transcodingPosition.Value.Ticks : (long?)null;
|
var ticks = transcodingPosition.HasValue ? transcodingPosition.Value.Ticks : (long?)null;
|
||||||
|
|
||||||
|
@ -208,6 +208,7 @@ namespace MediaBrowser.Api
|
||||||
job.CompletionPercentage = percentComplete;
|
job.CompletionPercentage = percentComplete;
|
||||||
job.TranscodingPositionTicks = ticks;
|
job.TranscodingPositionTicks = ticks;
|
||||||
job.BytesTranscoded = bytesTranscoded;
|
job.BytesTranscoded = bytesTranscoded;
|
||||||
|
job.BitRate = bitRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
var deviceId = state.Request.DeviceId;
|
var deviceId = state.Request.DeviceId;
|
||||||
|
@ -219,7 +220,7 @@ namespace MediaBrowser.Api
|
||||||
|
|
||||||
_sessionManager.ReportTranscodingInfo(deviceId, new TranscodingInfo
|
_sessionManager.ReportTranscodingInfo(deviceId, new TranscodingInfo
|
||||||
{
|
{
|
||||||
Bitrate = state.TotalOutputBitrate,
|
Bitrate = bitRate ?? state.TotalOutputBitrate,
|
||||||
AudioCodec = audioCodec,
|
AudioCodec = audioCodec,
|
||||||
VideoCodec = videoCodec,
|
VideoCodec = videoCodec,
|
||||||
Container = state.OutputContainer,
|
Container = state.OutputContainer,
|
||||||
|
@ -694,6 +695,7 @@ namespace MediaBrowser.Api
|
||||||
|
|
||||||
public long? BytesDownloaded { get; set; }
|
public long? BytesDownloaded { get; set; }
|
||||||
public long? BytesTranscoded { get; set; }
|
public long? BytesTranscoded { get; set; }
|
||||||
|
public int? BitRate { get; set; }
|
||||||
|
|
||||||
public long? TranscodingPositionTicks { get; set; }
|
public long? TranscodingPositionTicks { get; set; }
|
||||||
public long? DownloadPositionTicks { get; set; }
|
public long? DownloadPositionTicks { get; set; }
|
||||||
|
|
|
@ -1172,6 +1172,7 @@ namespace MediaBrowser.Api.Playback
|
||||||
double? percent = null;
|
double? percent = null;
|
||||||
TimeSpan? transcodingPosition = null;
|
TimeSpan? transcodingPosition = null;
|
||||||
long? bytesTranscoded = null;
|
long? bytesTranscoded = null;
|
||||||
|
int? bitRate = null;
|
||||||
|
|
||||||
var parts = line.Split(' ');
|
var parts = line.Split(' ');
|
||||||
|
|
||||||
|
@ -1235,11 +1236,32 @@ namespace MediaBrowser.Api.Playback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (part.StartsWith("bitrate=", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
var rate = part.Split(new[] { '=' }, 2).Last();
|
||||||
|
|
||||||
|
int? scale = null;
|
||||||
|
if (rate.IndexOf("kbits/s", StringComparison.OrdinalIgnoreCase) != -1)
|
||||||
|
{
|
||||||
|
scale = 1024;
|
||||||
|
rate = rate.Replace("kbits/s", string.Empty, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scale.HasValue)
|
||||||
|
{
|
||||||
|
float val;
|
||||||
|
|
||||||
|
if (float.TryParse(rate, NumberStyles.Any, UsCulture, out val))
|
||||||
|
{
|
||||||
|
bitRate = (int)Math.Ceiling(val * scale.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (framerate.HasValue || percent.HasValue)
|
if (framerate.HasValue || percent.HasValue)
|
||||||
{
|
{
|
||||||
ApiEntryPoint.Instance.ReportTranscodingProgress(transcodingJob, state, transcodingPosition, framerate, percent, bytesTranscoded);
|
ApiEntryPoint.Instance.ReportTranscodingProgress(transcodingJob, state, transcodingPosition, framerate, percent, bytesTranscoded, bitRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue