Class Y4mWriter

java.lang.Object
limn.video.decode.Y4mWriter

public final class Y4mWriter extends Object
Writes what a source produces as a YUV4MPEG2 file: the counterpart that makes Y4mDecoder verifiable, and the only way to get a real video file out of this project without shipping one.

It exists because no media may be committed to this repository. A test that needs a file writes one first, from a source whose every sample it can predict, and reads it back; the assertion is then about the reader and the writer rather than about a blob someone downloaded once. It is also how a picture leaves the process for a human to look at, since the format is what every video tool reads.

Two things do not survive the trip, and both are the container's limits rather than this writer's. YUV4MPEG2 has no way to say which luma/chroma matrix a stream was encoded with, so a BT.601 stream written here reads back as unsignalled; only the range is carried, through FFmpeg's XCOLORRANGE extension, and only when the source signalled one. And there is no tag for a two-plane layout, so PixelFormat.NV12 is refused rather than silently de-interleaved into something whose samples would no longer be the source's.

  • Method Details

    • write

      public static int write(Path file, VideoStreamSource source, int maxFrames)
      Drains source into file, creating or truncating it.

      Every picture is released as soon as it is written, so a source with a single slot works. VideoStreamSource.Read.PENDING is answered by asking again (the caller holds nothing), and a source that only ever answers that is abandoned rather than spun on forever.

      Parameters:
      maxFrames - most pictures to write, at least 1. A source that never ends needs this; a finite one stops at its own end, whichever comes first.
      Returns:
      pictures written
      Throws:
      UnsupportedOperationException - if the source's layout has no YUV4MPEG2 tag
      IllegalStateException - if the source answers PENDING indefinitely
      UncheckedIOException - if the file cannot be written
      NullPointerException - if file or source is null
      IllegalArgumentException - if maxFrames is below 1