public void EndRecording() { if (encoder != null) { encoder.Dispose(); encoder = null; } if (videoInput != null) { videoInput.EndRecording(); if (recorder.recordAudio) { audioInput.EndRecording(); } } Destroy(videoInput); Time.captureFramerate = 0; currentFrame = 0; isRecording = false; }
public void EndRecording() { if (encoder != null) { encoder.Dispose(); encoder = null; } if (commandBuffer != null) { _camera.RemoveCommandBuffer(CameraEvent.AfterEverything, commandBuffer); commandBuffer.Release(); commandBuffer = null; } if (renderBuffer != null) { renderBuffer.Release(); renderBuffer = null; } if (isRecording) { Debug.Log("VimeoRecorder: EndRecording()"); } isRecording = false; }
public void EndRecording() { if (encoder != null) { encoder.Dispose(); encoder = null; } if (videoInput != null) { videoInput.EndRecording(); Destroy(videoInput); } #if UNITY_2018_1_OR_NEWER if (audioInput != null) { if (recorder.recordAudio) { audioInput.EndRecording(); } Destroy(audioInput); } #endif Time.captureFramerate = 0; currentFrame = 0; isRecording = false; }
private IEnumerator StopRecord() { while (textures.Count > 0) { yield return(new WaitForEndOfFrame()); } Debug.Log("Fin record"); mediaEncoder.Dispose(); }
/// <summary> /// Resets state to become available for recording again. /// Removes framerate regulation /// </summary> public void EndRecording() { isActive = false; Time.captureFramerate = 0; #if UNITY_EDITOR && UNITY_2017_3_OR_NEWER if (encoder != null) { encoder.Dispose(); } #endif }
public override void EndRecording(RecordingSession session) { base.EndRecording(session); if (m_Encoder != null) { m_Encoder.Dispose(); m_Encoder = null; } // When adding a file to Unity's assets directory, trigger a refresh so it is detected. if (settings.fileNameGenerator.root == OutputPath.Root.AssetsFolder || settings.fileNameGenerator.root == OutputPath.Root.StreamingAssets) { AssetDatabase.Refresh(); } }
public override void EndRecording(RecordingSession session) { base.EndRecording(session); if (m_Encoder != null) { m_Encoder.Dispose(); m_Encoder = null; } // When adding a file to Unity's assets directory, trigger a refresh so it is detected. if (m_Settings.m_DestinationPath.root == OutputPath.ERoot.AssetsPath) { AssetDatabase.Refresh(); } }
/** * Stop the Camera and dispose the video file, to persist it onto the harddrive */ public void StopCamera() { recording = false; _mediaEncoder.Dispose(); if (_camAvailable) { _camAvailable = false; if (_frontCam.isPlaying) { _frontCam.Stop(); background.texture = _defaultBackground; } } Debug.Log("Letting go of camera"); }
protected override void DisposeEncoder() { base.DisposeEncoder(); if (m_Encoder == null) { return; } m_Encoder.Dispose(); m_Encoder = null; // When adding a file to Unity's assets directory, trigger a refresh so it is detected. if (settings.fileNameGenerator.root == OutputPath.Root.AssetsFolder || settings.fileNameGenerator.root == OutputPath.Root.StreamingAssets) { AssetDatabase.Refresh(); } }
IEnumerator CreateVideo(string path, List <byte[]> textureList, string chara, Text progressTxt) { progressTxt.gameObject.SetActive(true); VideoTrackAttributes videoAttributes = new VideoTrackAttributes { frameRate = new MediaRational(90), width = 320, height = 240, includeAlpha = false }; string filePath = Path.Combine(path, "eye_vid" + chara + ".mp4"); using (MediaEncoder encoder = new MediaEncoder(filePath, videoAttributes)) { for (int i = 0; i < textureList.Count; i++) { Texture2D tex = new Texture2D(320, 240, TextureFormat.RGBA32, false); tex.LoadImage(textureList[i]); Texture2D newTex = new Texture2D(320, 240, TextureFormat.RGBA32, false); newTex.SetPixels(tex.GetPixels()); newTex.Apply(); encoder.AddFrame(newTex); if (i % 100 == 0) { Resources.UnloadUnusedAssets(); System.GC.Collect(); } if (i % 10 == 0) { progressTxt.text = "Writing " + chara + " : " + System.Math.Round(((float)i / (float)textureList.Count) * 100, 2) + "%"; } yield return(new WaitForEndOfFrame()); } encoder.Dispose(); } Debug.Log("Finished!"); textureList.Clear(); Resources.UnloadUnusedAssets(); System.GC.Collect(); progressTxt.gameObject.SetActive(false); }
IEnumerator playVideo() { rend = GetComponent <MeshRenderer>(); videoPlayer = gameObject.AddComponent <VideoPlayer>(); audioSource = gameObject.AddComponent <AudioSource>(); //Disable Play on Awake for both Video and Audio videoPlayer.playOnAwake = false; audioSource.playOnAwake = false; videoPlayer.source = VideoSource.VideoClip; videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource; videoPlayer.EnableAudioTrack(0, true); videoPlayer.SetTargetAudioSource(0, audioSource); //Set video To Play then prepare Audio to prevent Buffering videoPlayer.clip = videoToPlay; videoPlayer.Prepare(); //Wait until video is prepared while (!videoPlayer.isPrepared) { yield return(null); } //Assign the Texture from Video to Material texture tex = videoPlayer.texture; rend.material.mainTexture = tex; videoPlayer.sendFrameReadyEvents = true; videoPlayer.frameReady += OnNewFrame; videoPlayer.Play(); audioSource.Play(); while (videoPlayer.isPlaying) { Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)videoPlayer.time)); Debug.Log("Playing Video"); yield return(null); } //while (texList.Count != (int)videoPlayer.frameCount) //{ //yield return null; //} //int i = 0; //foreach(Texture2D tex in texList) //{ // i++; // if(i > 447 && i < 765) // { // byte[] bytes; // bytes = tex.EncodeToPNG(); // string filePath = Application.dataPath + "/Resources/ConvertImages/"; // string fileName = filePath + i.ToString() + ".png"; // System.IO.File.WriteAllBytes(fileName, bytes); // AssetDatabase.ImportAsset(fileName); // yield return null; // } //} Debug.Log("Done Playing Video"); /////////////////////////////////////////// //// /// // 왜곡이미지 처리/// /////////////////////////////////////////// VideoTrackAttributes videoAttr = new VideoTrackAttributes { frameRate = new MediaRational((int)videoPlayer.frameRate), width = videoPlayer.width, height = videoPlayer.height, }; AudioTrackAttributes audioAttr = new AudioTrackAttributes { sampleRate = new MediaRational(48000), channelCount = 2, language = "fr" }; int sampleFramesPerVideoFrame = audioAttr.channelCount * audioAttr.sampleRate.numerator / videoAttr.frameRate.numerator; // 동영상 생성 경로 string encodedFilePath = Path.Combine(Application.dataPath + "/Resources/ConvertVideo", "my_movie.mp4"); MediaEncoder encoder = new MediaEncoder(encodedFilePath, videoAttr, audioAttr); for (int i = 0; i < texList.Count; ++i) { Debug.Log("Encoding tex num " + (i + 1) + " / " + texList.Count); encoder.AddFrame(texList[i]); yield return(null); } encoder.Dispose(); Debug.Log("Convert To Video Complete"); }
IEnumerator playVideo() { Debug.Log(Application.dataPath); rend = GetComponent <Renderer>(); videoPlayer = gameObject.AddComponent <VideoPlayer>(); audioSource = gameObject.AddComponent <AudioSource>(); //Disable Play on Awake for both Video and Audio videoPlayer.playOnAwake = false; audioSource.playOnAwake = false; videoPlayer.source = VideoSource.VideoClip; videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource; videoPlayer.EnableAudioTrack(0, true); videoPlayer.SetTargetAudioSource(0, audioSource); //Set video To Play then prepare Audio to prevent Buffering videoPlayer.clip = videoToPlay; videoPlayer.Prepare(); //Wait until video is prepared while (!videoPlayer.isPrepared) { yield return(null); } //Assign the Texture from Video to Material texture tex = videoPlayer.texture; rend.material.mainTexture = tex; videoPlayer.sendFrameReadyEvents = true; videoPlayer.frameReady += OnNewFrame; videoPlayer.Play(); audioSource.Play(); Debug.Log("Playing Video"); while (texList.Count != (int)videoPlayer.frameCount) { yield return(null); } Debug.Log("Done Playing Video"); /////////////////////////////////////////// //// /// // 왜곡이미지 처리/// /////////////////////////////////////////// VideoTrackAttributes videoAttr = new VideoTrackAttributes { frameRate = new MediaRational((int)videoPlayer.frameRate), width = videoPlayer.width, height = videoPlayer.height, }; AudioTrackAttributes audioAttr = new AudioTrackAttributes { sampleRate = new MediaRational(48000), channelCount = 2, language = "fr" }; int sampleFramesPerVideoFrame = audioAttr.channelCount * audioAttr.sampleRate.numerator / videoAttr.frameRate.numerator; // 동영상 생성 경로 string encodedFilePath = Path.Combine(Application.dataPath + "/Resources/ConvertVideo", "my_movie.mp4"); MediaEncoder encoder = new MediaEncoder(encodedFilePath, videoAttr, audioAttr); for (int i = 0; i < texList.Count; ++i) { Debug.Log("Encoding tex num " + (i + 1) + " / " + texList.Count); encoder.AddFrame(texList[i]); yield return(null); } encoder.Dispose(); Debug.Log("Convert To Video Complete"); }