Class RecordingSession
java.lang.Object
net.emustudio.emulib.recording.RecordingSession
- All Implemented Interfaces:
AutoCloseable
Thread-safe, one-time MP4 recording of video (H.264) and audio (PCM).
Video frames and audio arrive independently. Inputs are copied before returning, so producers may reuse their
buffers. Video is encoded on a dedicated worker into a temporary file; audio is stored compressed in another
temporary file and muxed in on stop(Path). Capture never waits for the worker: exceeding the bounded
queue fails the session instead of slowing emulation. Check getFailure() when capture returns false.
Audio is signed 16-bit little-endian stereo PCM at the configured sample rate. Producers own frame pacing, synthesis and mixing.
stop(Path) and close() wait for the worker and file I/O. Call them off the UI thread.
-
Constructor Summary
ConstructorsConstructorDescriptionRecordingSession(int width, int height, int videoScale, int videoRate, int audioSampleRate) Starts a recording. -
Method Summary
Modifier and TypeMethodDescriptionbooleancaptureAudio(byte[] pcmSamples, int length) Captures the first length bytes of PCM audio.booleancaptureVideo(BufferedImage frame) Captures one video frame.voidclose()Discards this recording and releases its files.voidStops accepting capture and saves MP4 to target, or discards the recording when target is null.
-
Constructor Details
-
RecordingSession
public RecordingSession(int width, int height, int videoScale, int videoRate, int audioSampleRate) throws IOException Starts a recording. Dimensions must be positive and even for H.264.- Parameters:
width- video width in pixelsheight- video height in pixelsvideoScale- frame-rate denominatorvideoRate- frame-rate numerator; fps = videoRate / videoScaleaudioSampleRate- stereo PCM frames per second- Throws:
IOException- if temporary recording files cannot be createdIllegalArgumentException- if dimensions, frame rate or sample rate are invalid
-
-
Method Details
-
captureVideo
Captures one video frame.- Parameters:
frame- video frame of the recording size; null frames are ignored- Returns:
- false if the frame was ignored, or the session is stopped or failed
-
captureAudio
public boolean captureAudio(byte[] pcmSamples, int length) Captures the first length bytes of PCM audio. Empty chunks are ignored.- Parameters:
pcmSamples- PCM buffer, which may be reused after this calllength- number of bytes, containing only whole stereo PCM frames- Returns:
- false if the session is stopped or failed
- Throws:
NullPointerException- if an active producer passes a null bufferIndexOutOfBoundsException- if length is outside the buffer
-
getFailure
- Returns:
- the capture failure, or null while healthy. Safe to poll from producer/UI threads.
-
stop
Stops accepting capture and saves MP4 to target, or discards the recording when target is null. Saving drains accepted captures; discarding drops pending captures. Repeated calls do nothing. Temporary files are always deleted; an existing target is kept if export fails.- Parameters:
target- destination MP4 (parent directories are created), or null to discard- Throws:
IOException- if capture or export failed, the recording has no frames, or stopping was interrupted
-
close
Discards this recording and releases its files. Blocks until the worker stops.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-