Exemple #1
0
        public override void CombineSuccessfulEncodes(EncodeJob[] jobs, string outputFileName)
        {
            if (jobs.Length == 0)
            {
                throw new ArgumentException("0 successful encodes to combine.");
            }
            if (jobs.Where(j => !j.Completed).Count() != 0)
            {
                throw new ArgumentException("Some jobs not completed.");
            }
            if (jobs.Where(j => !j.IsChunk).Count() != 0)
            {
                throw new ArgumentException("Some jobs have invalid or no chunk/scene.");
            }
            var unmantchedJobs = jobs.Where(j => j.VideoFileName != jobs.First().VideoFileName).Count();

            if (unmantchedJobs != 0)
            {
                throw new ArgumentException(unmantchedJobs + " jobs don't match videos");
            }

            //Sort the jobs and verify their expected output video actually exist
            var sortedJobs           = jobs.OrderBy(j => j.Chunk?.StartTime);
            var sortedJobOutputFiles = sortedJobs.Select(j =>
            {
                // The output file should be the only file in the job directory in the completed bucket
                var outDir = Path.Combine(AppConfigManager.Model.CompletedBucketPath, j.Id.ToString());
                if (_fileAccessor.DoesFolderExist(outDir) &&
                    _fileAccessor.GetFilesInFolder(outDir).Count() == 1)
                {
                    return(_fileAccessor.GetFilesInFolder(outDir).First());
                }
                else
                {
                    throw new DirectoryNotFoundException(
                        "Couldn't find job directory in completed bucket for job. CompletedBucket: "
                        + AppConfigManager.Model.CompletedBucketPath
                        + " job: " + jobs.ToString());
                }
            });

            //Concat the video files
            _videoAccessor.ConcatVideosIntoOneOutput(sortedJobOutputFiles.ToList()
                                                     , Path.Combine(AppConfigManager.Model.CompletedBucketPath, outputFileName));
        }