public override bool BeginRecording(RecordingSession session) { if (!base.BeginRecording(session)) { return(false); } try { m_Settings.m_DestinationPath.CreateDirectory(); } catch (Exception) { Debug.LogError(string.Format("Movie recorder output directory \"{0}\" could not be created.", m_Settings.m_DestinationPath.GetFullPath())); return(false); } int width; int height; if (m_Inputs[0] is ScreenCaptureInput) { var input = (ScreenCaptureInput)m_Inputs[0]; width = input.outputWidth; height = input.outputHeight; } else { var input = (BaseRenderTextureInput)m_Inputs[0]; if (input == null) { if (Verbose.enabled) { Debug.Log("MediaRecorder could not find input."); } return(false); } width = input.outputWidth; height = input.outputHeight; } if (width <= 0 || height <= 0) { if (Verbose.enabled) { Debug.Log(string.Format( "MovieRecorder got invalid input resolution {0} x {1}.", width, height)); } return(false); } if (width > 4096 || height > 2160 && m_Settings.m_OutputFormat == MediaRecorderOutputFormat.MP4) { Debug.LogError("Mp4 format does not support requested resolution."); } var cbRenderTextureInput = m_Inputs[0] as CBRenderTextureInput; bool includeAlphaFromTexture = cbRenderTextureInput != null && cbRenderTextureInput.cbSettings.m_AllowTransparency; if (includeAlphaFromTexture && m_Settings.m_OutputFormat == MediaRecorderOutputFormat.MP4) { Debug.LogWarning("Mp4 format does not support alpha."); includeAlphaFromTexture = false; } var videoAttrs = new VideoTrackAttributes() { frameRate = RationalFromDouble(session.settings.m_FrameRate), width = (uint)width, height = (uint)height, #if UNITY_2018_1_OR_NEWER includeAlpha = includeAlphaFromTexture, bitRateMode = (VideoBitrateMode)m_Settings.m_VideoBitRateMode #else includeAlpha = includeAlphaFromTexture #endif }; if (Verbose.enabled) { Debug.Log( string.Format( "MovieRecorder starting to write video {0}x{1}@[{2}/{3}] fps into {4}", width, height, videoAttrs.frameRate.numerator, videoAttrs.frameRate.denominator, m_Settings.m_DestinationPath.GetFullPath())); } var audioInput = (AudioInput)m_Inputs[1]; var audioAttrsList = new List <UnityEditor.Media.AudioTrackAttributes>(); var audioAttrs = new UnityEditor.Media.AudioTrackAttributes() { sampleRate = new MediaRational { numerator = audioInput.sampleRate, denominator = 1 }, channelCount = audioInput.channelCount, language = "" }; audioAttrsList.Add(audioAttrs); if (Verbose.enabled) { Debug.Log(string.Format("MovieRecorder starting to write audio {0}ch @ {1}Hz", audioAttrs.channelCount, audioAttrs.sampleRate.numerator)); } #if RECORD_AUDIO_MIXERS var audioSettings = input.audioSettings; m_WavWriters = new WavWriter [audioSettings.m_AudioMixerGroups.Length]; for (int n = 0; n < m_WavWriters.Length; n++) { if (audioSettings.m_AudioMixerGroups[n].m_MixerGroup == null) { continue; } var path = Path.Combine( m_Settings.m_DestinationPath, "recording of " + audioSettings.m_AudioMixerGroups[n].m_MixerGroup.name + ".wav"); if (Verbose.enabled) { Debug.Log("Starting wav recording into file " + path); } m_WavWriters[n].StartVertice(path); } #endif try { var fileName = m_Settings.m_BaseFileName.BuildFileName(session, recordedFramesCount, width, height, m_Settings.m_OutputFormat.ToString().ToLower()); var path = m_Settings.m_DestinationPath.GetFullPath() + "/" + fileName; m_Encoder = new UnityEditor.Media.MediaEncoder(path, videoAttrs, audioAttrsList.ToArray()); return(true); } catch { if (Verbose.enabled) { Debug.LogError("MovieRecorder unable to create MovieEncoder."); } } return(false); }
public MediaEncoder(string filePath, AudioTrackAttributes audioAttrs) : this(filePath, new[] { audioAttrs }) { }
public MediaEncoder(string filePath, VideoTrackAttributes videoAttrs, AudioTrackAttributes audioAttrs) : this(filePath, videoAttrs, new AudioTrackAttributes[] { audioAttrs }) { }