// Start capture audio session public bool StartCapture() { // Check if we can start capture session if (status != CaptureStatus.READY) { OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.CAPTURE_ALREADY_IN_PROGRESS)); return(false); } saveFolderFullPath = Utils.CreateFolder(saveFolder); // Init audio recorder if (captureMicrophone) { if (MicrophoneRecorder.singleton == null) { gameObject.AddComponent <MicrophoneRecorder>(); } MicrophoneRecorder.singleton.saveFolderFullPath = saveFolderFullPath; MicrophoneRecorder.singleton.captureType = CaptureType.VOD; audioRecorder = MicrophoneRecorder.singleton; } else { if (AudioRecorder.singleton == null) { if (GetComponent <DontDestroy>() != null) { // Reset AudioListener AudioListener listener = FindObjectOfType <AudioListener>(); if (listener) { Destroy(listener); Debug.LogFormat(LOG_FORMAT, "AudioListener found, reset in game scene."); } gameObject.AddComponent <AudioListener>(); gameObject.AddComponent <AudioRecorder>(); } else { // Keep AudioListener AudioListener listener = FindObjectOfType <AudioListener>(); if (!listener) { listener = gameObject.AddComponent <AudioListener>(); Debug.LogFormat(LOG_FORMAT, "AudioListener not found, add a new AudioListener."); } listener.gameObject.AddComponent <AudioRecorder>(); } } AudioRecorder.singleton.saveFolderFullPath = saveFolderFullPath; AudioRecorder.singleton.captureType = CaptureType.VOD; audioRecorder = AudioRecorder.singleton; } if (audioRecorder == null) { OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.AUDIO_CAPTURE_START_FAILED)); return(false); } audioRecorder.StartRecord(); Debug.LogFormat(LOG_FORMAT, "Audio capture session started."); return(true); }
/// <summary> /// Prepare capture settings. /// </summary> protected bool PrepareCapture() { if (status != CaptureStatus.READY) { Debug.LogWarningFormat(LOG_FORMAT, "Previous capture session not finish yet!"); OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.CAPTURE_ALREADY_IN_PROGRESS)); return(false); } if (!FFmpegConfig.IsExist()) { Debug.LogErrorFormat(LOG_FORMAT, "FFmpeg not found, please follow document and add ffmpeg executable before start capture!"); OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.FFMPEG_NOT_FOUND)); return(false); } if (captureSource == CaptureSource.RENDERTEXTURE) { if (inputTexture == null) { Debug.LogErrorFormat(LOG_FORMAT, "Input render texture not found, please attach input render texture!"); OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.INPUT_TEXTURE_NOT_FOUND)); return(false); } if (captureMode != CaptureMode.REGULAR) { Debug.LogFormat(LOG_FORMAT, "Capture from render texture only support REGULAR CaptureMode"); captureMode = CaptureMode.REGULAR; projectionType = ProjectionType.NONE; } if (stereoMode != StereoMode.NONE) { Debug.LogFormat(LOG_FORMAT, "Capture from render texture only support NONE StereoMode"); stereoMode = StereoMode.NONE; } frameWidth = inputTexture.width; frameHeight = inputTexture.height; } else if (captureSource == CaptureSource.SCREEN) { if (captureMode != CaptureMode.REGULAR) { Debug.LogFormat(LOG_FORMAT, "Capture from screen only support REGULAR CaptureMode"); captureMode = CaptureMode.REGULAR; projectionType = ProjectionType.NONE; } if (stereoMode != StereoMode.NONE) { Debug.LogFormat(LOG_FORMAT, "Capture from screen only support NONE StereoMode"); stereoMode = StereoMode.NONE; } if (captureCursor) { Cursor.SetCursor(cursorImage, Vector2.zero, CursorMode.ForceSoftware); } frameWidth = Screen.width; frameHeight = Screen.height; } else { ResolutionPresetSettings(); } // Some codec cannot handle odd video size frameWidth = Utils.GetClosestEvenNumber(frameWidth); frameHeight = Utils.GetClosestEvenNumber(frameHeight); if (captureType == CaptureType.LIVE) { if (string.IsNullOrEmpty(liveStreamUrl)) { Debug.LogWarningFormat(LOG_FORMAT, "Please input a valid live streaming url."); OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.INVALID_STREAM_URI)); return(false); } } if (captureMode == CaptureMode._360) { if (projectionType == ProjectionType.NONE) { Debug.LogFormat(LOG_FORMAT, "Projection type should be set for 360 capture, set type to equirect for generating texture properly"); projectionType = ProjectionType.EQUIRECT; } if (projectionType == ProjectionType.CUBEMAP) { if (stereoMode != StereoMode.NONE) { Debug.LogFormat(LOG_FORMAT, "Stereo settings not support for cubemap capture, reset to mono video capture."); stereoMode = StereoMode.NONE; } } CubemapSizeSettings(); } else if (captureMode == CaptureMode.REGULAR) { // Non 360 capture doesn't have projection type projectionType = ProjectionType.NONE; } if (frameRate < 18) { frameRate = 18; Debug.LogFormat(LOG_FORMAT, "Minimum frame rate is 18, set frame rate to 18."); } if (frameRate > 120) { frameRate = 120; Debug.LogFormat(LOG_FORMAT, "Maximum frame rate is 120, set frame rate to 120."); } AntiAliasingSettings(); if (captureAudio && offlineRender) { Debug.LogFormat(LOG_FORMAT, "Audio capture not supported in offline render mode, disable audio capture!"); captureAudio = false; } // Save camera settings SaveCameraSettings(); if (transparent) { TransparentCameraSettings(); } ffmpegFullPath = FFmpegConfig.path; saveFolderFullPath = Utils.CreateFolder(saveFolder); lastVideoFile = ""; return(true); }
public bool StartCapture() { if (captureStarted) { Debug.LogWarningFormat(LOG_FORMAT, "Previous video capture manager session not finish yet!"); return(false); } // check all video capture is ready bool allReady = true; foreach (VideoCapture videoCapture in videoCaptures) { if (videoCapture.status != CaptureStatus.READY) { allReady = false; break; } } if (!allReady) { Debug.LogWarningFormat(LOG_FORMAT, "There is one or more video capture session still in progress!"); return(false); } if (!FFmpegConfig.IsExist()) { Debug.LogErrorFormat(LOG_FORMAT, "FFmpeg not found, please follow document and add ffmpeg executable before start capture!"); return(false); } saveFolder = Utils.CreateFolder(saveFolder); if (captureMode == CaptureMode._360) { if (projectionType == ProjectionType.NONE) { Debug.LogFormat(LOG_FORMAT, "Projection type should be set for 360 capture, set type to equirect for generating texture properly"); projectionType = ProjectionType.EQUIRECT; } if (projectionType == ProjectionType.CUBEMAP) { if (stereoMode != StereoMode.NONE) { Debug.LogFormat(LOG_FORMAT, "Stereo settings not support for cubemap capture, reset to mono video capture."); stereoMode = StereoMode.NONE; } } } else if (captureMode == CaptureMode.REGULAR) { // Non 360 capture doesn't have projection type projectionType = ProjectionType.NONE; } // start capture for all video capture foreach (VideoCapture videoCapture in videoCaptures) { // video capture settings videoCapture.startOnAwake = startOnAwake; videoCapture.captureTime = captureTime; videoCapture.quitAfterCapture = quitAfterCapture; videoCapture.captureMode = captureMode; videoCapture.projectionType = projectionType; // only VOD supported in multi capture videoCapture.captureType = CaptureType.VOD; videoCapture.saveFolder = saveFolder; videoCapture.resolutionPreset = resolutionPreset; videoCapture.frameWidth = frameWidth; videoCapture.frameHeight = frameHeight; videoCapture.frameRate = frameRate; videoCapture.bitrate = bitrate; videoCapture.stereoMode = stereoMode; videoCapture.interpupillaryDistance = interpupillaryDistance; videoCapture.cubemapFaceSize = cubemapFaceSize; videoCapture.offlineRender = offlineRender; videoCapture.captureAudio = captureAudio; videoCapture.captureMicrophone = captureMicrophone; videoCapture.deviceIndex = deviceIndex; videoCapture.antiAliasing = antiAliasing; videoCapture.gpuEncoding = gpuEncoding; videoCapture.encoderPreset = encoderPreset; videoCapture.legacyGpuEncoding = legacyGpuEncoding; videoCapture.StartCapture(); } captureStarted = true; return(true); }
/// <summary> /// Initialize the attributes of the capture session and start capture. /// </summary> public bool StartCapture() { if (_captureStarted) { Debug.LogWarningFormat(LOG_FORMAT, "Previous screenshot session not finish yet!"); OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.SCREENSHOT_ALREADY_IN_PROGRESS)); return(false); } saveFolderFullPath = Utils.CreateFolder(saveFolder); if (captureMode == CaptureMode._360) { if (projectionType == ProjectionType.NONE) { Debug.LogFormat(LOG_FORMAT, "Projection type should be set for 360 capture, set type to equirect for generating texture properly"); projectionType = ProjectionType.EQUIRECT; } if (projectionType == ProjectionType.CUBEMAP) { if (stereoMode != StereoMode.NONE) { Debug.LogFormat(LOG_FORMAT, "Stereo settings not support for cubemap capture, reset to mono video capture."); stereoMode = StereoMode.NONE; } } CubemapSizeSettings(); } else if (captureMode == CaptureMode.REGULAR) { // Non 360 capture doesn't have projection type projectionType = ProjectionType.NONE; } AntiAliasingSettings(); // init ffmpeg encoding settings FFmpegEncoderSettings(); #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN if (gpuEncoding) { if (FreeTrial.Check()) { Debug.LogFormat(LOG_FORMAT, "GPU encoding is not supported in free trial version, fall back to software encoding."); gpuEncoding = false; } // init GPU encoding settings GPUEncoderSettings(); if (!gpuEncoder.instantiated || !gpuEncoder.IsSupported()) { Debug.LogFormat(LOG_FORMAT, "GPU encoding is not supported in current device or settings, fall back to software encoding."); gpuEncoding = false; } } #else if (gpuEncoding) { Debug.LogFormat(LOG_FORMAT, "GPU encoding is only available on windows system, fall back to software encoding."); gpuEncoding = false; } #endif if (gpuEncoding) { // init hardware encoding settings GPUEncoderSettings(); if (!gpuEncoder.StartScreenShot()) { OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.SCREENSHOT_START_FAILED)); return(false); } } else { if (!ffmpegEncoder.StartScreenShot()) { OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.SCREENSHOT_START_FAILED)); return(false); } } _captureStarted = true; // Start garbage collect thread. //if (!garbageThreadRunning) //{ // garbageThreadRunning = true; // if (garbageCollectionThread != null && // garbageCollectionThread.IsAlive) // { // garbageCollectionThread.Abort(); // garbageCollectionThread = null; // } // garbageCollectionThread = new Thread(GarbageCollectionProcess); // garbageCollectionThread.Priority = System.Threading.ThreadPriority.Lowest; // garbageCollectionThread.IsBackground = true; // garbageCollectionThread.Start(); //} Debug.LogFormat(LOG_FORMAT, "Screen shot session started."); return(true); }