示例#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;

                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;
            }));
        }
示例#2
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;
            }));
        }