Class VideoWriterBuilder
A fluent builder describing how a video file should be encoded. It mirrors the
style of MediaRecorderBuilder but covers the full set of knobs needed for video:
dimensions, frame rate, codec, bitrate and key frame (GOP) interval, plus the audio
track parameters. Build a VideoWriter with #build() and then push frames and
audio into it.
Example:
VideoWriter w = new VideoWriterBuilder()
.path(FileSystemStorage.getInstance().getAppHomePath() + "/out.mp4")
.width(720).height(1280).frameRate(30)
.videoCodec(VideoIO.CODEC_H264).videoBitRate(4_000_000)
.hasAudio(true).audioCodec(VideoIO.CODEC_AAC).sampleRate(44100).audioChannels(2)
.build();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaudioBitRate(int audioBitRate) Sets the target audio bitrate in bits per second.audioChannels(int audioChannels) Sets the number of audio channels.audioCodec(String audioCodec) Sets the audio codec by id, e.g.build()Builds theVideoWriterwith the current settings.Sets the container format, e.g.frameRate(float frameRate) Sets the constant target frame rate in frames per second.intThe configured audio bitrate.intThe configured audio channel count.The configured audio codec id.The configured container format.floatThe configured frame rate.intThe configured frame height.floatThe configured key frame interval in seconds.getPath()The configured output path.intThe configured audio sample rate.intThe configured video bitrate, or -1 to let the implementation choose.The configured video codec id.intgetWidth()The configured frame width.hasAudio(boolean hasAudio) Enables or disables the audio track.hasVideo(boolean hasVideo) Enables or disables the video track.height(int height) Sets the frame height in pixels.booleanTrue if the audio track is enabled.booleanTrue if the video track is enabled.keyFrameInterval(float seconds) Sets the key frame (GOP) interval in seconds.Sets the output path where the encoded video will be written, as acom.codename1.io.FileSystemStoragepath.sampleRate(int sampleRate) Sets the audio sample rate in Hz.videoBitRate(int videoBitRate) Sets the target video bitrate in bits per second.videoCodec(String videoCodec) Sets the video codec by id, e.g.width(int width) Sets the frame width in pixels.
-
Constructor Details
-
VideoWriterBuilder
public VideoWriterBuilder()
-
-
Method Details
-
path
Sets the output path where the encoded video will be written, as a
com.codename1.io.FileSystemStoragepath. Required.Parameters
path: the output FileSystemStorage path
Returns
Self for chaining.
-
container
Sets the container format, e.g.
VideoIO#CONTAINER_MP4(default) orVideoIO#CONTAINER_WEBM.Returns
Self for chaining.
-
hasVideo
Enables or disables the video track. Defaults to true. Set to false to produce an audio only file.
Returns
Self for chaining.
-
width
Sets the frame width in pixels. Default 1280.
Returns
Self for chaining.
-
height
Sets the frame height in pixels. Default 720.
Returns
Self for chaining.
-
frameRate
Sets the constant target frame rate in frames per second. Default 30. Frames are timestamped by the application when calling
VideoWriter#writeFrame, this value is the nominal rate written into the file metadata and used by encoders that need it.Returns
Self for chaining.
-
videoCodec
Sets the video codec by id, e.g.
VideoIO#CODEC_H264(default). UseVideoIO#getAvailableEncoders()to discover what the platform supports.Returns
Self for chaining.
-
videoBitRate
Sets the target video bitrate in bits per second. When left at the default (-1) the implementation picks a reasonable value derived from the resolution and frame rate.
Returns
Self for chaining.
-
keyFrameInterval
Sets the key frame (GOP) interval in seconds. A smaller value produces files that seek more accurately at the cost of size. Default 2 seconds.
Returns
Self for chaining.
-
hasAudio
Enables or disables the audio track. Defaults to false. When enabled, push PCM samples with
VideoWriter#writeAudio.Returns
Self for chaining.
-
audioCodec
Sets the audio codec by id, e.g.
VideoIO#CODEC_AAC(default).Returns
Self for chaining.
-
audioBitRate
Sets the target audio bitrate in bits per second. Default 128000.
Returns
Self for chaining.
-
sampleRate
Sets the audio sample rate in Hz. Default 44100.
Returns
Self for chaining.
-
audioChannels
Sets the number of audio channels. Default 2.
Returns
Self for chaining.
-
build
Builds the
VideoWriterwith the current settings.Throws
-
IOException: if the writer could not be created -
IllegalStateException: if#path(String)was not set or video encoding is not supported on this platform
- Throws:
IOException
-
-
getPath
The configured output path. -
getContainer
The configured container format. -
isHasVideo
public boolean isHasVideo()True if the video track is enabled. -
getWidth
public int getWidth()The configured frame width. -
getHeight
public int getHeight()The configured frame height. -
getFrameRate
public float getFrameRate()The configured frame rate. -
getVideoCodec
The configured video codec id. -
getVideoBitRate
public int getVideoBitRate()The configured video bitrate, or -1 to let the implementation choose. -
getKeyFrameInterval
public float getKeyFrameInterval()The configured key frame interval in seconds. -
isHasAudio
public boolean isHasAudio()True if the audio track is enabled. -
getAudioCodec
The configured audio codec id. -
getAudioBitRate
public int getAudioBitRate()The configured audio bitrate. -
getSampleRate
public int getSampleRate()The configured audio sample rate. -
getAudioChannels
public int getAudioChannels()The configured audio channel count.
-