# 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 Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `CODEC_AAC`
  Codec id for AAC audio, the most broadly compatible audio codec.
  `static final String`
  `CODEC_AV1`
  Codec id for AV1 video.
  `static final String`
  `CODEC_H264`
  Codec id for H.264 / AVC video, the most broadly compatible video codec.
  `static final String`
  `CODEC_HEVC`
  Codec id for H.265 / HEVC video.
  `static final String`
  `CODEC_OPUS`
  Codec id for Opus audio.
  `static final String`
  `CODEC_PCM`
  Codec id for uncompressed 16 bit PCM audio.
  `static final String`
  `CODEC_VP8`
  Codec id for VP8 video.
  `static final String`
  `CODEC_VP9`
  Codec id for VP9 video.
  `static final String`
  `CONTAINER_MKV`
  Container id for the Matroska (.mkv) container.
  `static final String`
  `CONTAINER_MOV`
  Container id for the QuickTime (.mov) container.
  `static final String`
  `CONTAINER_MP4`
  Container id for the MPEG 4 (.mp4) container.
  `static final String`
  `CONTAINER_WEBM`
  Container id for the WebM (.webm) container.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `VideoIO()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract VideoWriter`
  `createWriter(VideoWriterBuilder cfg)`
  Creates a `VideoWriter` for the supplied configuration.
  `abstract VideoCodec[]`
  `getAvailableDecoders()`
  Lists the codecs that can be used for decoding on this device.
  `abstract VideoCodec[]`
  `getAvailableEncoders()`
  Lists the codecs that can be used for encoding on this device.
  `static VideoIO`
  `getVideoIO()`
  Returns the `VideoIO` instance for the current platform, or null when video encoding/decoding is not supported.
  `boolean`
  `isDecoderSupported(String codecId)`
  Tests whether a given codec id can be used for decoding on this device.
  `boolean`
  `isEncoderSupported(String codecId)`
  Tests whether a given codec id can be used for encoding on this device.
  `static boolean`
  `isSupported()`
  Convenience test for whether this platform supports the `VideoIO` API.
  `VideoReader`
  `openReader(InputStream stream, String mimeType)`
  Opens a `VideoReader` for a clip supplied as a stream.
  `abstract VideoReader`
  `openReader(String filePath)`
  Opens a `VideoReader` for the clip at the supplied `com.codename1.io.FileSystemStorage` path.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### CODEC_H264

    public static final String CODEC_H264
    Codec id for H.264 / AVC video, the most broadly compatible video codec.
    See Also:
      - Constant Field Values

  - ### CODEC_HEVC

    public static final String CODEC_HEVC
    Codec id for H.265 / HEVC video.
    See Also:
      - Constant Field Values

  - ### CODEC_VP8

    public static final String CODEC_VP8
    Codec id for VP8 video.
    See Also:
      - Constant Field Values

  - ### CODEC_VP9

    public static final String CODEC_VP9
    Codec id for VP9 video.
    See Also:
      - Constant Field Values

  - ### CODEC_AV1

    public static final String CODEC_AV1
    Codec id for AV1 video.
    See Also:
      - Constant Field Values

  - ### CODEC_AAC

    public static final String CODEC_AAC
    Codec id for AAC audio, the most broadly compatible audio codec.
    See Also:
      - Constant Field Values

  - ### CODEC_OPUS

    public static final String CODEC_OPUS
    Codec id for Opus audio.
    See Also:
      - Constant Field Values

  - ### CODEC_PCM

    public static final String CODEC_PCM
    Codec id for uncompressed 16 bit PCM audio.
    See Also:
      - Constant Field Values

  - ### CONTAINER_MP4

    public static final String CONTAINER_MP4
    Container id for the MPEG 4 (.mp4) container.
    See Also:
      - Constant Field Values

  - ### CONTAINER_WEBM

    public static final String CONTAINER_WEBM
    Container id for the WebM (.webm) container.
    See Also:
      - Constant Field Values

  - ### CONTAINER_MOV

    public static final String CONTAINER_MOV
    Container id for the QuickTime (.mov) container.
    See Also:
      - Constant Field Values

  - ### CONTAINER_MKV

    public static final String CONTAINER_MKV
    Container id for the Matroska (.mkv) container.
    See Also:
      - Constant Field Values

- ## 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`