Beispiel #1
0
        public async Task <bool> BeginGenGif(object o)
        {
            return(await Task.Run(() => {
                object[] list = o as object[];
                string cutoffTime = list[0] as string;
                string filePath = list[1] as string;
                string GifPath = list[2] as string;

                if (string.IsNullOrEmpty(cutoffTime))
                {
                    return false;
                }
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;       //是否使用操作系统shell启动
                p.StartInfo.RedirectStandardInput = true;  //接受来自调用程序的输入信息
                p.StartInfo.RedirectStandardOutput = true; //由调用程序获取输出信息
                p.StartInfo.RedirectStandardError = true;  //重定向标准错误输出
                p.StartInfo.CreateNoWindow = true;         //不显示程序窗口
                p.Start();                                 //启动程序

                string str = $"\"{Properties.Settings.Default.FFMPEG_Path}\" -y -t 5 -ss {cutoffTime} -i \"{filePath}\" -s 280x170  \"{GifPath}\"";
                Console.WriteLine(str);


                p.StandardInput.WriteLine(str + "&exit");
                p.StandardInput.AutoFlush = true;
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();//等待程序执行完退出进程
                p.Close();
                SingleScreenShotCompleted?.Invoke(this, new ScreenShotEventArgs(str, GifPath));
                return true;
            }));
        }
Beispiel #2
0
        public async Task <bool> BeginGenGif(object o)
        {
            return(await Task.Run(() => {
                object[] list = o as object[];
                string cutoffTime = list[0] as string;
                string filePath = list[1] as string;
                string GifPath = list[2] as string;

                int duration = Properties.Settings.Default.Gif_Duration;

                int width = Properties.Settings.Default.Gif_Width;
                int height = Properties.Settings.Default.Gif_Height;
                if (Properties.Settings.Default.Gif_AutoHeight)
                {
                    (double w, double h) = MediaParse.GetWidthHeight(filePath);
                    if (w != 0)
                    {
                        height = (int)(h / w * (double)width);
                    }
                }



                if (width <= 0 || width > 1980)
                {
                    width = 280;
                }
                if (height <= 0 || height > 1080)
                {
                    height = 170;
                }

                if (string.IsNullOrEmpty(cutoffTime))
                {
                    return false;
                }
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;       //是否使用操作系统shell启动
                p.StartInfo.RedirectStandardInput = true;  //接受来自调用程序的输入信息
                p.StartInfo.RedirectStandardOutput = true; //由调用程序获取输出信息
                p.StartInfo.RedirectStandardError = true;  //重定向标准错误输出
                p.StartInfo.CreateNoWindow = true;         //不显示程序窗口
                p.Start();                                 //启动程序

                string str = $"\"{Properties.Settings.Default.FFMPEG_Path}\" -y -t {duration} -ss {cutoffTime} -i \"{filePath}\" -s {width}x{height}  \"{GifPath}\"";
                Console.WriteLine(str);


                p.StandardInput.WriteLine(str + "&exit");
                p.StandardInput.AutoFlush = true;
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();//等待程序执行完退出进程
                p.Close();
                SingleScreenShotCompleted?.Invoke(this, new ScreenShotEventArgs(str, GifPath));
                return true;
            }));
        }
Beispiel #3
0
        public void BeginScreenShot(object o)
        {
            List <object> list           = o as List <object>;
            string        cutoffTime     = list[0] as string;
            string        i              = list[1] as string;
            string        filePath       = list[2] as string;
            string        ScreenShotPath = list[3] as string;
            string        output         = $"{ScreenShotPath}\\ScreenShot-{i.PadLeft(2, '0')}.jpg";

            if (string.IsNullOrEmpty(cutoffTime))
            {
                return;
            }
            SemaphoreScreenShot.WaitOne();

            //--使用 ffmpeg.exe 截图
            Process          process   = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            startInfo.FileName       = Properties.Settings.Default.FFMPEG_Path;
            startInfo.CreateNoWindow = true;
            string str = $"-y -threads 1 -ss {cutoffTime} -i \"{filePath}\" -f image2 -frames:v 1 \"{output}\"";

            startInfo.UseShellExecute        = false;
            startInfo.Arguments              = str;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            process.StartInfo = startInfo;
            process.Start();
            StreamReader readerOut = process.StandardOutput;
            StreamReader readerErr = process.StandardError;
            string       errors    = readerErr.ReadToEnd();
            string       output2   = readerOut.ReadToEnd();

            while (!process.HasExited)
            {
                continue;
            }
            //--使用 ffmpeg.exe 截图
            SemaphoreScreenShot.Release();
            SingleScreenShotCompleted?.Invoke(this, new ScreenShotEventArgs(str, output));
            //App.Current.Dispatcher.Invoke((Action)delegate { cmdTextBox.AppendText(str + "\n"); cmdTextBox.ScrollToEnd(); });
            lock (ScreenShotLockObject) { ScreenShotCurrent += 1; }
        }
Beispiel #4
0
        public async Task <bool> BeginGenGif(object o)
        {
            return(await Task.Run(async() =>
            {
                object[] list = o as object[];
                string cutoffTime = list[0] as string;
                string filePath = list[1] as string;
                string GifPath = list[2] as string;

                int duration = Properties.Settings.Default.Gif_Duration;

                int width = Properties.Settings.Default.Gif_Width;
                int height = Properties.Settings.Default.Gif_Height;
                if (Properties.Settings.Default.Gif_AutoHeight)
                {
                    (double w, double h) = MediaParse.GetWidthHeight(filePath);
                    if (w != 0)
                    {
                        height = (int)(h / w * (double)width);
                    }
                }



                if (width <= 0 || width > 1980)
                {
                    width = 280;
                }
                if (height <= 0 || height > 1080)
                {
                    height = 170;
                }

                if (string.IsNullOrEmpty(cutoffTime))
                {
                    return false;
                }
                string str = $"\"{Properties.Settings.Default.FFMPEG_Path}\" -y -t {duration} -ss {cutoffTime} -i \"{filePath}\" -s {width}x{height}  \"{GifPath}\"";
                string error = await new FFmpegHelper(str, duration * 5).Run();
                SingleScreenShotCompleted?.Invoke(this, new ScreenShotEventArgs(str, GifPath, error));
                return true;
            }));
        }
Beispiel #5
0
        public async void BeginScreenShot(object o)
        {
            List <object> list           = o as List <object>;
            string        cutoffTime     = list[0] as string;
            string        i              = list[1] as string;
            string        filePath       = list[2] as string;
            string        ScreenShotPath = list[3] as string;
            string        output         = $"{ScreenShotPath}\\ScreenShot-{i.PadLeft(2, '0')}.jpg";

            if (string.IsNullOrEmpty(cutoffTime))
            {
                return;
            }
            SemaphoreScreenShot.WaitOne();

            string str   = $"\"{Properties.Settings.Default.FFMPEG_Path}\" -y -threads 1 -ss {cutoffTime} -i \"{filePath}\" -f image2 -frames:v 1 \"{output}\"";
            string error = await new FFmpegHelper(str).Run();

            SemaphoreScreenShot.Release();
            SingleScreenShotCompleted?.Invoke(this, new ScreenShotEventArgs(str, output, error));
            lock (ScreenShotLockObject) { ScreenShotCurrent += 1; }
        }