Resolved ffmpeg remaining as a zombie process
This commit is contained in:
@@ -39,7 +39,7 @@ public class EncoderService : BackgroundService, IEncoderService {
|
||||
if (JobQueue.Count > 0) {
|
||||
// Grab a reference to the next job in queue
|
||||
var job = JobQueue.Peek();
|
||||
ProcessJob(job); // Process the job
|
||||
ProcessJob(job, stoppingToken).Wait(stoppingToken); // Process the job
|
||||
JobQueue.Dequeue(); // Remove it from the queue
|
||||
Jobs.Add(job); // Add it to the completed jobs list
|
||||
}
|
||||
@@ -61,19 +61,21 @@ public class EncoderService : BackgroundService, IEncoderService {
|
||||
return JobQueue.Concat(Jobs);
|
||||
}
|
||||
|
||||
void ProcessJob(EncodingJob job) {
|
||||
async Task ProcessJob(EncodingJob job, CancellationToken cancellationToken) {
|
||||
job.Status = JobStatus.InProgress;
|
||||
var file = job.FilePath;
|
||||
var mediaInfo = FFProbe.Analyse(file);
|
||||
var mediaInfo = await FFProbe.AnalyseAsync(file, cancellationToken: cancellationToken);
|
||||
if (mediaInfo.PrimaryVideoStream == null) {
|
||||
job.Status = JobStatus.Failed;
|
||||
return;
|
||||
}
|
||||
var W = mediaInfo.PrimaryVideoStream.Width;
|
||||
var H = mediaInfo.PrimaryVideoStream.Height;
|
||||
|
||||
int W = mediaInfo.PrimaryVideoStream.Width;
|
||||
int H = mediaInfo.PrimaryVideoStream.Height;
|
||||
string outputPath = Path.Combine(options.TemporaryFilesPath, Path.GetFileName(job.FilePath));
|
||||
int qp = Utils.ToQPValue(W, H);
|
||||
var status = FFMpegArguments.FromFileInput(file, true, args => args.WithHardwareAcceleration())
|
||||
var result = FFMpegArguments
|
||||
.FromFileInput(file, true, args => args.WithHardwareAcceleration())
|
||||
.OutputToFile(outputPath, true, args => args
|
||||
.CopyChannel(Channel.Audio)
|
||||
.CopyChannel(Channel.Subtitle)
|
||||
@@ -84,8 +86,9 @@ public class EncoderService : BackgroundService, IEncoderService {
|
||||
.WithArgument(new NvencQPArgument((byte)qp))
|
||||
.WithFastStart()
|
||||
)
|
||||
.NotifyOnProgress(progress => {
|
||||
Logger.Log(LogLevel.Information,
|
||||
.NotifyOnProgress(progress =>
|
||||
{
|
||||
Logger.Log(LogLevel.Information,
|
||||
$"""
|
||||
Job {job.Id}: {progress / mediaInfo.Duration:P}
|
||||
Processed {progress:g} | Total {mediaInfo.Duration:g}
|
||||
@@ -94,9 +97,11 @@ public class EncoderService : BackgroundService, IEncoderService {
|
||||
Output path: {outputPath}
|
||||
""");
|
||||
job.Progress = (float)(progress / mediaInfo.Duration);
|
||||
})
|
||||
.ProcessSynchronously();
|
||||
if(status) {
|
||||
}).CancellableThrough(cancellationToken)
|
||||
.ProcessAsynchronously();
|
||||
result.Wait(cancellationToken);
|
||||
|
||||
if(result.Result) {
|
||||
job.Status = JobStatus.Completed;
|
||||
job.EncodedFilePath = outputPath;
|
||||
File.Delete(file); // Clean up original file
|
||||
|
||||
Reference in New Issue
Block a user