//void GarbageCollectionProcess() //{ // double deltaTime = 1 / (double)frameRate; // int sleepTime = (int)(deltaTime * 1000); // while (status != CaptureStatus.READY) // { // Thread.Sleep(sleepTime); // System.GC.Collect(); // } // garbageThreadRunning = false; //} #endregion #region Unity Lifecycle protected new void Awake() { base.Awake(); if (ffmpegEncoder == null) { ffmpegEncoder = GetComponentInChildren <FFmpegEncoder>(true); if (ffmpegEncoder == null) { Debug.LogErrorFormat(LOG_FORMAT, "Component FFmpegEncoder not found, please use prefab or follow the document to set up video capture."); return; } } if (gpuEncoder == null) { gpuEncoder = GetComponentInChildren <GPUEncoder>(true); if (gpuEncoder == null) { Debug.LogErrorFormat(LOG_FORMAT, "Component hardware encoder not found, please use prefab or follow the document to set up video capture."); } } if (nvidiaEncoder == null) { nvidiaEncoder = GetComponentInChildren <NvidiaEncoder>(true); if (nvidiaEncoder == null) { Debug.LogErrorFormat(LOG_FORMAT, "Component nvidia encoder not found, please use prefab or follow the document to set up video capture."); } } }
/// <summary> /// Media muxing the thread function. /// </summary> private void MuxingThreadFunction() { // Wait for all video record finish while (GetVideoPendingCount() < videoCaptures.Count) { Thread.Sleep(1000); } // Muxing video capture foreach (IVideoCapture videoCapture in videoCaptures) { if (!StartMuxProcess(videoCapture)) { break; } FFmpegEncoder ffmpegEncoder = videoCapture.GetFFmpegEncoder(); // Clean video files if (File.Exists(ffmpegEncoder.videoSavePath)) { // clean up video with no sound File.Delete(ffmpegEncoder.videoSavePath); ffmpegEncoder.videoSavePath = ""; } } // Clean video capture queue videoCaptures.Clear(); // Clean audio file if (File.Exists(audioSavePath)) { File.Delete(audioSavePath); audioSavePath = ""; } }
private void Awake() { if (ffmpegEncoder == null) { ffmpegEncoder = GetComponentInChildren <FFmpegEncoder>(true); if (ffmpegEncoder == null) { Debug.LogErrorFormat(LOG_FORMAT, "Component software Encoder not found, please use prefab or follow the document to set up video capture."); } } if (gpuEncoder == null) { gpuEncoder = GetComponentInChildren <GPUEncoder>(true); if (gpuEncoder == null) { Debug.LogErrorFormat(LOG_FORMAT, "Component GPU encoder not found, please use prefab or follow the document to set up video capture."); } } if (ffmpegEncoder != null) { ffmpegEncoder.OnComplete += OnEncoderComplete; } #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN if (gpuEncoder != null) { gpuEncoder.gameObject.SetActive(true); gpuEncoder.OnComplete += OnEncoderComplete; } #endif }
// Start video/audio muxing process, this is blocking function public bool StartMuxProcess(IVideoCapture videoCapture) { FFmpegEncoder ffmpegEncoder = videoCapture.GetFFmpegEncoder(); string videoSavePath = string.Format("{0}capture_{1}x{2}_{3}_{4}.mp4", Config.saveFolder, ffmpegEncoder.outputFrameWidth, ffmpegEncoder.outputFrameHeight, Utils.GetTimeString(), Utils.GetRandomString(5)); IntPtr nativeAPI = FFmpegEncoder_StartMuxProcess( ffmpegEncoder.bitrate, videoSavePath, ffmpegEncoder.videoSavePath, audioSavePath, ffmpegPath); if (nativeAPI == IntPtr.Zero) { OnError(EncoderErrorCode.MUXING_FAILED_TO_START); return(false); } // Make sure generated the merge file int waitCount = 0; while (!File.Exists(videoSavePath)) { if (waitCount++ < 100) { Thread.Sleep(500); } else { OnError(EncoderErrorCode.MUXING_FAILED); FFmpegEncoder_CleanMuxProcess(nativeAPI); return(false); } } FFmpegEncoder_CleanMuxProcess(nativeAPI); //Debug.LogFormat(LOG_FORMAT, "Muxing process finish!"); // Video capture callback videoCapture.OnAudioMuxingComplete(videoSavePath); return(true); }