Class VideoIO

java.lang.Object
com.codename1.media.VideoIO

public abstract class VideoIO extends Object

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 Details

  • Constructor Details

    • VideoIO

      public VideoIO()
  • Method Details

    • getVideoIO

      public static VideoIO getVideoIO()

      Returns the VideoIO instance 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 VideoIO API.

      Returns

      true if video encoding/decoding is available

    • getAvailableEncoders

      public abstract VideoCodec[] 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

      public abstract VideoCodec[] getAvailableDecoders()

      Lists the codecs that can be used for decoding on this device.

      Returns

      the available decoder codecs (never null, possibly empty)

    • isEncoderSupported

      public boolean isEncoderSupported(String codecId)

      Tests whether a given codec id can be used for encoding on this device.

      Parameters
      • codecId: one of the #CODEC_H264 style constants
      Returns

      true if an encoder for the codec exists

    • isDecoderSupported

      public boolean isDecoderSupported(String codecId)

      Tests whether a given codec id can be used for decoding on this device.

      Parameters
      • codecId: one of the #CODEC_H264 style constants
      Returns

      true if a decoder for the codec exists

    • createWriter

      public abstract VideoWriter createWriter(VideoWriterBuilder cfg) throws IOException

      Creates a VideoWriter for the supplied configuration. Application code normally uses VideoWriterBuilder#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

      public abstract VideoReader openReader(String filePath) throws IOException

      Opens a VideoReader for the clip at the supplied com.codename1.io.FileSystemStorage path.

      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

      public VideoReader openReader(InputStream stream, String mimeType) throws IOException

      Opens a VideoReader 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
      • 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