Class 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().
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCodec id for AAC audio, the most broadly compatible audio codec.static final StringCodec id for AV1 video.static final StringCodec id for H.264 / AVC video, the most broadly compatible video codec.static final StringCodec id for H.265 / HEVC video.static final StringCodec id for Opus audio.static final StringCodec id for uncompressed 16 bit PCM audio.static final StringCodec id for VP8 video.static final StringCodec id for VP9 video.static final StringContainer id for the Matroska (.mkv) container.static final StringContainer id for the QuickTime (.mov) container.static final StringContainer id for the MPEG 4 (.mp4) container.static final StringContainer id for the WebM (.webm) container. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract VideoWriterCreates aVideoWriterfor the supplied configuration.abstract VideoCodec[]Lists the codecs that can be used for decoding on this device.abstract VideoCodec[]Lists the codecs that can be used for encoding on this device.static VideoIOReturns theVideoIOinstance for the current platform, or null when video encoding/decoding is not supported.booleanisDecoderSupported(String codecId) Tests whether a given codec id can be used for decoding on this device.booleanisEncoderSupported(String codecId) Tests whether a given codec id can be used for encoding on this device.static booleanConvenience test for whether this platform supports theVideoIOAPI.openReader(InputStream stream, String mimeType) Opens aVideoReaderfor a clip supplied as a stream.abstract VideoReaderopenReader(String filePath) Opens aVideoReaderfor the clip at the suppliedcom.codename1.io.FileSystemStoragepath.
-
Field Details
-
CODEC_H264
Codec id for H.264 / AVC video, the most broadly compatible video codec.- See Also:
-
CODEC_HEVC
-
CODEC_VP8
-
CODEC_VP9
-
CODEC_AV1
-
CODEC_AAC
Codec id for AAC audio, the most broadly compatible audio codec.- See Also:
-
CODEC_OPUS
-
CODEC_PCM
-
CONTAINER_MP4
-
CONTAINER_WEBM
-
CONTAINER_MOV
-
CONTAINER_MKV
-
-
Constructor Details
-
VideoIO
public VideoIO()
-
-
Method Details
-
getVideoIO
Returns the
VideoIOinstance for the current platform, or null when video encoding/decoding is not supported. Prefer#isSupported()for a simple boolean check.Returns
the platform
VideoIO, or null if unsupported -
isSupported
public static boolean isSupported()Convenience test for whether this platform supports the
VideoIOAPI.Returns
true if video encoding/decoding is available
-
getAvailableEncoders
Lists the codecs that can be used for encoding on this device. The set is device dependent and may include hardware accelerated entries (see
VideoCodec#isHardwareAccelerated()).Returns
the available encoder codecs (never null, possibly empty)
-
getAvailableDecoders
Lists the codecs that can be used for decoding on this device.
Returns
the available decoder codecs (never null, possibly empty)
-
isEncoderSupported
Tests whether a given codec id can be used for encoding on this device.
Parameters
codecId: one of the#CODEC_H264style constants
Returns
true if an encoder for the codec exists
-
isDecoderSupported
Tests whether a given codec id can be used for decoding on this device.
Parameters
codecId: one of the#CODEC_H264style constants
Returns
true if a decoder for the codec exists
-
createWriter
Creates a
VideoWriterfor the supplied configuration. Application code normally usesVideoWriterBuilder#build()rather than calling this directly.Parameters
cfg: the encoder configuration
Returns
a ready to use writer
Throws
IOException: if the writer cannot be created
- Throws:
IOException
-
openReader
Opens a
VideoReaderfor the clip at the suppliedcom.codename1.io.FileSystemStoragepath.Parameters
filePath: the FileSystemStorage path of the clip to decode
Returns
a reader positioned at the start of the clip
Throws
IOException: if the clip cannot be opened
- Throws:
IOException
-
openReader
Opens a
VideoReaderfor 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
-
stream: the clip data -
mimeType: the clip mime type (e.g. "video/mp4"), used to pick a file suffix; may be null
Returns
a reader for the clip
Throws
IOException: if the clip cannot be opened
- Throws:
IOException
-
-