public class VideoWriterBuilder
- Object
- 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();
Constructors
public VideoWriterBuilder() |
Methods
Inherited methods
Constructor details
VideoWriterBuilder
public VideoWriterBuilder()Method details
path
public VideoWriterBuilder path(String path)Sets the output path where the encoded video will be written, as a
com.codename1.io.FileSystemStorage path. Required.Parameters
pathString- the output FileSystemStorage path
Returns
Self for chaining.
container
public VideoWriterBuilder container(String container)Sets the container format, e.g.
VideoIO#CONTAINER_MP4 (default) or
VideoIO#CONTAINER_WEBM.Returns
Self for chaining.
hasVideo
public VideoWriterBuilder hasVideo(boolean hasVideo)Enables or disables the video track. Defaults to true.
Audio-only output (hasVideo(false)) is not currently implemented by the
platform backends, so build() rejects it rather than silently
producing a file with an empty or unexpected video track.
Returns
Self for chaining.
width
public VideoWriterBuilder width(int width)Sets the frame width in pixels. Default 1280.
Returns
Self for chaining.
height
public VideoWriterBuilder height(int height)Sets the frame height in pixels. Default 720.
Returns
Self for chaining.
frameRate
public VideoWriterBuilder frameRate(float 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
public VideoWriterBuilder videoCodec(String videoCodec)Sets the video codec by id, e.g.
VideoIO#CODEC_H264 (default). Use
VideoIO#getAvailableEncoders() to discover what the platform supports.Returns
Self for chaining.
videoBitRate
public VideoWriterBuilder videoBitRate(int 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
public VideoWriterBuilder keyFrameInterval(float seconds)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
public VideoWriterBuilder hasAudio(boolean hasAudio)Enables or disables the audio track. Defaults to false. When enabled, push PCM
samples with
VideoWriter#writeAudio.Returns
Self for chaining.
audioCodec
public VideoWriterBuilder audioCodec(String audioCodec)Sets the audio codec by id, e.g.
VideoIO#CODEC_AAC (default).Returns
Self for chaining.
audioBitRate
public VideoWriterBuilder audioBitRate(int audioBitRate)Sets the target audio bitrate in bits per second. Default 128000.
Returns
Self for chaining.
sampleRate
public VideoWriterBuilder sampleRate(int sampleRate)Sets the audio sample rate in Hz. Default 44100.
Returns
Self for chaining.
audioChannels
public VideoWriterBuilder audioChannels(int audioChannels)Sets the number of audio channels. Default 2.
Returns
Self for chaining.
build
public VideoWriter build()
throws IOExceptionBuilds the
VideoWriter with the current settings.Throws
IOException- if the writer could not be created
IllegalStateException- if
#path(String)was not set, video encoding is not supported on this platform, or audio-only output (#hasVideo(boolean)set to false) was requested
getPath
public String getPath()The configured output path.
getContainer
public String 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
public String 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
public String 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.