Example #1
0
        public async Task ExtractAndAddAudio(string audioInputPath, string audioOutputPath,
                                             string inputPath, string outputPath, string tempDirectory, bool isMultiThread = false, bool trimVideo = false)
        {
            Console.WriteLine("Extracting Audio");
            if (!File.Exists(audioOutputPath))
            {
                await ExtractAudio(audioInputPath,
                                   audioOutputPath,
                                   (o, args) => { },
                                   isMultiThread
                                   );
            }

            var audio = await FFmpeg.GetMediaInfo(audioOutputPath);

            var inputVideo = await FFmpeg.GetMediaInfo(inputPath);

            if (trimVideo && TimeSpan.Compare(audio.Duration, inputVideo.Duration) == -1)
            {
                // Split Video

                Console.WriteLine("Splitting Video");
                var tempOutput = AppDomainHelpers
                                 .GetPath(tempDirectory,
                                          $"temp_split_video_output_{Guid.NewGuid().ToString().Replace("-", "")}",
                                          ".mp4");

                var split = await FFmpeg.Conversions.FromSnippet.Split(inputPath, tempOutput, TimeSpan.Zero,
                                                                       audio.Duration);

                split.UseMultiThread(isMultiThread);
                await split.Start();

                File.Move(tempOutput, inputPath, true);
            }

            Console.WriteLine("Adding Audio");
            await AddAudio(inputPath,
                           audioOutputPath,
                           outputPath,
                           (o, args) => { },
                           isMultiThread
                           );
        }
Example #2
0
        public async Task StartAsync()
        {
            if (!_isDownloadWebcamVideo && !_isDownloadPresentation)
            {
                throw new Exception("Either Presentaton or Desk-share Video Must Be Selected");
            }

            if (!Directory.Exists(_outputDirectory))
            {
                Directory.CreateDirectory(_outputDirectory);
            }

            Directory.SetCurrentDirectory(_outputDirectory);

            bool downloadVideoResponse        = false,
                 downloadPresentationResponse = false,
                 hasAudio = false;

            _webDriver = WebDriverFactory.Create(_webDriverType, _url);


            _bigBlueButtonDocumentParser = new BigBlueButtonDocumentParser(_webDriver, Options);

            var deskShareVideoName  = $"{_outputFileName}-desk";
            var webcamVideoName     = $"{_outputFileName}-webcam";
            var audioOutputName     = $"{_outputFileName}-output";
            var presentationName    = $"{_outputFileName}-presentation";
            var tmpPresentationName = $"{_outputFileName}-tmp";

            var downloadDeskShareThread = new Thread(() =>
            {
                if (_isDownloadDeskShareVideo)
                {
                    var response          = DownloadVideo(deskShareVideoName).GetAwaiter().GetResult();
                    downloadVideoResponse = response.IsSuccess;
                }
            });

            var downloadWebcamThread = new Thread(() =>
            {
                if (_isDownloadWebcamVideo)
                {
                    var response = DownloadWebcam(webcamVideoName).GetAwaiter().GetResult();
                    hasAudio     = response.IsSuccess;
                }
            });

            var downloadPresentationThread = new Thread(() =>
            {
                if (_isDownloadPresentation)
                {
                    var response = DownloadPresentation(tmpPresentationName).GetAwaiter().GetResult();
                    downloadPresentationResponse = response.IsSuccess;
                }
            });


            downloadDeskShareThread.Start();
            downloadWebcamThread.Start();
            downloadPresentationThread.Start();

            downloadWebcamThread.Join();
            downloadDeskShareThread.Join();
            downloadPresentationThread.Join();


            if (!downloadVideoResponse && !downloadPresentationResponse)
            {
                throw new BigBlueButtonDocumentException("Neither Video Nor Presentation Couldn't Be Downloaded.");
            }


            var audioInputPath         = AppDomainHelpers.GetPath(_outputDirectory, webcamVideoName, ".mp4");
            var audioOutputPath        = AppDomainHelpers.GetPath(_outputDirectory, $"{audioOutputName}", ".mp3");
            var deskShareInputPath     = AppDomainHelpers.GetPath(_outputDirectory, $"{deskShareVideoName}", ".mp4");
            var videoOutputPath        = AppDomainHelpers.GetPath(_outputDirectory, _outputFileName, ".mp4");
            var presentationOutputPath = AppDomainHelpers.GetPath(_outputDirectory, presentationName, ".mp4");
            var tmpPresentationPath    = AppDomainHelpers.GetPath(_outputDirectory, tmpPresentationName, ".mp4");

            if (downloadVideoResponse)
            {
                if (hasAudio)
                {
                    await _videoService.ExtractAndAddAudio(audioInputPath, audioOutputPath, deskShareInputPath,
                                                           videoOutputPath, _outputDirectory, _isUseMultiThread, true);
                }
                else
                {
                    File.Move(deskShareInputPath, videoOutputPath, true);
                }
            }

            if (downloadPresentationResponse)
            {
                if (hasAudio)
                {
                    await _videoService.ExtractAndAddAudio(audioInputPath, audioOutputPath, tmpPresentationPath,
                                                           presentationOutputPath, _outputDirectory, _isUseMultiThread, true);
                }
                else
                {
                    File.Move(tmpPresentationPath, presentationOutputPath, true);
                }
            }


            RemoveTempFiles(
                audioOutputName,
                deskShareVideoName,
                tmpPresentationName
                );
            _webDriver.Quit();
        }
 public static void DeleteFileInAppDirectory(string directory, string fileName, string fileExtension)
 {
     DeleteIfExists(AppDomainHelpers.GetPath(directory, fileName, fileExtension));
 }