static GameObject VideoGO = null; // temp GO used during video recording to process each frame public static void StartRecording() { register_events(); DateTime date = DateTime.Now; string prefix = date.Day + "-" + date.Month + "-" + date.Year + "-" + date.Hour + "-" + date.Minute + "-" + date.Second; string sName = Path.Combine(Application.persistentDataPath, "ARStream_" + prefix + ".txt"); var stream = new gs.ARKitStream(); try { stream.InitializeWrite(sName); SaveStream = stream; } catch (Exception e) { ErrorMessageF("Error creating stream file " + sName + " : " + e.Message); } if (EnableSaveVideoStream) { VideoGO = new GameObject("gs_stream_recorder"); VideoGO.AddComponent <RecorderFrameProcessing>().PerFrameFunc = per_frame_processing; string sVideoName = Path.Combine(Application.persistentDataPath, "VideoStream_" + prefix + ".bin"); var video_stream = new gs.VideoStream(); try { video_stream.InitializeWrite(sVideoName); SaveVideoStream = video_stream; } catch (Exception e) { ErrorMessageF("Error creating video stream file " + sVideoName + " : " + e.Message); } } }
public static void StopRecording() { if (SaveStream != null) { SaveStream.Shutdown(); SaveStream = null; } if (SaveVideoStream != null) { SaveVideoStream.Shutdown(); SaveVideoStream = null; if (VideoGO != null) { GameObject.Destroy(VideoGO); VideoGO = null; } } }
public void StartPlayback(string sFilename) { if (FakeStream != null) { FakeStream.Stop(true); } if (current_filename != sFilename) { gs.ARKitStream stream = new gs.ARKitStream(); stream.InitializeFromFileAscii(sFilename); string sVideoFilename = sFilename.Replace("ARStream", "VideoStream"); sVideoFilename = sVideoFilename.Replace(".txt", ".bin"); gs.VideoStream video_stream = null; if (File.Exists(sVideoFilename)) { video_stream = new gs.VideoStream(); video_stream.InitializeRead(sVideoFilename, true); } FakeStream = new gs.ARKitStreamPlayback(); FakeStream.SetSource(stream, video_stream); current_filename = sFilename; } samples_parent = new GameObject("samples_parent"); planes_parent = new GameObject("planes_parent"); Material videoMaterial = null; if (VideoPlane != null) { videoMaterial = VideoPlane.GetComponent <Renderer>().material; } Texture2D video_texture = null; FakeStream.NewFrameF = (time) => { reset_all_markers(); }; FakeStream.UpdateCameraF = (pos, rot) => { Camera.main.transform.position = pos; Camera.main.transform.rotation = rot; }; FakeStream.EmitSamplePointF = (pos, screenPos, color) => { if (ShowSamplePoints) { GameObject sample_go = request_marker_go(); sample_go.transform.position = pos; sample_go.GetComponent <MeshRenderer>().material.color = color; } }; FakeStream.PlaneChangeF = (ARKitStream.PlaneChange eType, ARKitStream.ARKitPlane plane) => { if (eType == ARKitStream.PlaneChange.Removed) { remove_plane(plane); } else { update_plane(plane); } }; FakeStream.EmitVideoFrameF = (frame) => { if (videoMaterial != null) { if (video_texture == null) { video_texture = new Texture2D(frame.width, frame.height); } video_texture.LoadImage(frame.rgb); videoMaterial.SetTexture("_MainTex", video_texture); } }; FakeStream.Start(Time.realtimeSinceStartup); }