public static void EncodeLargestChunk(RenderChunkStatus LargestChunk)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            bool isZipProduction = LargestChunk.Job.Production.IsZipProduction;

            if (isZipProduction == false)
            {
                for (int i = LargestChunk.StartIndex; i <= LargestChunk.EndIndex; i++)
                {
                    LargestChunk.Job.RenderChunkStatusList.First(item => item.StartIndex == i).Status = 6;
                }

                string cmd = "";
                cmd += "-hwaccel cuvid";
                cmd += " -y -loglevel panic";
                cmd += " -start_number " + LargestChunk.StartFrame;
                cmd += " -f image2";
                cmd += " -i " + JobPathHelper.GetLocalJobRenderOutputFileMask(LargestChunk.Job);
                cmd += " -vframes " + (LargestChunk.EndFrame - LargestChunk.StartFrame + 1);
                cmd += " -pix_fmt yuv420p";

                if (Settings.UseCuda)
                {
                    cmd += " -c:v h264_nvenc";
                }
                else
                {
                    cmd += " -c:v libx264";
                }

                cmd += " -profile:v high -qp 19 -preset fast ";
                cmd += JobPathHelper.GetRenderChunkPath(LargestChunk);

                Encode(LargestChunk.Job, cmd);
            }

            for (int i = LargestChunk.StartIndex; i <= LargestChunk.EndIndex; i++)
            {
                LargestChunk.Job.RenderChunkStatusList.First(item => item.StartIndex == i).Status = 7;
            }

            IsBusy = false;
        }
        private RenderChunkStatus GetLargestChunkRendered(Job job)
        {
            RenderChunkStatus result = null;

            List <RenderChunkStatus> renderedChunkList = job.RenderChunkStatusList.Where(item => item.Status == 5).ToList();
            int lastIndex;

            if (renderedChunkList.Count > 0)
            {
                result          = renderedChunkList[0];
                result.EndIndex = result.StartIndex;
                lastIndex       = result.StartIndex;
            }
            else
            {
                return(null);
            }

            if (renderedChunkList.Count > 1)
            {
                for (int i = 1; i < renderedChunkList.Count; i++)
                {
                    RenderChunkStatus thisChunk = renderedChunkList[i];

                    if (thisChunk.StartIndex == lastIndex + 1)
                    {
                        result.EndFrame = thisChunk.EndFrame;
                        result.EndIndex = thisChunk.StartIndex;
                    }
                    else
                    {
                        result          = thisChunk;
                        result.EndIndex = result.StartIndex;
                    }

                    lastIndex = thisChunk.StartIndex;
                }
            }

            return(result);
        }
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            timer.Stop();

            client   = new MongoClient(string.Format(@"mongodb://{0}:{1}", Settings.MongoServerURL, Settings.MongoPort));
            database = client.GetDatabase("deadline10db");

            database = client.GetDatabase("deadline10db");
            var          jobCollection  = database.GetCollection <BsonDocument>("Jobs");
            var          taskCollection = database.GetCollection <BsonDocument>("JobTasks");
            BsonDocument jobDoc         = null;

            try
            {
                string jobName = string.Format("{0} [{1}]", job.ID, job.RenderStartTime);
                List <BsonDocument> jobList = jobCollection.Find(Builders <BsonDocument> .Filter.AnyEq("Props.Name", jobName)).SortByDescending(bson => bson["LastWriteTime"]).ToList();
                if (jobList.Count == 0)
                {
                    timer.Start();
                    return;
                }
                jobDoc = jobList[0];

                int    status         = Convert.ToInt32(jobDoc["Stat"]);
                double tasks          = Convert.ToDouble(jobDoc["Props"]["Tasks"]);
                double completedTasks = Convert.ToDouble(jobDoc["CompletedChunks"]);
                string mongoJobId     = Convert.ToString(jobDoc["_id"]);

                var taskResults = taskCollection.Find(Builders <BsonDocument> .Filter.Eq("JobID", mongoJobId)).SortByDescending(bson => bson["TaskID"]);
                var taskList    = taskResults.ToList();

                bool createNewTasks = (job.RenderChunkStatusList.Count == 0);

                //get all render chunk statuses
                foreach (BsonDocument taskDoc in taskList)
                {
                    int taskID = Convert.ToInt32(taskDoc["TaskID"]);

                    RenderChunkStatus currentChunk;

                    if (createNewTasks)
                    {
                        currentChunk            = new RenderChunkStatus();
                        currentChunk.StartIndex = taskID;
                        currentChunk.Job        = job;
                    }
                    else
                    {
                        currentChunk = job.RenderChunkStatusList.First(item => item.StartIndex == taskID);
                    }


                    currentChunk.SlaveName = Convert.ToString(taskDoc["Slave"]);
                    currentChunk.Status    = Math.Max(currentChunk.Status, Convert.ToInt32(taskDoc["Stat"]));
                    string[] frameString = Convert.ToString(taskDoc["Frames"]).Split(new char[] { '-' });
                    currentChunk.StartFrame = Convert.ToInt32(frameString[0]);
                    if (frameString.Length > 1)
                    {
                        currentChunk.EndFrame = Convert.ToInt32(frameString[1]);
                    }
                    else
                    {
                        currentChunk.EndFrame = currentChunk.StartFrame;
                    }

                    var slaveCollection           = database.GetCollection <BsonDocument>("SlaveInfo");
                    List <BsonDocument> slaveList = slaveCollection.Find(Builders <BsonDocument> .Filter.AnyEq("_id", currentChunk.SlaveName.ToLower())).ToList();
                    if (slaveList.Count > 0)
                    {
                        BsonDocument slaveInfo = slaveList[0];
                        currentChunk.Processors     = Convert.ToInt32(slaveInfo["Procs"]);
                        currentChunk.ProcessorSpeed = Convert.ToInt32(slaveInfo["ProcSpd"]);
                    }

                    Dictionary <string, object> taskVal = (Dictionary <string, object>)BsonTypeMapper.MapToDotNetValue(taskDoc);

                    currentChunk.RenderStartDate = (DateTime)taskVal["StartRen"];
                    currentChunk.RenderEndDate   = (DateTime)taskVal["Comp"];
                    currentChunk.Status          = Math.Max(currentChunk.Status, Convert.ToInt32(taskDoc["Stat"]));

                    if (createNewTasks)
                    {
                        job.RenderChunkStatusList.Add(currentChunk);
                    }
                }

                if (createNewTasks)
                {
                    job.RenderChunkStatusList = job.RenderChunkStatusList.OrderBy(item => item.StartIndex).ToList();
                }

                RenderChunkStatus largestChunk = GetLargestChunkRendered(job);
                if (largestChunk != null)
                {
                    RenderChunkEncoder.EncodeLargestChunk(largestChunk);
                }

                int finishedChunks = job.RenderChunkStatusList.Count(item => item.Status == 7);

                job.Progress = (float)Math.Round(100f * finishedChunks / job.RenderChunkStatusList.Count);

                if (finishedChunks == taskList.Count)
                {
                    if (RenderChunkEncoder.MergeChunks(job) == true)
                    {
                        CompleteJob();
                    }
                    else
                    {
                        FireFailureEvent(job.ErrorStatus);
                    }
                }
                else
                {
                    if (status == 4)
                    {
                        FailJob();
                    }
                    else
                    {
                        timer.Start();
                    }
                }
            }
            catch (Exception ex)
            {
                timer.Start();
            }
        }
Exemple #4
0
 public static string GetRenderChunkPath(RenderChunkStatus renderChunk)
 {
     return(Path.Combine(GetLocalJobDirectory(renderChunk.Job), "clip_" + renderChunk.Job.Position + "_chunk_" + string.Format("{0:00000}", renderChunk.StartFrame) + "_" + string.Format("{0:00000}", renderChunk.EndFrame) + ".mp4"));
 }