Ejemplo n.º 1
0
        /// <summary>
        /// 加载设备列表
        /// </summary>
        private void LoadDeviceList()
        {
            rife = new RIFE();
            int           n  = 0;
            List <string> gl = rife.GetAvailableGPU();
            bool          cb = false;

            foreach (string s in gl)
            {
                if (s != null)
                {
                    if (s.IndexOf("Traceback") != -1)
                    {
                        cb = true;
                    }
                }
            }
            if (cb)
            {
                gl.Clear();
            }
            else
            {
                foreach (string s in gl)
                {
                    if (s != null)
                    {
                        p1.com_devices.Items.Add($"{n} {s}");
                        n += 1;
                    }
                }
            }

            /*foreach (string s in gl)
             * {
             *  if (s != null)
             *  {
             *      com_devices.Items.Add($"{n} {s}");
             *      n += 1;
             *  }
             * }*/
            List <string> cl = rife.GetAvailableCPU();

            //设置设备选择列表的默认项
            p1.com_devices.Items.Add($"-1 {cl[0]}");
            if (gl.Count == 0)
            {
                p1.com_devices.Text = $"-1 {cl[0]}";
            }
            else
            {
                p1.com_devices.Text = $"0 {gl[0]}";
            }
        }
Ejemplo n.º 2
0
        } = false;                                                    //是否完成了补帧

        public void Interpolate()
        {
            if (!Directory.Exists(Interpolated_Frames) && !Output_only_final)
            {
                Directory.CreateDirectory(Interpolated_Frames);
            }
            r = new RIFE();
            if (mode == InterpolationMode.pro)
            {
                Json_File = Output_Path + "\\tasks.json";
                Need_File = Output_Path + "\\need.txt";

                WriteLine(prefix + "创建补帧队列", msgtype.warning);
                List <string> Files = new List <string>();
                foreach (string s in Directory.EnumerateFiles(Origin_frames, "*", SearchOption.TopDirectoryOnly))
                {
                    Files.Add(s);
                }
                Files.Sort();
                List <int[]> IndexList = new List <int[]>();
                for (var i = 0; i < Files.Count - 1; i++)
                {
                    var    s0  = int.Parse(Files[i].Substring(Files[i].LastIndexOf(@"\") + 1, 9));
                    var    s1  = int.Parse(Files[i + 1].Substring(Files[i].LastIndexOf(@"\") + 1, 9));
                    var    exp = 1;
                    string bs  = "000000000";
                    if ((s1 - s0) > 1)
                    {
                        if (s1 - s0 - 1 == 1)
                        {
                            exp = 1;
                        }
                        else
                        {
                            //计算exp
                            do
                            {
                                exp += 1;
                                //MessageBox.Show($"num:{Math.Pow(2, exp) - 2} exp:{exp} need:{need}");
                            } while (Math.Pow(2, exp) - 2 < (s1 - s0 - 1));
                        }
                        if (s1 - s0 - 1 > Value_static_frame)
                        {
                            //当重复帧多余Value_static_frame时识别为刻意静止,采用帧复制
                            WriteLine(prefix + $"skip {Files[i]}...", msgtype.warning);
                            for (int po = s0 + 1; po != s1; po++)
                            {
                                try { File.Copy(Files[i], $"{Files[i].Substring(0, Files[i].LastIndexOf(@"\"))}\\{bs.Substring(0, bs.Length - po.ToString().Length)}{po}.png"); } catch { }
                            }
                        }
                        else
                        {
                            IndexList.Add(new int[] { i, i + 1, exp, (s1 - s0 - 1) });
                        }
                    }
                }
                WriteLine(prefix + "创建JSON文件记录", msgtype.warning);
                //创建JSON记录文件
                string          sn = "";
                JsonMaker       j  = new JsonMaker();
                List <JsonItem> l  = new List <JsonItem>();
                int             n  = 0;
                //记录同时将图片对复制到临时目录
                foreach (int[] i in IndexList)
                {
                    n += 1;
                    Directory.CreateDirectory($"{Temp_Dir}\\{n}");
                    l.Add(new JsonItem($"{Temp_Dir}\\{n}".Replace("\\", "/"), i[2], i[3].ToString()));
                    string s0 = Files[i[0]];
                    string s1 = Files[i[1]];
                    File.Copy(s0, $"{Temp_Dir}\\{n}\\000000001.png", true);
                    File.Copy(s1, $"{Temp_Dir}\\{n}\\000000002.png", true);
                    WriteLine(prefix + $"{n}/{IndexList.Count}", msgtype.info);
                    sn += $"{Temp_Dir}\\{n}?{i[3]}\r\n";
                }
                j.Make(Json_File, l);
                File.WriteAllText(Need_File, sn);
                if (!Directory.Exists(Temp_Dir1))
                {
                    Directory.CreateDirectory(Temp_Dir1);
                }
                WriteLine(prefix + "第一轮补帧", msgtype.warning);
                r.JsonInterpolate(vector, Json_File, Temp_Dir1, gpu_id, OpenUHD, batchsize, (s, se) =>
                {
                    if (se.Data != null)
                    {
                        WriteLine(prefix + se.Data, msgtype.info);
                    }
                }, (c, xe) =>
                {
                    WriteLine(prefix + "移动文件", msgtype.warning);
                    Dictionary <string, double> npairs = new Dictionary <string, double>();
                    n = 0;
                    foreach (string s in File.ReadLines(Need_File))
                    {
                        string[] p = s.Split('?');
                        npairs.Add(p[0], double.Parse(p[1]));
                        n += 1;
                    }
                    int iw = 0;
                    List <string> files = new List <string>();
                    while (iw != n)
                    {
                        iw += 1;
                        foreach (string s in Directory.EnumerateFiles($"{Temp_Dir}\\{iw}", "*.png", SearchOption.TopDirectoryOnly))
                        {
                            files.Add(s);
                        }
                    }
                    double max   = 0;
                    double start = 1;
                    foreach (string s in Directory.EnumerateFiles(Origin_frames, "*", SearchOption.AllDirectories))
                    {
                        double d = double.Parse(s.Substring(s.LastIndexOf("\\") + 1, 9));
                        if (d > max)
                        {
                            max = d;
                        }
                    }
                    int get = 0;
                    for (double i = start; i < max; i++)
                    {
                        string file = Origin_frames + "\\000000000".Substring(0, 10 - i.ToString().Length) + i.ToString() + ".png";
                        if (!File.Exists(file))
                        {
                            File.Move(files[get], file);
                            Console.WriteLine(prefix + $"{i}/{max} {files[get]}", msgtype.info);
                            get += 1;
                        }
                    }
                    WriteLine(prefix + "第二轮补帧", msgtype.warning);
                    var exp = 0;
                    if (times == Times.two)
                    {
                        exp = 1;
                    }
                    if (times == Times.four)
                    {
                        exp = 2;
                    }
                    if (times == Times.Eight)
                    {
                        exp = 3;
                    }
                    if (times == Times.Sixteen)
                    {
                        exp = 4;
                    }
                    if (Output_Audio && finish_audio_exc)
                    {
                        if (Output_only_final)
                        {
                            r.Interpolate(Output_only_final, vector, Origin_frames, Video_File, gpu_id, OpenUHD, exp, Value_scene, Audio_File, InterpolatedFps, Output_fps, CRFValue, batchsize, (sl, se) => {
                                if (se.Data != null)
                                {
                                    WriteLine(prefix + se.Data, msgtype.info);
                                }
                            }, (sl, se) => {
                                WriteLine(prefix + "补帧完成", msgtype.pass);
                                finish_interpolate = true;
                            });
                        }
                        else
                        {
                            r.Interpolate(Output_only_final, vector, Origin_frames, Interpolated_Frames, gpu_id, OpenUHD, exp, Value_scene, Audio_File, InterpolatedFps, Output_fps, CRFValue, batchsize, (sl, se) => {
                                if (se.Data != null)
                                {
                                    WriteLine(prefix + se.Data, msgtype.info);
                                }
                            }, (sl, se) => {
                                WriteLine(prefix + "补帧完成", msgtype.pass);
                                finish_interpolate = true;
                            });
                        }
                    }
                    else
                    {
                        if (Output_only_final)
                        {
                            r.Interpolate(Output_only_final, vector, Origin_frames, Video_File, gpu_id, OpenUHD, exp, Value_scene, "", InterpolatedFps, Output_fps, CRFValue, batchsize, (sl, se) => {
                                if (se.Data != null)
                                {
                                    WriteLine(prefix + se.Data, msgtype.info);
                                }
                            }, (sl, se) => {
                                WriteLine(prefix + "补帧完成", msgtype.pass);
                                finish_interpolate = true;
                            });
                        }
                        else
                        {
                            r.Interpolate(Output_only_final, vector, Origin_frames, Interpolated_Frames, gpu_id, OpenUHD, exp, Value_scene, "", InterpolatedFps, Output_fps, CRFValue, batchsize, (sl, se) => {
                                if (se.Data != null)
                                {
                                    WriteLine(prefix + se.Data, msgtype.info);
                                }
                            }, (sl, se) => {
                                WriteLine(prefix + "补帧完成", msgtype.pass);
                                finish_interpolate = true;
                            });
                        }
                    }
                });
            }
            else
            {
                var exp = 0;
                if (times == Times.two)
                {
                    exp = 1;
                }
                if (times == Times.four)
                {
                    exp = 2;
                }
                if (times == Times.Eight)
                {
                    exp = 3;
                }
                if (times == Times.Sixteen)
                {
                    exp = 4;
                }
                if (Output_Audio && finish_audio_exc)
                {
                    if (Output_only_final)
                    {
                        r.Interpolate(Output_only_final, vector, Origin_frames, Video_File, gpu_id, OpenUHD, exp, Value_scene, Audio_File, InterpolatedFps, Output_fps, CRFValue, batchsize, (sl, se) => {
                            if (se.Data != null)
                            {
                                WriteLine(prefix + se.Data, msgtype.info);
                            }
                        }, (sl, se) => {
                            WriteLine(prefix + "补帧完成", msgtype.pass);
                            finish_interpolate = true;
                        });
                    }
                    else
                    {
                        r.Interpolate(Output_only_final, vector, Origin_frames, Interpolated_Frames, gpu_id, OpenUHD, exp, Value_scene, Audio_File, InterpolatedFps, Output_fps, CRFValue, batchsize, (sl, se) => {
                            if (se.Data != null)
                            {
                                WriteLine(prefix + se.Data, msgtype.info);
                            }
                        }, (sl, se) => {
                            WriteLine(prefix + "补帧完成", msgtype.pass);
                            finish_interpolate = true;
                        });
                    }
                }
                else
                {
                    if (Output_only_final)
                    {
                        r.Interpolate(Output_only_final, vector, Origin_frames, Video_File, gpu_id, OpenUHD, exp, Value_scene, "", InterpolatedFps, Output_fps, CRFValue, batchsize, (sl, se) => {
                            if (se.Data != null)
                            {
                                WriteLine(prefix + se.Data, msgtype.info);
                            }
                        }, (sl, se) => {
                            WriteLine(prefix + "补帧完成", msgtype.pass);
                            finish_interpolate = true;
                        });
                    }
                    else
                    {
                        r.Interpolate(Output_only_final, vector, Origin_frames, Interpolated_Frames, gpu_id, OpenUHD, exp, Value_scene, "", InterpolatedFps, Output_fps, CRFValue, batchsize, (sl, se) => {
                            if (se.Data != null)
                            {
                                WriteLine(prefix + se.Data, msgtype.info);
                            }
                        }, (sl, se) => {
                            WriteLine(prefix + "补帧完成", msgtype.pass);
                            finish_interpolate = true;
                        });
                    }
                }
            }
        }