public abstract class VideoIO
- Object
- VideoIO
Low level video encoding and decoding using the platform’s native codecs. VideoIO
is to video what com.codename1.ui.util.ImageIO is to still images, but goes deeper:
it can enumerate the codecs the device actually supports, encode application rendered
frames and audio into a standard container (VideoWriter), and decode an existing
clip into frame accurate RGBA frames and PCM audio (VideoReader).
It is supported on iOS, macOS, Android, Windows, Linux, JavaScript and the desktop
simulator. It is not available on the TV, Watch or Car targets. As with other
optional platform features, always gate usage with #isSupported():
if (VideoIO.isSupported()) {
VideoIO io = VideoIO.getVideoIO();
// ... encode / decode
}
Encoding
Configure a VideoWriterBuilder, build a VideoWriter, push frames and audio, then
close it. Every frame is an ordinary com.codename1.ui.Image, so the application has
full control over the pixels.
Decoding
#openReader(String) returns a VideoReader exposing duration, dimensions and frame
rate, frame accurate VideoReader#frameAt(long), a variable to constant frame rate
resampler VideoReader#readFrames(float, com.codename1.media.VideoReader.FrameCallback)
and the audio track as PCM via VideoReader#readAudio().
Fields
Constructors
public VideoIO() |
Methods
Inherited methods
Field details
CODEC_H264
public static final String CODEC_H264 = "h264"CODEC_HEVC
public static final String CODEC_HEVC = "hevc"CODEC_VP8
public static final String CODEC_VP8 = "vp8"CODEC_VP9
public static final String CODEC_VP9 = "vp9"CODEC_AV1
public static final String CODEC_AV1 = "av1"CODEC_AAC
public static final String CODEC_AAC = "aac"CODEC_OPUS
public static final String CODEC_OPUS = "opus"CODEC_PCM
public static final String CODEC_PCM = "pcm"CONTAINER_MP4
public static final String CONTAINER_MP4 = "mp4"CONTAINER_WEBM
public static final String CONTAINER_WEBM = "webm"CONTAINER_MOV
public static final String CONTAINER_MOV = "mov"CONTAINER_MKV
public static final String CONTAINER_MKV = "mkv"Constructor details
VideoIO
public VideoIO()Method details
getVideoIO
public static VideoIO getVideoIO()VideoIO instance for the current platform, or null when video
encoding/decoding is not supported. Prefer #isSupported() for a simple boolean
check.Returns
VideoIO, or null if unsupportedisSupported
public static boolean isSupported()VideoIO API.Returns
getAvailableEncoders
public abstract VideoCodec[] getAvailableEncoders()VideoCodec#isHardwareAccelerated()).Returns
getAvailableDecoders
public abstract VideoCodec[] getAvailableDecoders()Returns
isEncoderSupported
public boolean isEncoderSupported(String codecId)Parameters
codecIdString- one of the
#CODEC_H264style constants
Returns
isDecoderSupported
public boolean isDecoderSupported(String codecId)Parameters
codecIdString- one of the
#CODEC_H264style constants
Returns
createWriter
public abstract VideoWriter createWriter(VideoWriterBuilder cfg)
throws IOExceptionVideoWriter for the supplied configuration. Application code normally
uses VideoWriterBuilder#build() rather than calling this directly.Parameters
cfgVideoWriterBuilder- the encoder configuration
Returns
Throws
IOException- if the writer cannot be created
openReader
public abstract VideoReader openReader(String filePath)
throws IOExceptionVideoReader for the clip at the supplied
com.codename1.io.FileSystemStorage path.Parameters
filePathString- the FileSystemStorage path of the clip to decode
Returns
Throws
IOException- if the clip cannot be opened
openReader
public VideoReader openReader(InputStream stream, String mimeType)
throws IOExceptionVideoReader for a clip supplied as a stream. The default implementation
spools the stream to a temporary file and opens that; platforms that can decode
directly from a stream may override it. The stream is fully consumed and closed.Parameters
streamInputStream- the clip data
mimeTypeString- the clip mime type (e.g. “video/mp4”), used to pick a file suffix; may be null
Returns
Throws
IOException- if the clip cannot be opened