Exemplo n.º 1
0
        public async Task MuxingJobTest()
        {
            File.Copy(MuxTestAudioFile, _sourceMuxTestAudioFile);
            File.Copy(MuxTestVideoFile, _sourceMuxTestVideoFile);
            Directory.CreateDirectory(_targetTestPath);

            MuxJobRequestModel request = new MuxJobRequestModel()
            {
                AudioSourceFilename = _sourceMuxTestAudioFile,
                VideoSourceFilename = _sourceMuxTestVideoFile,
                DestinationFilename = _targetFileMux,
                Inpoint             = "0",
                Needed       = DateTime.UtcNow,
                OutputFolder = _targetTestPath
            };

            var jobGuid = await _muxJobClient.CreateNewAsync(request);

            bool      done;
            int       maxCount = 240;
            Stopwatch sw       = new Stopwatch();

            Console.WriteLine($"Starting job {jobGuid}");
            sw.Start();
            FfmpegJobModel job;

            do
            {
                job = await _statusClient.GetAsync(jobGuid);

                var runningTask = job.Tasks.FirstOrDefault(t => t.State == FfmpegTaskModelState.InProgress);
                Console.WriteLine($"Jobstatus : {job.State}, time: {sw.ElapsedMilliseconds} ms, filename: {runningTask?.DestinationFilename}, {runningTask?.Progress:0.##} %");
                if (job.State == FfmpegJobModelState.Failed || job.State == FfmpegJobModelState.Canceled || job.State == FfmpegJobModelState.Unknown)
                {
                    throw new Exception($"Error running job. job state: {job.State}");
                }
                done = job.State == FfmpegJobModelState.Done;
                if (!done)
                {
                    Thread.Sleep(1000);
                }
            } while (!done && maxCount-- > 0);

            Assert.That(done, Is.True);
            Console.WriteLine($"Job done, time : {sw.ElapsedMilliseconds} ms ({maxCount})");
            sw.Stop();

            foreach (var target in job.Tasks)
            {
                string fileFullPath = Path.Combine(_targetTestPath, target.DestinationFilename);
                Console.WriteLine("Checking file: " + fileFullPath);
                Assert.That(File.Exists(fileFullPath), Is.True, $"Expected to find transcoded file @ {fileFullPath}");
            }
        }
Exemplo n.º 2
0
        public Guid PostMuxAudioJob(string audioFileFullPath, string videoFileFullPath, string outputFolder)
        {
            return(Retry(() =>
            {
                var task = _audioMuxClient.CreateNewAsync(new MuxJobRequestModel()
                {
                    DestinationFilename = System.IO.Path.GetFileName(videoFileFullPath),
                    Needed = DateTime.UtcNow,
                    OutputFolder = outputFolder,
                    Inpoint = "0",
                    AudioSourceFilename = audioFileFullPath,
                    VideoSourceFilename = videoFileFullPath
                });

                Task.WaitAll(task);
                return task.Result;
            }));
        }