CaptureGUI.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. using UnityEngine;
  2. using System.Text;
  3. using System.Collections;
  4. //-----------------------------------------------------------------------------
  5. // Copyright 2012-2017 RenderHeads Ltd. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. namespace RenderHeads.Media.AVProMovieCapture
  8. {
  9. /// <summary>
  10. /// Uses IMGUI to render a GUI to control video capture. This is mainly used for the demos.
  11. /// </summary>
  12. [AddComponentMenu("AVPro Movie Capture/Capture GUI", 300)]
  13. public class CaptureGUI : MonoBehaviour
  14. {
  15. public CaptureBase _movieCapture;
  16. public bool _showUI = true;
  17. public bool _whenRecordingAutoHideUI = true;
  18. public GUISkin _guiSkin;
  19. // GUI
  20. private int _shownSection = -1;
  21. private string[] _videoCodecNames = new string[0];
  22. private string[] _audioCodecNames = new string[0];
  23. private bool[] _videoCodecConfigurable;
  24. private bool[] _audioCodecConfigurable;
  25. private string[] _audioDeviceNames = new string[0];
  26. private string[] _downScales = new string[0];
  27. private string[] _frameRates = new string[0];
  28. private int _downScaleIndex;
  29. private int _frameRateIndex;
  30. private Vector2 _videoPos = Vector2.zero;
  31. private Vector2 _audioPos = Vector2.zero;
  32. private Vector2 _audioCodecPos = Vector2.zero;
  33. // Status
  34. private long _lastFileSize;
  35. private uint _lastEncodedMinutes;
  36. private uint _lastEncodedSeconds;
  37. private uint _lastEncodedFrame;
  38. private void Start()
  39. {
  40. if (_movieCapture != null)
  41. {
  42. CreateGUI();
  43. }
  44. }
  45. private void CreateGUI()
  46. {
  47. _downScales = new string[6];
  48. _downScales[0] = "Original";
  49. _downScales[1] = "Half";
  50. _downScales[2] = "Quarter";
  51. _downScales[3] = "Eighth";
  52. _downScales[4] = "Sixteenth";
  53. _downScales[5] = "Custom";
  54. switch (_movieCapture._downScale)
  55. {
  56. default:
  57. case CaptureBase.DownScale.Original:
  58. _downScaleIndex = 0;
  59. break;
  60. case CaptureBase.DownScale.Half:
  61. _downScaleIndex = 1;
  62. break;
  63. case CaptureBase.DownScale.Quarter:
  64. _downScaleIndex = 2;
  65. break;
  66. case CaptureBase.DownScale.Eighth:
  67. _downScaleIndex = 3;
  68. break;
  69. case CaptureBase.DownScale.Sixteenth:
  70. _downScaleIndex = 4;
  71. break;
  72. case CaptureBase.DownScale.Custom:
  73. _downScaleIndex = 5;
  74. break;
  75. }
  76. _frameRates = new string[11];
  77. _frameRates[0] = "1";
  78. _frameRates[1] = "10";
  79. _frameRates[2] = "15";
  80. _frameRates[3] = "24";
  81. _frameRates[4] = "25";
  82. _frameRates[5] = "30";
  83. _frameRates[6] = "50";
  84. _frameRates[7] = "60";
  85. _frameRates[8] = "75";
  86. _frameRates[9] = "90";
  87. _frameRates[10] = "120";
  88. switch (_movieCapture._frameRate)
  89. {
  90. default:
  91. case CaptureBase.FrameRate.One:
  92. _frameRateIndex = 0;
  93. break;
  94. case CaptureBase.FrameRate.Ten:
  95. _frameRateIndex = 1;
  96. break;
  97. case CaptureBase.FrameRate.Fifteen:
  98. _frameRateIndex = 2;
  99. break;
  100. case CaptureBase.FrameRate.TwentyFour:
  101. _frameRateIndex = 3;
  102. break;
  103. case CaptureBase.FrameRate.TwentyFive:
  104. _frameRateIndex = 4;
  105. break;
  106. case CaptureBase.FrameRate.Thirty:
  107. _frameRateIndex = 5;
  108. break;
  109. case CaptureBase.FrameRate.Fifty:
  110. _frameRateIndex = 6;
  111. break;
  112. case CaptureBase.FrameRate.Sixty:
  113. _frameRateIndex = 7;
  114. break;
  115. case CaptureBase.FrameRate.SeventyFive:
  116. _frameRateIndex = 8;
  117. break;
  118. case CaptureBase.FrameRate.Ninety:
  119. _frameRateIndex = 9;
  120. break;
  121. case CaptureBase.FrameRate.OneTwenty:
  122. _frameRateIndex = 10;
  123. break;
  124. }
  125. int numVideoCodecs = NativePlugin.GetNumAVIVideoCodecs();
  126. if (numVideoCodecs > 0)
  127. {
  128. _videoCodecNames = new string[numVideoCodecs + 2];
  129. _videoCodecNames[0] = "Uncompressed";
  130. _videoCodecNames[1] = "Media Foundation H.264(MP4)";
  131. _videoCodecConfigurable = new bool[numVideoCodecs];
  132. for (int i = 0; i < numVideoCodecs; i++)
  133. {
  134. _videoCodecNames[i + 2] = NativePlugin.GetAVIVideoCodecName(i);
  135. _videoCodecConfigurable[i] = NativePlugin.IsConfigureVideoCodecSupported(i);
  136. }
  137. }
  138. int numAudioDevices = NativePlugin.GetNumAVIAudioInputDevices();
  139. if (numAudioDevices > 0)
  140. {
  141. _audioDeviceNames = new string[numAudioDevices + 1];
  142. _audioDeviceNames[0] = "Unity";
  143. for (int i = 0; i < numAudioDevices; i++)
  144. {
  145. _audioDeviceNames[i + 1] = NativePlugin.GetAVIAudioInputDeviceName(i);
  146. }
  147. }
  148. int numAudioCodecs = NativePlugin.GetNumAVIAudioCodecs();
  149. if (numAudioCodecs > 0)
  150. {
  151. _audioCodecNames = new string[numAudioCodecs + 1];
  152. _audioCodecNames[0] = "Uncompressed";
  153. _audioCodecConfigurable = new bool[numAudioCodecs];
  154. for (int i = 0; i < numAudioCodecs; i++)
  155. {
  156. _audioCodecNames[i + 1] = NativePlugin.GetAVIAudioCodecName(i);
  157. _audioCodecConfigurable[i] = NativePlugin.IsConfigureAudioCodecSupported(i);
  158. }
  159. }
  160. _movieCapture.SelectCodec(false);
  161. _movieCapture.SelectAudioCodec(false);
  162. _movieCapture.SelectAudioDevice(false);
  163. }
  164. private void OnGUI()
  165. {
  166. GUI.skin = _guiSkin;
  167. GUI.depth = -10;
  168. GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(Screen.width / 1920f * 1.5f, Screen.height / 1080f * 1.5f, 1f));
  169. if (_showUI)
  170. {
  171. GUILayout.Window(4, new Rect(0f, 0f, 450f, 256f), MyWindow, "AVPro Movie Capture UI");
  172. }
  173. }
  174. private void MyWindow(int id)
  175. {
  176. if (_movieCapture == null)
  177. {
  178. GUILayout.Label("CaptureGUI - No CaptureFrom component set");
  179. return;
  180. }
  181. if (_movieCapture.IsCapturing())
  182. {
  183. GUI_RecordingStatus();
  184. return;
  185. }
  186. GUILayout.BeginVertical();
  187. if (_movieCapture != null)
  188. {
  189. GUILayout.Label("Resolution:");
  190. GUILayout.BeginHorizontal();
  191. _downScaleIndex = GUILayout.SelectionGrid(_downScaleIndex, _downScales, _downScales.Length);
  192. switch (_downScaleIndex)
  193. {
  194. case 0:
  195. _movieCapture._downScale = CaptureBase.DownScale.Original;
  196. break;
  197. case 1:
  198. _movieCapture._downScale = CaptureBase.DownScale.Half;
  199. break;
  200. case 2:
  201. _movieCapture._downScale = CaptureBase.DownScale.Quarter;
  202. break;
  203. case 3:
  204. _movieCapture._downScale = CaptureBase.DownScale.Eighth;
  205. break;
  206. case 4:
  207. _movieCapture._downScale = CaptureBase.DownScale.Sixteenth;
  208. break;
  209. case 5:
  210. _movieCapture._downScale = CaptureBase.DownScale.Custom;
  211. break;
  212. }
  213. GUILayout.EndHorizontal();
  214. GUILayout.BeginHorizontal(GUILayout.Width(256));
  215. if (_movieCapture._downScale == CaptureBase.DownScale.Custom)
  216. {
  217. string maxWidthString = GUILayout.TextField(Mathf.FloorToInt(_movieCapture._maxVideoSize.x).ToString(), 4);
  218. int maxWidth = 0;
  219. if (int.TryParse(maxWidthString, out maxWidth))
  220. {
  221. _movieCapture._maxVideoSize.x = Mathf.Clamp(maxWidth, 0, 16384);
  222. }
  223. GUILayout.Label("x", GUILayout.Width(20));
  224. string maxHeightString = GUILayout.TextField(Mathf.FloorToInt(_movieCapture._maxVideoSize.y).ToString(), 4);
  225. int maxHeight = 0;
  226. if (int.TryParse(maxHeightString, out maxHeight))
  227. {
  228. _movieCapture._maxVideoSize.y = Mathf.Clamp(maxHeight, 0, 16384);
  229. }
  230. }
  231. GUILayout.EndHorizontal();
  232. GUILayout.BeginHorizontal();
  233. GUILayout.Label("Frame Rate:");
  234. _frameRateIndex = GUILayout.SelectionGrid(_frameRateIndex, _frameRates, _frameRates.Length);
  235. switch (_frameRateIndex)
  236. {
  237. case 0:
  238. _movieCapture._frameRate = CaptureBase.FrameRate.One;
  239. break;
  240. case 1:
  241. _movieCapture._frameRate = CaptureBase.FrameRate.Ten;
  242. break;
  243. case 2:
  244. _movieCapture._frameRate = CaptureBase.FrameRate.Fifteen;
  245. break;
  246. case 3:
  247. _movieCapture._frameRate = CaptureBase.FrameRate.TwentyFour;
  248. break;
  249. case 4:
  250. _movieCapture._frameRate = CaptureBase.FrameRate.TwentyFive;
  251. break;
  252. case 5:
  253. _movieCapture._frameRate = CaptureBase.FrameRate.Thirty;
  254. break;
  255. case 6:
  256. _movieCapture._frameRate = CaptureBase.FrameRate.Fifty;
  257. break;
  258. case 7:
  259. _movieCapture._frameRate = CaptureBase.FrameRate.Sixty;
  260. break;
  261. case 8:
  262. _movieCapture._frameRate = CaptureBase.FrameRate.SeventyFive;
  263. break;
  264. case 9:
  265. _movieCapture._frameRate = CaptureBase.FrameRate.Ninety;
  266. break;
  267. case 10:
  268. _movieCapture._frameRate = CaptureBase.FrameRate.OneTwenty;
  269. break;
  270. }
  271. GUILayout.EndHorizontal();
  272. GUILayout.Space(16f);
  273. _movieCapture._isRealTime = GUILayout.Toggle(_movieCapture._isRealTime, "RealTime");
  274. GUILayout.Space(16f);
  275. // Video Codec
  276. GUILayout.BeginHorizontal();
  277. if (_shownSection != 0)
  278. {
  279. if (GUILayout.Button("+", GUILayout.Width(24)))
  280. {
  281. _shownSection = 0;
  282. }
  283. }
  284. else
  285. {
  286. if (GUILayout.Button("-", GUILayout.Width(24)))
  287. {
  288. _shownSection = -1;
  289. }
  290. }
  291. GUILayout.Label("Using Video Codec: " + _movieCapture._codecName);
  292. if (_movieCapture._codecIndex >= 0 && _videoCodecConfigurable[_movieCapture._codecIndex])
  293. {
  294. GUILayout.Space(16f);
  295. if (GUILayout.Button("Configure Codec"))
  296. {
  297. NativePlugin.ConfigureVideoCodec(_movieCapture._codecIndex);
  298. }
  299. }
  300. GUILayout.EndHorizontal();
  301. if (_videoCodecNames != null && _shownSection == 0)
  302. {
  303. GUILayout.Label("Select Video Codec:");
  304. _videoPos = GUILayout.BeginScrollView(_videoPos, GUILayout.Height(100));
  305. int newCodecIndex = GUILayout.SelectionGrid(-1, _videoCodecNames, 1) - 2;
  306. GUILayout.EndScrollView();
  307. if (newCodecIndex >= -2)
  308. {
  309. _movieCapture._codecIndex = newCodecIndex;
  310. if (_movieCapture._codecIndex >= 0)
  311. {
  312. _movieCapture._codecName = _videoCodecNames[_movieCapture._codecIndex + 2];
  313. _movieCapture._useMediaFoundationH264 = false;
  314. }
  315. else
  316. {
  317. if (_movieCapture._codecIndex == -2)
  318. {
  319. _movieCapture._codecName = "Uncompressed";
  320. _movieCapture._useMediaFoundationH264 = false;
  321. }
  322. else
  323. {
  324. if (_movieCapture._codecIndex == -1)
  325. {
  326. _movieCapture._codecName = "Media Foundation H.264(MP4)";
  327. _movieCapture._useMediaFoundationH264 = true;
  328. }
  329. }
  330. }
  331. _shownSection = -1;
  332. }
  333. GUILayout.Space(16f);
  334. }
  335. GUI.enabled = _movieCapture._isRealTime;
  336. _movieCapture._noAudio = !GUILayout.Toggle(!_movieCapture._noAudio, "Record Audio");
  337. if (GUI.enabled)
  338. GUI.enabled = !_movieCapture._noAudio;
  339. // Audio Device
  340. GUILayout.BeginHorizontal();
  341. if (_shownSection != 1)
  342. {
  343. if (GUILayout.Button("+", GUILayout.Width(24)))
  344. {
  345. _shownSection = 1;
  346. }
  347. }
  348. else
  349. {
  350. if (GUILayout.Button("-", GUILayout.Width(24)))
  351. {
  352. _shownSection = -1;
  353. }
  354. }
  355. GUILayout.Label("Using Audio Source: " + _movieCapture._audioDeviceName);
  356. GUILayout.EndHorizontal();
  357. if (_audioDeviceNames != null && _shownSection == 1)
  358. {
  359. GUILayout.Label("Select Audio Source:");
  360. _audioPos = GUILayout.BeginScrollView(_audioPos, GUILayout.Height(100));
  361. int newAudioIndex = GUILayout.SelectionGrid(-1, _audioDeviceNames, 1) - 1;
  362. GUILayout.EndScrollView();
  363. if (newAudioIndex >= -1)
  364. {
  365. _movieCapture._audioDeviceIndex = newAudioIndex;
  366. if (_movieCapture._audioDeviceIndex >= 0)
  367. _movieCapture._audioDeviceName = _audioDeviceNames[_movieCapture._audioDeviceIndex + 1];
  368. else
  369. _movieCapture._audioDeviceName = "Unity";
  370. _shownSection = -1;
  371. }
  372. GUILayout.Space(16f);
  373. }
  374. // Audio Codec
  375. GUILayout.BeginHorizontal();
  376. if (_shownSection != 2)
  377. {
  378. if (GUILayout.Button("+", GUILayout.Width(24)))
  379. {
  380. _shownSection = 2;
  381. }
  382. }
  383. else
  384. {
  385. if (GUILayout.Button("-", GUILayout.Width(24)))
  386. {
  387. _shownSection = -1;
  388. }
  389. }
  390. GUILayout.Label("Using Audio Codec: " + _movieCapture._audioCodecName);
  391. if (_movieCapture._audioCodecIndex >= 0 && _audioCodecConfigurable[_movieCapture._audioCodecIndex])
  392. {
  393. GUILayout.Space(16f);
  394. if (GUILayout.Button("Configure Codec"))
  395. {
  396. NativePlugin.ConfigureAudioCodec(_movieCapture._audioCodecIndex);
  397. }
  398. }
  399. GUILayout.EndHorizontal();
  400. if (_audioCodecNames != null && _shownSection == 2)
  401. {
  402. GUILayout.Label("Select Audio Codec:");
  403. _audioCodecPos = GUILayout.BeginScrollView(_audioCodecPos, GUILayout.Height(100));
  404. int newCodecIndex = GUILayout.SelectionGrid(-1, _audioCodecNames, 1) - 1;
  405. GUILayout.EndScrollView();
  406. if (newCodecIndex >= -1)
  407. {
  408. _movieCapture._audioCodecIndex = newCodecIndex;
  409. if (_movieCapture._audioCodecIndex >= 0)
  410. _movieCapture._audioCodecName = _audioCodecNames[_movieCapture._audioCodecIndex + 1];
  411. else
  412. _movieCapture._audioCodecName = "Uncompressed";
  413. _shownSection = -1;
  414. }
  415. GUILayout.Space(16f);
  416. }
  417. GUI.enabled = true;
  418. GUILayout.Space(16f);
  419. GUILayout.BeginHorizontal();
  420. GUILayout.Label("Filename Prefix & Ext: ");
  421. _movieCapture._autoFilenamePrefix = GUILayout.TextField(_movieCapture._autoFilenamePrefix, 64);
  422. _movieCapture._autoFilenameExtension = GUILayout.TextField(_movieCapture._autoFilenameExtension, 8);
  423. GUILayout.EndHorizontal();
  424. GUILayout.Space(16f);
  425. GUILayout.Space(16f);
  426. GUILayout.Label("(Press Esc or CTRL-F5 to stop capture)");
  427. GUILayout.BeginHorizontal();
  428. if (!_movieCapture.IsCapturing())
  429. {
  430. GUI.color = Color.green;
  431. if (GUILayout.Button("Start Capture"))
  432. {
  433. StartCapture();
  434. }
  435. GUI.color = Color.white;
  436. }
  437. else
  438. {
  439. /*if (!_movieCapture.IsPaused())
  440. {
  441. if (GUILayout.Button("Pause Capture"))
  442. {
  443. PauseCapture();
  444. }
  445. }
  446. else
  447. {
  448. if (GUILayout.Button("Resume Capture"))
  449. {
  450. ResumeCapture();
  451. }
  452. }
  453. if (GUILayout.Button("Cancel Capture"))
  454. {
  455. CancelCapture();
  456. }
  457. if (GUILayout.Button("Stop Capture"))
  458. {
  459. StopCapture();
  460. }*/
  461. }
  462. GUILayout.EndHorizontal();
  463. if (_movieCapture.IsCapturing())
  464. {
  465. if (!string.IsNullOrEmpty(_movieCapture.LastFilePath))
  466. {
  467. GUILayout.Label("Writing file: '" + System.IO.Path.GetFileName(_movieCapture.LastFilePath) + "'");
  468. }
  469. }
  470. else
  471. {
  472. if (!string.IsNullOrEmpty(_movieCapture.LastFilePath))
  473. {
  474. GUILayout.Space(16f);
  475. GUILayout.Label("Last file written: '" + System.IO.Path.GetFileName(_movieCapture.LastFilePath) + "'");
  476. #if UNITY_EDITOR
  477. GUILayout.BeginHorizontal();
  478. if (GUILayout.Button("Browse"))
  479. {
  480. Utils.ShowInExplorer(_movieCapture.LastFilePath);
  481. }
  482. if (GUILayout.Button("View Last Capture"))
  483. {
  484. Utils.OpenInDefaultApp(_movieCapture.LastFilePath);
  485. }
  486. GUILayout.EndHorizontal();
  487. #endif
  488. }
  489. }
  490. }
  491. GUILayout.EndVertical();
  492. }
  493. private void GUI_RecordingStatus()
  494. {
  495. GUILayout.Space(8.0f);
  496. GUILayout.Label("Output", "box");
  497. GUILayout.BeginVertical("box");
  498. DrawGuiField("Recording to", System.IO.Path.GetFileName(_movieCapture.LastFilePath));
  499. GUILayout.Space(8.0f);
  500. GUILayout.Label("Video", "box");
  501. DrawGuiField("Dimensions", _movieCapture.GetRecordingWidth() + "x" + _movieCapture.GetRecordingHeight() + " @ " + ((int)_movieCapture._frameRate).ToString() + "hz");
  502. DrawGuiField("Codec", _movieCapture._codecName);
  503. if (!_movieCapture._noAudio && _movieCapture._isRealTime)
  504. {
  505. GUILayout.Label("Audio", "box");
  506. DrawGuiField("Source", _movieCapture._audioDeviceName);
  507. DrawGuiField("Codec", _movieCapture._audioCodecName);
  508. if (_movieCapture._audioDeviceName == "Unity")
  509. {
  510. DrawGuiField("Sample Rate", _movieCapture._unityAudioSampleRate.ToString() + "hz");
  511. DrawGuiField("Channels", _movieCapture._unityAudioChannelCount.ToString());
  512. }
  513. }
  514. GUILayout.EndVertical();
  515. GUILayout.Space(8.0f);
  516. GUILayout.Label("Stats", "box");
  517. GUILayout.BeginVertical("box");
  518. if (_movieCapture.FPS > 0f)
  519. {
  520. Color originalColor = GUI.color;
  521. if (_movieCapture._isRealTime)
  522. {
  523. float fpsDelta = (_movieCapture.FPS - (int)_movieCapture._frameRate);
  524. GUI.color = Color.red;
  525. if (fpsDelta > -10)
  526. {
  527. GUI.color = Color.yellow;
  528. }
  529. if (fpsDelta > -2)
  530. {
  531. GUI.color = Color.green;
  532. }
  533. }
  534. DrawGuiField("Capture Rate", string.Format("{0:0.##} / {1} FPS", _movieCapture.FPS, (int)_movieCapture._frameRate));
  535. GUI.color = originalColor;
  536. }
  537. else
  538. {
  539. DrawGuiField("Capture Rate", string.Format(".. / {0} FPS", (int)_movieCapture._frameRate));
  540. }
  541. DrawGuiField("File Size", ((float)_lastFileSize / (1024f * 1024f)).ToString("F1") + "MB");
  542. DrawGuiField("Video Length", _lastEncodedMinutes.ToString("00") + ":" + _lastEncodedSeconds.ToString("00") + "." + _lastEncodedFrame.ToString("000"));
  543. GUILayout.Label("Dropped Frames", "box");
  544. DrawGuiField("In Unity", _movieCapture.NumDroppedFrames.ToString());
  545. DrawGuiField("In Encoder ", _movieCapture.NumDroppedEncoderFrames.ToString());
  546. if (!_movieCapture._noAudio)
  547. {
  548. if (_movieCapture._audioCapture && _movieCapture._audioDeviceName == "Unity")
  549. {
  550. DrawGuiField("Audio Overflows", _movieCapture._audioCapture.OverflowCount.ToString());
  551. }
  552. }
  553. GUILayout.EndVertical();
  554. GUILayout.BeginHorizontal();
  555. if (!_movieCapture.IsPaused())
  556. {
  557. GUI.backgroundColor = Color.yellow;
  558. if (GUILayout.Button("Pause Capture"))
  559. {
  560. PauseCapture();
  561. }
  562. }
  563. else
  564. {
  565. GUI.backgroundColor = Color.green;
  566. if (GUILayout.Button("Resume Capture"))
  567. {
  568. ResumeCapture();
  569. }
  570. }
  571. GUI.backgroundColor = Color.cyan;
  572. if (GUILayout.Button("Cancel Capture"))
  573. {
  574. CancelCapture();
  575. }
  576. GUI.backgroundColor = Color.red;
  577. if (GUILayout.Button("Stop Capture"))
  578. {
  579. StopCapture();
  580. }
  581. GUI.backgroundColor = Color.white;
  582. GUILayout.EndHorizontal();
  583. }
  584. private void DrawGuiField(string a, string b)
  585. {
  586. GUILayout.BeginHorizontal();
  587. GUILayout.Label(a);
  588. GUILayout.FlexibleSpace();
  589. GUILayout.Label(b);
  590. GUILayout.EndHorizontal();
  591. }
  592. private void StartCapture()
  593. {
  594. _lastFileSize = 0;
  595. _lastEncodedMinutes = _lastEncodedSeconds = _lastEncodedFrame = 0;
  596. if (_whenRecordingAutoHideUI)
  597. {
  598. _showUI = false;
  599. }
  600. if (_movieCapture != null)
  601. {
  602. _movieCapture.StartCapture();
  603. }
  604. }
  605. private void StopCapture()
  606. {
  607. if (_movieCapture != null)
  608. {
  609. _movieCapture.StopCapture();
  610. }
  611. }
  612. private void CancelCapture()
  613. {
  614. if (_movieCapture != null)
  615. {
  616. _movieCapture.CancelCapture();
  617. }
  618. }
  619. private void ResumeCapture()
  620. {
  621. if (_movieCapture != null)
  622. {
  623. _movieCapture.ResumeCapture();
  624. }
  625. }
  626. private void PauseCapture()
  627. {
  628. if (_movieCapture != null)
  629. {
  630. _movieCapture.PauseCapture();
  631. }
  632. }
  633. private void Update()
  634. {
  635. if (_movieCapture != null)
  636. {
  637. if (_whenRecordingAutoHideUI && !_showUI)
  638. {
  639. if (!_movieCapture.IsCapturing())
  640. _showUI = true;
  641. }
  642. if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.F5))
  643. {
  644. if (_movieCapture.IsCapturing())
  645. {
  646. _movieCapture.StopCapture();
  647. }
  648. }
  649. if (_movieCapture.IsCapturing())
  650. {
  651. _lastFileSize = _movieCapture.GetCaptureFileSize();
  652. if (!_movieCapture._isRealTime)
  653. {
  654. _lastEncodedSeconds = (uint)Mathf.FloorToInt((float)_movieCapture.NumEncodedFrames / (float)_movieCapture._frameRate);
  655. }
  656. else
  657. {
  658. _lastEncodedSeconds = _movieCapture.TotalEncodedSeconds;
  659. }
  660. _lastEncodedMinutes = _lastEncodedSeconds / 60;
  661. _lastEncodedSeconds = _lastEncodedSeconds % 60;
  662. _lastEncodedFrame = _movieCapture.NumEncodedFrames % (uint)_movieCapture._frameRate;
  663. }
  664. }
  665. }
  666. }
  667. }