public void CreateVideoFromByteArray(string filePath, int width, int height, int frameRate) { byte[] frameData = new byte[width * height * 4]; GCHandle frameHandle = GCHandle.Alloc(frameData, GCHandleType.Pinned); // Start the recording session int encoderHandle = AVProMovieCapturePlugin.CreateRecorderAVI(filePath, (uint)width, (uint)height, frameRate, (int)AVProMovieCapturePlugin.PixelFormat.RGBA32, false, _videoCodecIndex, false, 0, 0, -1, -1, false, false, false); if (encoderHandle >= 0) { AVProMovieCapturePlugin.Start(encoderHandle); // Write out 100 frames int numFrames = 100; for (int i = 0; i < numFrames; i++) { // TODO: update the byte array with your data :) // Wait for the encoder to be ready for the next frame int numAttempts = 32; while (numAttempts > 0) { if (AVProMovieCapturePlugin.IsNewFrameDue(encoderHandle)) { // Encode the new frame AVProMovieCapturePlugin.EncodeFrame(encoderHandle, frameHandle.AddrOfPinnedObject()); break; } System.Threading.Thread.Sleep(1); numAttempts--; } } // End the session AVProMovieCapturePlugin.Stop(encoderHandle, false); AVProMovieCapturePlugin.FreeRecorder(encoderHandle); } if (frameHandle.IsAllocated) { frameHandle.Free(); } }
public void StopCapture() { if (_capturing) { Debug.Log("[AVProMovieCapture] Stopping capture"); _capturing = false; } if (_handle >= 0) { AVProMovieCapturePlugin.Stop(_handle); System.Threading.Thread.Sleep(100); AVProMovieCapturePlugin.FreeRecorder(_handle); _handle = -1; } _fileInfo = null; if (_audioCapture) { _audioCapture.enabled = false; } Time.captureFramerate = 0; Application.targetFrameRate = -1; if (_oldVSyncCount > 0) { QualitySettings.vSyncCount = _oldVSyncCount; _oldVSyncCount = 0; } if (_texture != null) { Destroy(_texture); _texture = null; } }
public virtual void StopCapture(bool skipPendingFrames = false) { UnprepareCapture(); if (_capturing) { Debug.Log("[AVProMovieCapture] Stopping capture"); _capturing = false; } #if AVPRO_MOVIECAPTURE_GLISSUEEVENT_52 GL.IssuePluginEvent(_freeEventFunction, AVProMovieCapturePlugin.PluginID | (int)AVProMovieCapturePlugin.PluginEvent.FreeResources); #else GL.IssuePluginEvent(AVProMovieCapturePlugin.PluginID | (int)AVProMovieCapturePlugin.PluginEvent.FreeResources); #endif if (_handle >= 0) { AVProMovieCapturePlugin.Stop(_handle, skipPendingFrames); //System.Threading.Thread.Sleep(100); AVProMovieCapturePlugin.FreeRecorder(_handle); _handle = -1; } _fileInfo = null; if (_audioCapture) { _audioCapture.enabled = false; } if (_motionBlur) { _motionBlur.enabled = false; } // Restore Unity timing Time.captureFramerate = 0; Application.targetFrameRate = _oldTargetFrameRate; _oldTargetFrameRate = -1; if (_oldFixedDeltaTime > 0f) { Time.fixedDeltaTime = _oldFixedDeltaTime; } _oldFixedDeltaTime = 0f; if (_oldVSyncCount > 0) { QualitySettings.vSyncCount = _oldVSyncCount; _oldVSyncCount = 0; } _motionBlur = null; if (_texture != null) { Destroy(_texture); _texture = null; } }