Exemple #1
0
        /// <summary>
        /// Opens an encoder and starts encoding a specified job
        /// </summary>
        public override void BeginEncodeJobAttempts(EncodeJob job, string encoderType)
        {
            //make the encoder
            IEncoder encoder = encoderType.ToLower() switch
            {
                "libaomffmpeg" => new EncoderLibaomFfmpeg(),
                "hevcffmpeg" => new EncoderHevcFfmpeg(),
                _ => throw new InvalidOperationException()
            };

            EncodeAttempt?attempt;

            do
            {
                if (0 != job.Attempts.Count)
                {
                    EncodeJobManager.ImproveQuality(job);
                }
                try
                {
                    var outputPath = Path.Combine(AppConfigManager.Model.ActiveBucketPath,
                                                  job.Id.ToString(),
                                                  EncodeJob.GenerateJobOutputFilename(job));

                    //Start the encode
                    DateTime startTime = DateTime.Now;
                    encoder.Encode(job, outputPath);

                    //Save the attempt
                    attempt = new EncodeAttempt(outputPath)
                    {
                        CommandLineArgs = (string)job.AdditionalCommandArguments.Clone(),
                        StartTime       = startTime,
                        EndTime         = DateTime.Now,
                        VmafResult      = (job.IsChunk) ?
                                          _videoAccessor.GetVmafScene(Path.Combine(job.VideoDirectoryPath, job.VideoFileName),
                                                                      outputPath,
                                                                      job.Chunk !.StartTime,
                                                                      job.Chunk !.EndTime) :
                                          _videoAccessor.GetVmaf(Path.Combine(job.VideoDirectoryPath, job.VideoFileName), outputPath),
                        FileSize = _fileAccessor.GetFileSize(outputPath)
                    };
                    var oldJob = (job.Clone() as EncodeJob) !;
                    oldJob.Id       = job.Id;
                    oldJob.Attempts = job.Attempts;
                    job.Attempts.Add(attempt);
                    try
                    {
                        EncodeJobManager.Instance.UpdateJob(oldJob, job);
                        job = EncodeJobManager.Instance.FindEncodeJob(job.Id) ?? job;
                    }
                    catch
                    { }
                }
                catch
                { attempt = null; }
            } while (RunAgain(job, attempt?.OriginalOutputPath));
        }