Download

How to programmatically export level sequence audio and visuals

Hi all,

We’re working on a project that trains a neural net with videos+audio generated from UE4, and as you’d expect, given the # of files needed for good training, we would want to do this automatically instead of using the editor GUI. The video part is not hard as there are articles on it already (https://michaeljcole.github.io/wiki.unrealengine.com/Sequencer_Batch_Rendering/, https://docs.unrealengine.com/en-US/AnimatingObjects/Sequencer/Workflow/RenderAndExport/RenderingCmdLine/index.html). I couldn’t find anything except questions on the audio part, so I figured I’d share the solution here.

One of the more recent UE releases added audio output from the “master audio submix,” which I believe requires the Audio Synthesis plugin to be enabled (I think it’s automatically labelled as of 4.25). This results in an extra .wav file being output in the output directory, which is temporally aligned with the .avi. It wasn’t clear how exactly to set this from the command prompt as the parameters seem to only be documented in the UE4 source code (in my case, I looked in UE4.25), in particular, Runtime/MovieSceneCapture/Private/MovieSceneCapture.cpp. Here you can see this “AudioCaptureProtocol,” which needs to be set to get the audio to output.

So, to do the equivalent of hitting the “Capture Movie” button in my screenshot, you’ll need to go into a command prompt and use this syntax:
[HR][/HR]“E:\Program Files\Epic Games\UE_4.25\Engine\Binaries\Win64\UE4Editor.exe” “E:\Unreal Projects[project folder name][uproject name].uproject” /Game/[map name] -game -MovieSceneCaptureType="/Script/MovieSceneCapture.AutomatedLevelSequenceCapture" -LevelSequence="/Game/[level sequence to use]" -MovieFrameRate=30 -noloadingscreen -resx=1280 -resy=720 -MovieFormat=AVI -MovieQuality=75 -AudioCaptureProtocol=MasterAudioSubmix -MovieOverwriteExisting=true [HR][/HR]
I find that, unlike the .avi, the audio doesn’t seem to overwrite or create a new .wav file unless you explicitly tell it to with that last parameter. In the UE source code, it seems that the devs are currently treating the audio output under the same umbrella as visuals, so they still share parameters like MovieOverwriteExisting, which affects both audio and visuals and doesn’t seem separable, although you can of course change the name of the output file (add the -MovieName=“Example” parameter). I don’t think there’s a difference in 4.26 as far as I can tell from the release notes. For our project, I use python to programmatically generate this command and output to many files of specific names. You should also be able to send options directly to BP or C++ like this or use an extra file to keep track of things. You could also use Windows Batch if you prefer.

Anyway, hope this helps someone avoid diving into the engine code.