public ImageToMJPEGMOVMuxer(SeekableByteChannel ch, AudioFormat af, int framesPerSecond)
      throws IOException {

    this.ch = ch;
    this.af = af;
    this.framesPerSecond = framesPerSecond;

    // Muxer that will store the encoded frames
    muxer = new WebOptimizedMP4Muxer(ch, Brand.MP4, 4096 * 4);

    // Add video track to muxer
    videoTrack = muxer.addTrack(TrackType.VIDEO, framesPerSecond);
    muxer.addTimecodeTrack(framesPerSecond);
    videoTrack.setTgtChunkDuration(new Rational(3, 1), Unit.SEC);

    if (af != null) audioTrack = muxer.addPCMAudioTrack(af);
  }
  public void finish() throws IOException {

    videoTrack.addSampleEntry(MP4Muxer.videoSampleEntry(imageType, size, ENCODER_NAME));

    // Write MP4 header and finalize recording
    if (af != null) audioTrack.addSampleEntry(MP4Muxer.audioSampleEntry(af));

    muxer.writeHeader();
    NIOUtils.closeQuietly(ch);
  }