Пример #1
0
    public void StopVideo(CamVideo cv)
    {
        // stop getting video data
        cv.done = true;

        //save video
    }
Пример #2
0
    public void TakeVideo(FaceManager fm, UnityEngine.UI.Image checkImg, RectTransform full)
    {
        view.transform.GetChild(0).gameObject.SetActive(false);

        fm.setUpDelegates();
        fm.ChangeLook();

        CamVideo cv = Camera.main.gameObject.AddComponent <CamVideo>();
        Image    i  = createVidJuice(checkImg);

        cv.init(view.rectTransform, full, (int save) =>
        {
            int w = cv.w;
            int h = cv.h;
            l.Init(false);
            if (save > 0)
            {
                StartCoroutine(saveT(cv, w, h));
            }
            fm.removeAll();
            Destroy(i.gameObject);
            check.interactable = false;
            check.onClick.RemoveAllListeners();
            check.onClick.AddListener(() => TakeVideo(fm, checkImg, full));
            checkImg.sprite = Resources.Load <Sprite>("play");

            //  Directory.Delete(m_FilePath, true); // NativeGallery.GetSavePath(persis, "", "LPM{0}.gif")
        }, i);
        // StartCoroutine(gettingVideo(cv));
        OnlySeeCheckButton();

        check.onClick.RemoveAllListeners();
        check.onClick.AddListener(() => StopVideo(cv));
        checkImg.sprite = Resources.Load <Sprite>("stop");
    }
Пример #3
0
    IEnumerator saveT(CamVideo cv, int w, int h)
    {
        Queue <byte[]> frameQueue        = cv.frameQueue;
        int            savingFrameNumber = cv.savingFrameNumber;

        while (frameQueue.Count > 0)
        {
            // Generate file path
            string path = persis + "/frame" + savingFrameNumber + ".raw";
            File.WriteAllBytes(path, frameQueue.Dequeue());
            savingFrameNumber++;
        }
        Destroy(cv);
        List <Frame> frames = new List <Frame>();
        Texture2D    temp   = new Texture2D(w, h, TextureFormat.RGB24, false);

        temp.hideFlags  = HideFlags.HideAndDontSave;
        temp.wrapMode   = TextureWrapMode.Clamp;
        temp.filterMode = FilterMode.Bilinear;
        temp.anisoLevel = 0;
        for (int i = 0; i < savingFrameNumber; i++)
        {
            string BMPpath = persis + "/RECORDING_LPM" + "/frame" + i + ".raw";

            if (File.Exists(BMPpath))
            {
                temp.LoadRawTextureData(File.ReadAllBytes(BMPpath));
                Color32[] colors = temp.GetPixels32();
                yield return(null);

                Frame frame = new Frame()
                {
                    Width = w, Height = h, Data = colors
                };
                frames.Add(frame);
            }
            else
            {
                break;
            }
        }
        Flush(temp);
        yield return(null);

        l.updateThis(() =>
        {
            Directory.Delete(persis + "/RECORDING_LPM", true);
            SeeEverything();
            check.interactable = true;
            view.transform.GetChild(0).gameObject.SetActive(true);
            Application.targetFrameRate = 24;
        });
        ProGifEncoder encoder = new ProGifEncoder(0, 5);

        encoder.SetDelay(70);

        StartCoroutine(SaveVidFile());

        ThreadPriority WorkerPriority = ThreadPriority.BelowNormal;
        // GetSavePath(string saveDir, string album, string filenameFormatted)
        string name_ = new FilePathName().GetGifFileName();

        ProGifWorker worker = new ProGifWorker(WorkerPriority)
        {
            m_Encoder            = encoder,
            m_Frames             = frames,
            persisT              = persis,
            m_FilePath           = Application.persistentDataPath + "/" + name_ + ".gif",
            m_OnFileSaved        = Saved,
            m_OnFileSaveProgress = l.setProgress,
        };

        worker.Start();
        //  _thread.Start();
    }