private Guid HandleNewMuxJob(MuxJobRequestModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var outputFilename = $"{model.OutputFolder}{Path.DirectorySeparatorChar}{model.DestinationFilename}";
            var frameCount     = _helper.GetDuration(model.VideoSourceFilename);

            string arguments = string.Empty;

            if (model.Inpoint > TimeSpan.Zero)
            {
                arguments += $"-ss {model.Inpoint:g} ";
            }
            arguments += $@"-xerror -i ""{model.VideoSourceFilename}"" -i ""{model.AudioSourceFilename}"" -map 0:v:0 -map 1:a:0 -c copy -y ""{outputFilename}""";
            var jobs = new List <FFmpegJob>
            {
                new MuxJob
                {
                    Arguments                  = arguments,
                    State                      = TranscodingJobState.Queued,
                    DestinationFilename        = outputFilename,
                    DestinationDurationSeconds = frameCount
                }
            };
            var request = new MuxJobRequest
            {
                AudioSourceFilename = model.AudioSourceFilename,
                VideoSourceFilename = model.VideoSourceFilename,
                DestinationFilename = model.DestinationFilename,
                OutputFolder        = model.OutputFolder
            };

            return(_repository.Add(request, jobs));
        }
示例#2
0
        public Guid Add(MuxJobRequest request, ICollection <FFmpegJob> jobs)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (jobs == null)
            {
                throw new ArgumentNullException(nameof(jobs));
            }

            Guid jobCorrelationId = Guid.NewGuid();

            using (var scope = TransactionUtils.CreateTransactionScope())
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Execute(
                        "INSERT INTO FfmpegMuxRequest (JobCorrelationId, VideoSourceFilename, AudioSourceFilename, DestinationFilename, OutputFolder, Needed, Created) VALUES(@JobCorrelationId, @VideoSourceFilename, @AudioSourceFilename, @DestinationFilename, @OutputFolder, @Needed, @Created);",
                        new
                    {
                        JobCorrelationId = jobCorrelationId,
                        request.VideoSourceFilename,
                        request.AudioSourceFilename,
                        request.Needed,
                        request.DestinationFilename,
                        request.OutputFolder,
                        Created = DateTime.UtcNow
                    });

                    foreach (MuxJob job in jobs.Select(x => x as MuxJob))
                    {
                        var jobId = connection.ExecuteScalar <int>(
                            "INSERT INTO FfmpegJobs (JobCorrelationId, Created, Needed, JobState, JobType) VALUES(@JobCorrelationId, @Created, @Needed, @State, @JobType);SELECT @@IDENTITY;",
                            new
                        {
                            JobCorrelationId = jobCorrelationId,
                            Created          = DateTimeOffset.UtcNow,
                            job.Needed,
                            State   = job.State,
                            JobType = JobType.Mux
                        });

                        connection.Execute(
                            "INSERT INTO FfmpegTasks (FfmpegJobs_id, Arguments, TaskState, DestinationFilename, DestinationDurationSeconds, VerifyOutput) VALUES(@FfmpegJobsId, @Arguments, @QueuedState, @DestinationFilename, @DestinationDurationSeconds, @VerifyOutput);",
                            new
                        {
                            FfmpegJobsId = jobId,
                            job.Arguments,
                            QueuedState = TranscodingJobState.Queued,
                            job.DestinationFilename,
                            job.DestinationDurationSeconds,
                            VerifyOutput = false
                        });
                    }
                }

                scope.Complete();

                return(jobCorrelationId);
            }
        }