{"id":17351441,"url":"https://github.com/apidcloud/recordertest","last_synced_at":"2025-07-20T14:04:56.895Z","repository":{"id":50774708,"uuid":"255553132","full_name":"Apidcloud/RecorderTest","owner":"Apidcloud","description":"Headless Unity Screen and Audio Recorder repository. ","archived":false,"fork":false,"pushed_at":"2021-05-30T07:30:04.000Z","size":112514,"stargazers_count":10,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T21:26:28.805Z","etag":null,"topics":["headless","recorder","screen","screenshot","standalone","unity","unity3d","webgl"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Apidcloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-14T08:30:52.000Z","updated_at":"2024-01-18T19:08:35.000Z","dependencies_parsed_at":"2022-09-11T16:21:37.416Z","dependency_job_id":null,"html_url":"https://github.com/Apidcloud/RecorderTest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Apidcloud/RecorderTest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apidcloud%2FRecorderTest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apidcloud%2FRecorderTest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apidcloud%2FRecorderTest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apidcloud%2FRecorderTest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Apidcloud","download_url":"https://codeload.github.com/Apidcloud/RecorderTest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apidcloud%2FRecorderTest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266135685,"owners_count":23881803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["headless","recorder","screen","screenshot","standalone","unity","unity3d","webgl"],"created_at":"2024-10-15T17:09:57.018Z","updated_at":"2025-07-20T14:04:51.888Z","avatar_url":"https://github.com/Apidcloud.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Headless Unity Screen and Audio Recording\n\nHeadless mode is made possible for standalone build (i.e., windows, Mac, and Linux), through batch mode (`-batchMode`).\n\nThe web environment build (i.e., WebGL) is automated through `puppeteer`. Ideally, it will also be possible to make it work with audio, but **there is limited support for WebGL, as explained further below**.\n\nIn this test repository, everything is done locally, but the textures/images and audio could be sent to a server that is responsible for rendering them into video instead. Search for `SERVER` within `Assets/ScreenRecorder.cs` for that. The opposite is also valid: triggering the build in a server that replies with the rendered video.\n\n## Setup\n### Build\nThe first step is to build the project to the desired target. You can either do it manually through the Editor (**File \u003e Build Settings \u003e Build**), or through cli, as described in the subsections below.\n\nTo make it easier to access, in **standalone** scenarios, in case you opt for the cli, the resulting file will be saved to an automatically created `Build` folder. **Don't forget to `cd` to the project folder first.**\n\nThe **WebGl** build, in case you opt for the cli, will output it by default to `WebGl/Build`, and the textures will be saved into the persistent path, which is an **IndexedDB**.\n\n**Before building the project to WebGL**, however, you should **disable** the `anti-aliasing` in unity's **quality settings**. If it is enabled, it will throw some OpenGL errors and the rendering will not work causing the output images to be black.\n\n#### Windows x64\n`$ \"C:\\Program Files\\Unity\\Editor\\Unity.exe” -quit -batchmode -projectPath ./ -executeMethod BuildHelper.BuildWin64 -logFile buildLog.txt`\n\n#### Windows x86\n`$ \"C:\\Program Files (x86)\\Unity\\Editor\\Unity.exe” -quit -batchmode -projectPath ./ -executeMethod BuildHelper.BuildWin -logFile buildLog.txt`\n\n#### MacOS\n`$ /Applications/Unity/Hub/Editor/2018.4.10f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectPath ./ -executeMethod BuildHelper.BuildMac -logFile buildLog.txt`\n\n#### Linux\nRun the build resulting file as above, while setting `-executeMethod` to `BuildHelper.BuildLinux` or `BuildHelper.BuildLinux64` or `BuildHelper.BuildLinuxUniversal`\n\n#### WebGL\nMake sure to **disable** `anti-aliasing`, as described above, before running the following command:\n\n`$ \u003cunity-executable-or-app-path\u003e -quit -batchmode -projectPath ./ -executeMethod BuildHelper.BuildWeb -logFile buildLog.txt`\n\nAlternatively, if you want to automate the extra setup described next section, you can run the following instead:\n\n`$ \u003cunity-executable-or-app-path\u003e -quit -batchmode -projectPath ./ -executeMethod BuildHelper.BuildWeb -logFile buildLog.txt \u0026\u0026 node WebGl/inject.js`\n\nOr simply adapt `buildAndInjectWebGL.sh` to your needs, and execute it:\n\n`$ bash ./buildAndInjectWebGL.sh`\n\n### Run WebGl build\n\n#### Extra setup\nBefore anything else, _if you rebuilt the WebGl build_, some extra code must be added to the `index.html` file within `WebGl/Build` folder, so that Unity can call a function from the client side. You can either do it manually, or by running a simple script that will do that for you.\n\n##### Inject through script\nMake sure to have `nodejs` installed and run:\n\n`$ node WebGl/inject.js`\n\n##### Manually\nAt the end of html tag `head`, add a reference to a new script:\n\n`\u003cscript src=\"../handleDatabase.js\"\u003e\u003c/script\u003e`\n\nAt the beginning of `body`, add a new html element:\n\n`\u003cimg id=\"testImage\"\u003e`\n\nThis script will run after 30 frames are stored into the IndexedDB, and will change the background (i.e., `testImage`) to the first captured image as a test, to see if everything is working.\n\n#### Run build\n\nTo actually run the WebGL build in the browser, you will need a server. For instance:\n\n`$ python -m SimpleHTTPServer 8080`\n\nAnd open `http://localhost:8080/\u003cpath-to-WebGl/Build/\u003e`\n\nYou should see something like below:\n\n\u003cimg src=\"WebGl/ScreenshotResults/expectedWebGLResult.png\" alt=\"expected webgl result\" width=\"400\"/\u003e\n\n**Note that the screen of the game window will be black, because we are only concerned about running the project in headless/batch mode.**\n\n#### Run with Puppeteer\n\nThe idea of using something like Puppeteer is to run the browser automatically and in headless mode, while still executing the build and recording the images.\n\n##### Basic Setup\n\n1. Install [NodeJS](https://nodejs.org/en/) (v10.18.1 or higher)\n2. Install Yarn globally with `$ npm i -g yarn` or download it at their [website](https://yarnpkg.com/en/docs/install)\n3. `$ cd WebGl \u0026\u0026 yarn` to install the dependencies.\n4. `$ yarn server` to run a local server\n5. `$ yarn start` to run the WebGL build through puppeteer\n\n##### Expected results\n\nThe example is taking 2 screenshots after running for a few seconds (`WebGl/ScreenshotResults`). The resulting `renderingResult.png` should be the same as `expectedWebGLResult.png`.\n\nIt is also possible to run the WebGL build in **no-gpu** scenarios (e.g., a server). To do so, just uncomment `--disable-gpu` within `WebGl/main.js`.\n\n### Run Build in Batch Mode (Standalone)\n\nThe project is prepared to run in batch mode through a coroutine that will save the first 30 frames to .bmp files to **Build/ScreenRecorder**.\n\n#### Windows\n`$ ./Build/AutomaticRecording.exe -batchMode -logFile batchLog.txt`\n\n#### Mac\n`$ sudo ./Build/AutomaticRecording.app/Contents/MacOS/AutomaticRecording -batchMode -logFile batchLog.txt`\n\n### Video (with audio) Rendering\n\nAfter getting the images and audio (either locally or remotely), it is possible to render them to video (e.g., `.mp4`) through something like **ffpmeg**. You can do so, for standalone builds, explicitly or through a simple script.\n\n#### Explicitly\nAn example of that is to change to run:\n\n`$ ffmpeg -y -r 30 -f image2 -s 1920x1080 -i \"./Build/ScreenRecorder/frame%04d.bmp\" -i \"./Build/ScreenRecorder/audio_output.wav\" -shortest -vcodec libx264 -crf 25 -pix_fmt yuv420p \"./Build/ScreenRecorder/_video.mp4\"`\n\nBy default, the name of the (presumably longer) audio file will be `audio_output.wav`. The video is cutoff when the images/frames end through the flag `-shortest` to make sure the audio matches correctly.\n\n#### Script\n\nAlternatively, you can simply execute `ffmpegRendering.sh`:\n\n`$ bash ./ffmpegRendering.sh`\n\n#### Run Build and Render video\nYou can also run the build and render the video right after (_you might need admin permissions_):\n\n`$ ./Build/\u003cexecutable-or-app-name\u003e -batchMode -logFile batchLog.txt \u0026\u0026 bash ./ffmpegRendering.sh`\n\nOr simply (_you might need admin permissions_):\n\n`$ bash ./runBuildAndRender.sh`\n\n#### Audio Recording limitation in WebGL\nUnity3D relies on multiple threads to handle audio and mixing. Unfortunately, since WebGL platform does not support threads, the Audio API is limited and doesn't support `OnAudioFilterRead`, which is used (e.g., in standalone versions) to get the audio data while it is playing in runtime. More on this [here](https://docs.unity3d.com/Manual/webgl-audio.html).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapidcloud%2Frecordertest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapidcloud%2Frecordertest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapidcloud%2Frecordertest/lists"}