Beispiel #1
0
        public void When_UpdateVideoAdapterSettings_is_mapped_to_a_VideoAdapterSettings_and_the_SetName_is_null_then_all_fields_are_mapped_correctly_and_SetName_in_the_result_is_null()
        {
            const string fullName = "FullName";
            const string userName = "******";
            const string userId   = "UserId";

            var entity = AdapterSettingsCreator.CreateSingle();

            VideoProcess
            .Expect(process =>
                    process.GetAdapterSettings())
            .Return(entity)
            .Repeat.Once();
            VideoProcess.Replay();

            var updateModel = new UpdateVideoAdapterSettingsModel
            {
                FullName = fullName,
                UserName = userName,
                UserId   = userId,
                SetName  = null,
            };

            var result = Mapper.Map(updateModel);

            Assert.AreEqual(null, result.SetName);
            Assert.AreNotEqual(fullName, result.OAuthAccessToken.FullName);
            Assert.AreNotEqual(userName, result.OAuthAccessToken.Username);
            Assert.AreNotEqual(userId, result.OAuthAccessToken.UserId);

            VideoProcess.VerifyAllExpectations();
        }
Beispiel #2
0
        public void When_Edit_is_called_with_an_Id_then_GetVideoAdapterSettings_on_IVideoAdapterSettingsProcess_is_called_and_the_result_is_mapped_with_VideoAdapterSettingsMapper()
        {
            var adapterSettings = AdapterSettingsCreator.CreateSingle();

            VideoProcess
            .Expect(process =>
                    process.GetAdapterSettings())
            .Return(adapterSettings)
            .Repeat.Once();
            VideoProcess.Replay();

            var updateModel = CreateUpdateVideoAdapterSettingsModel(Guid.NewGuid());

            VideoAdapterSettingsMapper
            .Expect(mapper =>
                    mapper.MapToUpdate(
                        Arg <AdapterSettings> .Matches(settings => settings.Id == adapterSettings.Id)))
            .Return(updateModel)
            .Repeat.Once();
            VideoAdapterSettingsMapper.Replay();

            var result = Controller.Edit().Result as ViewResult;

            Assert.IsNotNull(result);

            var model = result.Model as UpdateVideoAdapterSettingsModel;

            Assert.IsNotNull(model);

            VideoProcess.VerifyAllExpectations();
            VideoAdapterSettingsMapper.VerifyAllExpectations();
        }
Beispiel #3
0
        /// <summary>
        /// 开始直播(服务端开始推流)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartLiveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (toolStripComboBox1.ComboBox != null)
                {
                    string camera = toolStripComboBox1.ComboBox.SelectedText;
                    if (string.IsNullOrEmpty(camera))
                    {
                        MessageBox.Show("请选择要使用的相机");
                        return;
                    }
                    var path    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Icon");
                    var imgPath = Path.Combine(path + "\\", "stop.jpg");
                    StartLiveToolStripMenuItem.Enabled = false;

                    StartLiveToolStripMenuItem.Image = Image.FromFile(imgPath);
                    string args = $" -f dshow -re -i  video=\"{camera}\" -tune zerolatency -vcodec libx264 -preset ultrafast -b:v 400k -s 704x576 -r 25 -acodec aac -b:a 64k -f flv \"rtmp://127.0.0.1:20050/myapp/test\"";
                    VideoProcess.Run(args);
                }

                StartLiveToolStripMenuItem.Text = "正在直播";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        protected override void AdditionalSetup()
        {
            base.AdditionalSetup();

            VideoAdapter = MockHelper.CreateAndRegisterMock <IVideoAdapter>();
            Process      = new VideoProcess(CatalogsContainer);
        }
        protected override void AdditionalSetup()
        {
            base.AdditionalSetup();

            VideoAdapter = MockHelper.CreateAndRegisterMock<IVideoAdapter>();
            Process = new VideoProcess(CatalogsContainer);
        }
        public async Task <IActionResult> Post([FromBody] VideoProcess body)
        {
            var videoProcessing = new VideoProcessing(_webHostEnvironment);

            videoProcessing.SplitVideoIntoFrames(body.ImageName);

            Hashtable result = new Hashtable();

            result.Add("imageId", Path.GetFileNameWithoutExtension(body.ImageName));
            return(Json(result));
        }
Beispiel #7
0
        private void LiveRecordStripMenuItem_Click(object sender, EventArgs e)
        {
            var path = FileHelper.VideoRecordPath();

            if (string.IsNullOrEmpty(path))
            {
                MessageBox.Show("视频存放文件路径为空");
            }
            var args = $" -f dshow -re -i  video=\"Integrated Webcam\" -tune zerolatency -vcodec libx264 -preset ultrafast -b:v 400k -s 704x576 -r 25 -acodec aac -b:a 64k -f flv \"rtmp://127.0.0.1:20050/myapp/test\" -map 0 {path}";

            VideoProcess.Run(args);
            StartLiveToolStripMenuItem.Text = "正在直播";
        }
Beispiel #8
0
        private void DesktopRecordStripMenuItem_Click(object sender, EventArgs e)
        {
            var path = FileHelper.VideoRecordPath();

            if (string.IsNullOrEmpty(path))
            {
                MessageBox.Show("视频存放文件路径为空");
            }
            string args = $"ffmpeg -f gdigrab -r 24 -offset_x 0 -offset_y 0 -video_size 1920x1080 -i desktop -f dshow -list_devices 0 -i video=\"Integrated Webcam\":audio=\"麦克风(Realtek Audio)\" -filter_complex \"[0:v] scale = 1920x1080[desktop];[1:v] scale = 192x108[webcam];[desktop][webcam] overlay = x = W - w - 50:y = H - h - 50\" -f flv \"rtmp://127.0.0.1:20050/myapp/test\" -map 0 {path}";

            VideoProcess.Run(args);
            StartLiveToolStripMenuItem.Text = "正在直播";
        }
        public async Task VideoProcessing_WhenVideoExists_ShouldReturn200()
        {
            // Arrange
            _fixture.FakeUploadVideo();
            var body = new VideoProcess()
            {
                ImageName = _fixture.VideoFileName
            };

            // Act
            var result =
                await _fixture.Client.PostAsJsonAsync(new Uri($"/api/processing/", UriKind.RelativeOrAbsolute), body);

            // Assert
            result.StatusCode.ShouldBe(HttpStatusCode.OK);
        }
Beispiel #10
0
        public void When_Edit_is_called_with_a_model_then_Map_on_VideoAdapterSettingsMapper_is_called_and_the_result_is_used_to_call_UpdateVideoAdapterSettings_on_IVideoAdapterSettingsProcess_with()
        {
            var adapterSettings = AdapterSettingsCreator.CreateSingle();

            VideoProcess
            .Expect(process =>
                    process.UpdateAdapterSettings(
                        Arg <AdapterSettings> .Matches(settings =>
                                                       settings.Id == adapterSettings.Id)))
            .Return(adapterSettings)
            .Repeat.Once();
            VideoProcess.Replay();

            var updateModel = CreateUpdateVideoAdapterSettingsModel(adapterSettings.Id);

            VideoAdapterSettingsMapper
            .Expect(mapper =>
                    mapper.Map(
                        Arg <UpdateVideoAdapterSettingsModel> .Matches(m => m.SetName == adapterSettings.SetName)))
            .Return(adapterSettings)
            .Repeat.Once();
            VideoAdapterSettingsMapper.Replay();

            var result = Controller.Edit(updateModel).Result as RedirectToRouteResult;

            Assert.IsNotNull(result);

            var routeValues = result.RouteValues;

            Assert.AreEqual(1, routeValues.Count);

            foreach (var routeValue in routeValues)
            {
                Assert.AreEqual("action", routeValue.Key);
                Assert.AreEqual("Index", routeValue.Value);
            }

            VideoProcess.VerifyAllExpectations();
            VideoAdapterSettingsMapper.VerifyAllExpectations();
        }
Beispiel #11
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Log("\n\n## End ##");
            if (SaveToLog)
            {
                LogSw.Close();
            }

            if (DownloadingVideo)
            {
                VideoProcess.Kill();
            }
            else if (DownloadingPlaylist)
            {
                PlaylistProcess.Kill();
            }

            /*if (VideoProcess.Id != 0 && !VideoProcess.HasExited)
             *  VideoProcess.Kill();
             * else if (PlaylistProcess.Id != 0 && !PlaylistProcess.HasExited)
             *  PlaylistProcess.Kill();*/
        }
Beispiel #12
0
        void Execute(VideoProcess recoder)
        {
            //set process parameters
            currentProcess = new Process();
            currentProcess.StartInfo.Arguments = recoder.Command;
            currentProcess.StartInfo.FileName  = Config.Instance.FFMPEGPath;

            currentProcess.EnableRaisingEvents              = true;
            currentProcess.StartInfo.UseShellExecute        = false;
            currentProcess.StartInfo.CreateNoWindow         = true;
            currentProcess.StartInfo.RedirectStandardInput  = true;
            currentProcess.StartInfo.RedirectStandardOutput = true;
            currentProcess.StartInfo.RedirectStandardError  = true;

            currentProcess.Exited             += OnProcessExit;
            currentProcess.OutputDataReceived += new DataReceivedEventHandler(InterceptOutputAndUpdateUI);
            currentProcess.ErrorDataReceived  += new DataReceivedEventHandler(InterceptOutputAndUpdateUI);

            currentProcess.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(866);
            currentProcess.StartInfo.StandardErrorEncoding  = Encoding.GetEncoding(866);

            //set worker header label
            SetName(recoder.OutputPath.Split('\\')[recoder.OutputPath.Split('\\').Length - 1]);
            recodeLabels[processesFinished].Invoke((MethodInvoker)(() => recodeLabels[processesFinished].UpdateStatus(VideoProcessLabel.VideoRecodeStatus.InProgress)));

            //check if we want to overwrite output
            bool overWriteAllowed = false;

            if (System.IO.File.Exists(recoder.OutputPath))
            {
                overWriteAllowed = true;

                /*
                 * var dialogResult = MessageBox.Show($"File {recoder.OutputPath} already exists. Rewrite?", "Do it? or not?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                 *
                 * if (dialogResult == DialogResult.OK)
                 * {
                 *  overWriteAllowed = true;
                 * }
                 * else
                 * {
                 *  abortButton_Click(this, null);
                 *  //abortButton.Invoke((MethodInvoker)(() => abortButton.Text = "Close"));
                 *  this.Invoke((MethodInvoker)(() => Close()));
                 *  //Close();
                 *  return;
                 * }
                 */
            }


            string header = "+-----------------------------------------------------------------------------------------------------------------------------------+\n" +
                            "|-----------------------------------------------------------------------------------------------------------------------------------|\n" +
                            "|----------------Starting new ffmpeg.exe instance with parameters...------------------------------------|\n" +
                            "|-----------------------------------------------------------------------------------------------------------------------------------|\n" +
                            "+-----------------------------------------------------------------------------------------------------------------------------------+\n";

            string command = $"{recoder.Command}" + Environment.NewLine + Environment.NewLine;

            WriteLine(header, Color.Black, Color.White);
            WriteLine(command, Color.Lime);

            //* Start process and handlers
            currentProcess.Start();

            currentProcess.BeginOutputReadLine();
            currentProcess.BeginErrorReadLine();

            if (overWriteAllowed)
            {
                currentProcess.StandardInput.WriteLine("Y");
            }
        }
Beispiel #13
0
        private void DownloadVideos_Click(object sender, EventArgs e)
        {
            if (!CheckLibs(false))
            {
                return;
            }

            DownloadVideos.Enabled = false;
            DownloadVideos.Text    = "Descargando vídeo(s)...";
            Cursor.Current         = Cursors.WaitCursor;

            string[] Videos = VideosTextBox.Text.Split('\n');

            Log("\n\nDownloading " + Videos.Length + " videos from YouTube");

            DownloadProgressBar.Maximum = Videos.Length * 2;
            ProgressText.Text           = "1/" + Videos.Length;

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

            int    DownloadedVideos = 0;
            string Info             = "";
            bool   OpenDirAtEnd     = OpenAtEndCheckBox.Checked;

            try
            {
                InitializeProcess(VideoProcess);

                DownloadingVideo = true;

                for (int i = 0; i < Videos.Length; i++)
                {
                    Log("\nDownloading video " + i + "/" + Videos.Length + "...");
                    Info += (i + 1) + "/" + Videos.Length + ": ";

                    VideoProcess.StartInfo.Arguments = Videos[i] + " --get-title";
                    VideoProcess.Start();
                    VideoProcess.WaitForExit();

                    StreamReader sr    = VideoProcess.StandardOutput;
                    string       Title = sr.ReadLine();
                    sr.Close();

                    DownloadProgressBar.Value++;

                    if (Title == null)
                    {
                        Log("\n[ERROR] Video " + (i + 1) + "/" + Videos.Length + " was not found. URL: " + Videos[i]);
                        Info += "VÍDEO NO DISPONIBLE\n   URL: " + Videos[i];
                        DownloadProgressBar.Value++;
                        continue;
                    }

                    Log("\nVideo " + (i + 1) + "/" + Videos.Length + " was found! Title: " + Title + ", URL: " + Videos[i]);

                    if (!MP3CheckBox.Checked)
                    {
                        VideoProcess.StartInfo.Arguments = Videos[i] + " -f mp4 -o \"" + OutputPath + Title + ".mp4\"";
                    }
                    else
                    {
                        VideoProcess.StartInfo.Arguments = Videos[i] + " -x --audio-format mp3 -o \"" + OutputPath + Title + ".%(ext)s\"";
                    }
                    if (MetadataCheckBox.Checked)
                    {
                        VideoProcess.StartInfo.Arguments += " --add-metadata";
                    }

                    VideoProcess.Start();
                    VideoProcess.WaitForExit();

                    Log("\nVideo downloaded/converted successfully!");
                    Info += Title + "\n   URL: " + Videos[i] + "\n\n";

                    DownloadedVideos++;
                    DownloadProgressBar.Value++;
                    ProgressText.Text = (i + 1) + "/" + Videos.Length;
                }
                DownloadingVideo = false;

                Info = Info.Remove(Info.Length - 2, 2);

                Log("\nVideos downloaded " + ((MP3CheckBox.Checked) ? "and converted to .mp3 " : "") + "successfully: " + DownloadedVideos + "/" + Videos.Length + "\n");
                DownloadResultForm drm = new DownloadResultForm(Results.Info,
                                                                "Vídeos descargados con éxito: " + DownloadedVideos + "/" + Videos.Length,
                                                                DownloadTypes.Video,
                                                                null,
                                                                MP3CheckBox.Checked,
                                                                MetadataCheckBox.Checked,
                                                                Info);
            }
            catch (Exception ex)
            {
                DownloadingVideo = false;

                OpenDirAtEnd = false;

                Log("\n[ERROR] Error during download videos process:\n" + ex.Message + "\n");
                Info += "\n\n" + ex.ToString();

                DownloadResultForm drm = new DownloadResultForm(Results.Error,
                                                                "Error en la descarga de " + DownloadedVideos + "/" + Videos.Length + " vídeos",
                                                                DownloadTypes.Video,
                                                                null,
                                                                MP3CheckBox.Checked,
                                                                MetadataCheckBox.Checked,
                                                                Info);
            }
            Cursor.Current = Cursors.Default;

            DownloadVideos.Text       = "Descargar vídeo(s)";
            DownloadVideos.Enabled    = true;
            DownloadProgressBar.Value = 0;
            ProgressText.Text         = "--/--";

            if (OpenDirAtEnd)
            {
                Process.Start("explorer.exe", OutputPath);
            }
        }