void Start() { if (_camera == null) { _camera = Camera.main; } if (_camera == null) { Debug.LogWarning("VimeoPublisher: No camera was specified."); return; } recorder = _camera.GetComponent <VimeoRecorder>(); if (recorder == null) { recorder = _camera.gameObject.AddComponent <VimeoRecorder>(); Debug.Log("VimeoRecorder automatically added to " + _camera.name + ": " + recorder); } api = gameObject.AddComponent <VimeoApi> (); api.token = GetVimeoToken(); api.OnPatchComplete += VideoUpdated; api.OnUploadComplete += UploadComplete; api.OnUploadProgress += UploadProgress; if (recordOnStart) { BeginRecording(); } }
IEnumerator OnPostRender() { if (isRecording && encoder != null) { yield return(new WaitForEndOfFrame()); VimeoRecorder.CaptureLock(renderBuffer, (data) => { encoder.AddFrame(data); }); // Fill 'audioBuffer' with the audio content to be encoded into the file for this frame. // ... //encoder.AddSamples(audioBuffer); } }
public void BeginRecording() { Debug.Log("VimeoRecorder: BeginRecording()"); isRecording = true; _camera = GetComponent <Camera>(); encodedFilePath = Path.Combine(outputPath, "test-recording.mp4"); Debug.Log(encodedFilePath); // Setup shader/material/quad if (shaderCopy == null) { shaderCopy = Shader.Find("Hidden/FrameRecorder/CopyFrameBuffer"); } if (matCopy == null) { matCopy = new Material(shaderCopy); } if (fullscreenQuad == null) { fullscreenQuad = VimeoRecorder.CreateFullscreenQuad(); } // Get Camera data and prepare to send to buffer int captureWidth = (_camera.pixelWidth + 1) & ~1; int captureHeight = (_camera.pixelHeight + 1) & ~1; renderBuffer = new RenderTexture(captureWidth, captureHeight, 0); renderBuffer.wrapMode = TextureWrapMode.Repeat; renderBuffer.Create(); Debug.Log("WxH: " + captureWidth + "x" + captureHeight); // Configure encoder videoAttrs = new VideoTrackAttributes { frameRate = new MediaRational(40), width = (uint)captureWidth, height = (uint)captureHeight, includeAlpha = false }; audioAttrs = new AudioTrackAttributes { sampleRate = new MediaRational(48000), channelCount = 2, language = "en" }; encoder = new MediaEncoder(encodedFilePath, videoAttrs, audioAttrs); //sampleFramesPerVideoFrame = audioAttrs.channelCount * audioAttrs.sampleRate.numerator / videoAttrs.frameRate.numerator; //audioBuffer = new NativeArray<float>(sampleFramesPerVideoFrame, Allocator.Temp); // Setup the command buffer // TODO: Support RenderTexture int tid = Shader.PropertyToID("_TmpFrameBuffer"); commandBuffer = new CommandBuffer(); commandBuffer.name = "VimeoRecorder: copy frame buffer"; commandBuffer.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Bilinear); commandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, tid); commandBuffer.SetRenderTarget(renderBuffer); commandBuffer.DrawMesh(fullscreenQuad, Matrix4x4.identity, matCopy, 0, 0); commandBuffer.ReleaseTemporaryRT(tid); _camera.AddCommandBuffer(CameraEvent.AfterEverything, commandBuffer); }