Remove Java Vorbis Encoder.

- The same functionality was added to the C version of the Vorbis
  Encoder.

Change-Id: I7c26352db583d99a2d7744cca89f5a7155e55138
diff --git a/JNI/com/google/libvorbis/AudioFrame.java b/JNI/com/google/libvorbis/AudioFrame.java
deleted file mode 100644
index c25cfec..0000000
--- a/JNI/com/google/libvorbis/AudioFrame.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.google.libvorbis;
-
-import java.nio.ByteBuffer;
-
-public class AudioFrame {
-  public long timestamp;
-  public ByteBuffer frame;
-
-  AudioFrame(long time, ByteBuffer data) {
-    timestamp = time;
-    frame = data;
-  }
-}
diff --git a/JNI/com/google/libvorbis/VorbisEncoderConfig.java b/JNI/com/google/libvorbis/VorbisEncoderConfig.java
deleted file mode 100755
index 63613c2..0000000
--- a/JNI/com/google/libvorbis/VorbisEncoderConfig.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package com.google.libvorbis;
-
-/**
- * Class to hold parameters for the Vorbis encoder.
- */
-public class VorbisEncoderConfig {
-  public enum Format {kAudioFormatPcm, kAudioFormatVorbis}
-
-  public Format format_tag;            // Audio format.
-  public short channels;              // Number of channels.
-  public int sample_rate;             // Samples per second.
-  public int bytes_per_second;        // Average bytes per second.
-  public short block_align;           // Atomic audio unit size in bytes.
-  public short bits_per_sample;       // Sample container size.
-
-  // Rate control values. Set the min and max values to |kUseDefault| to
-  // encode at an average bitrate. Use the same value for minimum, average, and
-  // maximum to encode at a constant bitrate. Values are in kilobits.
-  public int average_bitrate;
-  public int minimum_bitrate;
-  public int maximum_bitrate;
-
-  // Advanced Vorbis encoding settings. More information about the effects and
-  // usage of these settings can be found on the documentation page for the
-  // libvorbis function vorbis_encode_ctl:
-  // http://xiph.org/vorbis/doc/vorbisenc/vorbis_encode_ctl.html
-
-  // Selects a quality mode based on |average_bitrate|, and disables libvorbis
-  // rate control. In other words, this allows libvorbis to produce a (somewhat)
-  // variable bitrate.
-  // Note: The flag is ignored when minimum and maximum bitrates are not
-  //       |kUseDefault| or -1.
-  public boolean bitrate_based_quality;
-
-  // Impulse block bias. Valid range is -15.0 to 0.0.
-  public double impulse_block_bias;
-
-  // Hard-lowpass frequency. Valid range is 2 to 99.
-  public double lowpass_frequency;
-
-  public VorbisEncoderConfig() {
-    format_tag = Format.kAudioFormatPcm;
-    channels = 2;
-    bytes_per_second = 0;
-    sample_rate = 44100;
-    block_align = 0;
-    bits_per_sample = 16;
-
-    average_bitrate = 64000;
-    minimum_bitrate = -1;
-    maximum_bitrate = -1;
-
-    bitrate_based_quality = true;
-    impulse_block_bias = -7.5;
-    lowpass_frequency = 50.0;
-  }
-
-  public VorbisEncoderConfig(VorbisEncoderConfig copy) {
-    format_tag = copy.format_tag;
-    channels = copy.channels;
-    bytes_per_second = copy.bytes_per_second;
-    sample_rate = copy.sample_rate;
-    block_align = copy.block_align;
-    bits_per_sample = copy.bits_per_sample;
-
-    average_bitrate = copy.average_bitrate;
-    minimum_bitrate = copy.minimum_bitrate;
-    maximum_bitrate = copy.maximum_bitrate;
-
-    bitrate_based_quality = copy.bitrate_based_quality;
-    impulse_block_bias = copy.impulse_block_bias;
-    lowpass_frequency = copy.lowpass_frequency;
-  }
-
-  public Format format_tag() {
-    return format_tag;
-  }
-
-  public short channels() {
-    return channels;
-  }
-
-  public int sample_rate() {
-    return sample_rate;
-  }
-
-  public int bytes_per_second() {
-    return bytes_per_second;
-  }
-
-  public short block_align() {
-    return block_align;
-  }
-
-  public short bits_per_sample() {
-    return bits_per_sample;
-  }
-}
diff --git a/JNI/com/google/libvorbis/VorbisEncoderWrapper.java b/JNI/com/google/libvorbis/VorbisEncoderWrapper.java
deleted file mode 100755
index 47ef2d4..0000000
--- a/JNI/com/google/libvorbis/VorbisEncoderWrapper.java
+++ /dev/null
@@ -1,251 +0,0 @@
-package com.google.libvorbis;
-
-import com.google.libogg.OggPacket;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.ShortBuffer;
-import java.util.LinkedList;
-import java.util.Queue;
-
-/**
- * This class wraps Vorbis and Ogg JNI
- */
-public class VorbisEncoderWrapper {
-  private VorbisDspState dsp_state_;
-  private VorbisInfo info_;
-  private VorbisBlock block_;
-  private OggPacket ident_packet;
-  private OggPacket comments_packet;
-  private OggPacket setup_packet;
-  VorbisEncoderConfig config = null;
-
-  private long lastGranulepos;
-  private Queue<OggPacket> vorbisPackets;
-
-  public VorbisEncoderWrapper() {
-      info_ = new VorbisInfo();
-      dsp_state_ = new VorbisDspState();
-      block_ = new VorbisBlock();
-      ident_packet = null;
-      comments_packet = null;
-      setup_packet = null;
-      lastGranulepos = 0;
-  }
-
-  public boolean Init(VorbisEncoderConfig configArg) {
-    config = new VorbisEncoderConfig(configArg);
-
-    if (config.channels <= 0 || config.channels > 2)
-      return false;
-
-    if (config.format_tag != VorbisEncoderConfig.Format.kAudioFormatPcm)
-      return false;
-
-    if (config.format_tag == VorbisEncoderConfig.Format.kAudioFormatPcm &&
-        config.bits_per_sample != 16)
-      return false;
-
-    Codec.vorbisInfoInit(info_);
-
-    int status =
-        VorbisEnc.vorbisEncodeSetupManaged(info_, config.channels, config.sample_rate,
-            config.minimum_bitrate, config.average_bitrate, config.maximum_bitrate);
-    if (status != 0)
-      return false;
-
-    if (config.minimum_bitrate == -1 && config.maximum_bitrate == -1 &&
-        config.bitrate_based_quality) {
-      // Enable VBR.
-      if (!CodecControlSet(VorbisEnc.OV_ECTL_RATEMANAGE2_SET, 0)) {
-        return false;
-      }
-    }
-
-    status = VorbisEnc.vorbisEncodeSetupInit(info_);
-    if (status != 0)
-        return false;
-
-    status = Codec.vorbisAnalysisInit(dsp_state_, info_);
-    if (status != 0)
-        return false;
-
-    status = Codec.vorbisBlockInit(dsp_state_, block_);
-    if (status != 0)
-        return false;
-
-    status = GenerateHeaders();
-    if (status != 0)
-      return false;
-
-    config.format_tag = VorbisEncoderConfig.Format.kAudioFormatVorbis;
-    vorbisPackets = new LinkedList<OggPacket>();
-    return true;
-  }
-
-  public ByteBuffer getCodecPrivate() {
-    // Perform minimal private data validation.
-    if (ident_packet == null || comments_packet == null || setup_packet == null)
-      return null;
-
-    if (ident_packet.getBytes() > 255 || comments_packet.getBytes() > 255)
-      return null;
-
-    final long data_length =
-        ident_packet.getBytes() + comments_packet.getBytes() + setup_packet.getBytes();
-
-    // Calculate total bytes of storage required for the private data chunk.
-    // 1 byte to store header count (total headers - 1 = 2).
-    // 1 byte each for ident and comment length values.
-    // The length of setup data is implied by the total length.
-    final int header_length = 1 + 1 + 1 + (int)data_length;
-    ByteBuffer data = ByteBuffer.allocate(header_length);
-
-    // Write header count. As above, number of headers - 1.
-    data.put((byte)2);
-
-    // Write ident length, comment length.
-    data.put((byte)ident_packet.getBytes());
-    data.put((byte)comments_packet.getBytes());
-
-    // Write the data blocks.
-    byte[] indentData = ident_packet.getPacketData();
-    data.put(indentData);
-
-    byte[] commentsData = comments_packet.getPacketData();
-    data.put(commentsData);
-
-    byte[] setupData = setup_packet.getPacketData();
-    data.put(setupData);
-
-    return data;
-  }
-
-  public boolean encodeAudio(byte[] pcmArray) {
-    // TODO(fgalligan): Check mod block_align
-
-    final int channels = config.channels;
-    final int num_blocks = pcmArray.length / config.block_align;
-
-    ByteBuffer byteBuffer = ByteBuffer.wrap(pcmArray);
-    byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
-    ShortBuffer sampleBuffer = byteBuffer.asShortBuffer();
-
-    float[][] float2dArray = new float[channels][num_blocks];
-
-    for (int i = 0; i < num_blocks; ++i) {
-      for (int c = 0; c < channels; ++c) {
-        short sample = sampleBuffer.get();
-        float2dArray[c][i] = sample / 32768.f;
-      }
-    }
-
-    Codec.vorbisAnalysisBuffer(dsp_state_, float2dArray);
-    int status = Codec.vorbisAnalysisWrote(dsp_state_, num_blocks);
-    if (status != 0)
-      return false;
-    return true;
-  }
-
-  public AudioFrame readCompressedAudio() {
-    if (samplesEncoded()) {
-      // There's a compressed block available-- give libvorbis a chance to
-      // optimize distribution of data for the current encode settings.
-      OggPacket packet = new OggPacket();
-      int status = Codec.vorbisAnalysis(block_, packet);
-      if (status != 0)
-        return null;
-
-      status = Codec.vorbisBitrateAddblock(block_);
-      if (status != 0)
-        return null;
-
-      while ((status = Codec.vorbisBitrateFlushpacket(dsp_state_, packet)) == 1) {
-        //Using the add method to add items.
-        //Should anything go wrong an exception will be thrown.
-        if (packet.getGranulepos() > 0)
-          vorbisPackets.add(packet);
-      }
-    }
-
-    // Calculate size of data.
-    int totalSize = 0;
-    for(OggPacket p : vorbisPackets){
-      totalSize += p.getBytes();
-    }
-    if (totalSize == 0)
-      return null;
-
-    ByteBuffer data = ByteBuffer.allocate(totalSize);
-
-    long timestamp = (long)samplesToMilliseconds(lastGranulepos);
-
-    while (vorbisPackets.size() > 0) {
-      OggPacket packet = vorbisPackets.remove();
-      lastGranulepos = packet.getGranulepos();
-
-      byte[] packetData = packet.getPacketData();
-      data.put(packetData);
-    }
-
-    AudioFrame frame = new AudioFrame(timestamp, data);
-    return frame;
-  }
-
-  //When |SamplesAvailable()| returns true, the user must consume all samples
-  //made available by libvorbis. Any compressed samples left unconsumed will be
-  //lost.
-  private boolean samplesEncoded() {
-    final int kSamplesAvailable = 1;
-    int status = Codec.vorbisAnalysisBlockout(dsp_state_, block_);
-    if (status == kSamplesAvailable) {
-      return true;
-    }
-    return false;
-  }
-
-  private int GenerateHeaders() {
-    VorbisComment comments = new VorbisComment();
-    Codec.vorbisCommentInit(comments);
-
-    // Add app name and version to vorbis comments.
-    String encoder_id = "WebM JNI bindings";
-    String kVorbisEncoderTag = "encoder";
-
-    Codec.vorbisCommentAddTag(comments, kVorbisEncoderTag, encoder_id);
-
-    // Generate the vorbis header packets.
-    ident_packet = new OggPacket();
-    comments_packet = new OggPacket();
-    setup_packet = new OggPacket();
-
-    int status =
-        Codec.vorbisAnalysisHeaderout(dsp_state_, comments, ident_packet, comments_packet,
-            setup_packet);
-    if (status != 0) return status;
-    return 0;
-  }
-
-  private boolean CodecControlSet(int control_id, int val) {
-    int status = 0;
-    if (control_id == VorbisEnc.OV_ECTL_RATEMANAGE2_SET && val == 0) {
-      // Special case disabling rate control-- libvorbis expects a NULL
-      // pointer.
-      status = VorbisEnc.vorbisEncodeCtlSetNull(info_, control_id);
-    } else {
-      status = VorbisEnc.vorbisEncodeCtlSetInt(info_, control_id, val);
-    }
-    if (status != 0)
-      return false;
-    return true;
-  }
-
-  private double samplesToMilliseconds(long numSamples) {
-    final double sample_rate = config.sample_rate;
-    double seconds = 0.0;
-    if (sample_rate != 0) {
-      seconds = numSamples / sample_rate;
-    }
-    return seconds * 1000.0;
-  }
-}
diff --git a/JNI/examples/EncodeWavJavaExample.java b/JNI/examples/EncodeWavJavaExample.java
deleted file mode 100755
index 5394609..0000000
--- a/JNI/examples/EncodeWavJavaExample.java
+++ /dev/null
@@ -1,125 +0,0 @@
-import java.io.File;
-import java.nio.ByteBuffer;
-
-import com.google.libvorbis.AudioFrame;
-import com.google.libvorbis.VorbisEncoderConfig;
-import com.google.libvorbis.VorbisEncoderWrapper;
-import com.google.libwebm.mkvmuxer.AudioTrack;
-import com.google.libwebm.mkvmuxer.MkvWriter;
-import com.google.libwebm.mkvmuxer.Segment;
-import com.google.libwebm.mkvmuxer.SegmentInfo;
-import com.google.utils.WavReader;
-
-public class EncodeWavJavaExample {
-  /*
-   * This function will encode an audio WebM file. |wavInputName| filename of the source audio. The
-   * source audio must be a WAV file with raw PCM data. |webmOutputName| filename of the WebM
-   * file to write to. Returns true on success. If there is an error, |error| will be set to a
-   * descriptive string.
-   */
-  static public boolean encodeWavJavaExample(String wavInputName, String webmOutputName,
-                                             StringBuilder error) {
-    VorbisEncoderConfig vorbisConfig = null;
-    VorbisEncoderWrapper vorbisEncoder = null;
-    MkvWriter mkvWriter = null;
-
-    try {
-      File pcmFile = new File(wavInputName);
-      WavReader wavReader = null;
-      try {
-        wavReader = new WavReader(pcmFile);
-      } catch (Exception e) {
-        error.append("Could not create wav reader.");
-        return false;
-      }
-
-      vorbisConfig = new VorbisEncoderConfig();
-      vorbisConfig.channels = wavReader.nChannels();
-      vorbisConfig.sample_rate = wavReader.nSamplesPerSec();
-      vorbisConfig.bytes_per_second = wavReader.nAvgBytesPerSec();
-      vorbisConfig.block_align = wavReader.nBlockAlign();
-      vorbisConfig.bits_per_sample = wavReader.wBitsPerSample();
-
-      vorbisEncoder = new VorbisEncoderWrapper();
-      if (!vorbisEncoder.Init(vorbisConfig)) {
-        error.append("Could not initialize Vorbis encoder.");
-        return false;
-      }
-
-      mkvWriter = new MkvWriter();
-      if (!mkvWriter.open(webmOutputName)) {
-        error.append("WebM Output name is invalid or error while opening.");
-        return false;
-      }
-
-      Segment muxerSegment = new Segment();
-      if (!muxerSegment.init(mkvWriter)) {
-        error.append("Could not initialize muxer segment.");
-        return false;
-      }
-
-      SegmentInfo muxerSegmentInfo = muxerSegment.getSegmentInfo();
-      muxerSegmentInfo.setWritingApp("wavEncodeSample");
-
-      // Add Audio Track
-      int channels = vorbisConfig.channels;
-      int sampleRate = vorbisConfig.sample_rate;
-      long newAudioTrackNumber = muxerSegment.addAudioTrack(sampleRate, channels, 0);
-      if (newAudioTrackNumber == 0) {
-        error.append("Could not add audio track.");
-        return false;
-      }
-
-      AudioTrack muxerTrack = (AudioTrack) muxerSegment.getTrackByNumber(newAudioTrackNumber);
-      if (muxerTrack == null) {
-        error.append("Could not get audio track.");
-        return false;
-      }
-
-      ByteBuffer privateData = vorbisEncoder.getCodecPrivate();
-      if (!muxerTrack.setCodecPrivate(privateData.array())) {
-        error.append("Could not add audio private data.");
-        return false;
-      }
-
-      final int maxSamplesToRead = 1000;
-      int samplesLeft = 0;
-      while ((samplesLeft = wavReader.samplesRemaining()) > 0) {
-        byte[] pcmArray = null;
-        int samplesToRead = Math.min(samplesLeft, maxSamplesToRead);
-        try {
-          pcmArray = wavReader.readSamples(samplesToRead);
-        } catch (Exception e) {
-          error.append("Could not read samples.");
-          return false;
-        }
-
-        if (!vorbisEncoder.encodeAudio(pcmArray)) {
-          error.append("Error encoding samples.");
-          return false;
-        }
-
-        AudioFrame frame = null;
-        while ((frame = vorbisEncoder.readCompressedAudio()) != null) {
-          if (!muxerSegment.addFrame(
-              frame.frame.array(), newAudioTrackNumber, frame.timestamp * 1000000, true)) {
-            error.append("Could not add audio frame.");
-            return false;
-          }
-        }
-      }
-
-      if (!muxerSegment.finalizeSegment()) {
-        error.append("Finalization of segment failed.");
-        return false;
-      }
-
-    } finally {
-      if (mkvWriter != null) {
-        mkvWriter.close();
-      }
-    }
-
-    return true;
-  }
-}
diff --git a/JNI/examples/EncodeY4mWavJavaExample.java b/JNI/examples/EncodeY4mWavJavaExample.java
deleted file mode 100755
index 661697a..0000000
--- a/JNI/examples/EncodeY4mWavJavaExample.java
+++ /dev/null
@@ -1,223 +0,0 @@
-import java.io.File;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-
-import com.google.libvorbis.AudioFrame;
-import com.google.libvorbis.VorbisEncoderConfig;
-import com.google.libvorbis.VorbisEncoderWrapper;
-import com.google.libvpx.LibVpxEnc;
-import com.google.libvpx.LibVpxEncConfig;
-import com.google.libvpx.Rational;
-import com.google.libvpx.VpxCodecCxPkt;
-import com.google.libwebm.mkvmuxer.AudioTrack;
-import com.google.libwebm.mkvmuxer.MkvWriter;
-import com.google.libwebm.mkvmuxer.Segment;
-import com.google.libwebm.mkvmuxer.SegmentInfo;
-import com.google.utils.WavReader;
-import com.google.utils.Y4MReader;
-
-public class EncodeY4mWavJavaExample {
-  /*
-   * This function will encode an audio and video WebM file. |y4mName| filename of the source video.
-   * The source video must be a Y4M file with raw i420 frames. |wavName| filename of the source
-   * audio. The source audio must be a WAV file with raw PCM data. |webmOutputName| filename of the
-   * WebM file to write to. |framesToEncode| is the number of video frames to encode before
-   * stopping. Returns true on success. If there is an error, |error| will be set to a descriptive
-   * string.
-   */
-  static public boolean encodeY4mWavJavaExample(String y4mName, String wavName,
-                                                String webmOutputName, int framesToEncode,
-                                                StringBuilder error) {
-    LibVpxEncConfig vpxConfig = null;
-    LibVpxEnc vpxEncoder = null;
-    VorbisEncoderConfig vorbisConfig = null;
-    VorbisEncoderWrapper vorbisEncoder = null;
-    MkvWriter mkvWriter = null;
-
-    try {
-      File y4mFile = new File(y4mName);
-      Y4MReader y4mReader;
-      try {
-        y4mReader = new Y4MReader(y4mFile);
-      } catch (IOException e) {
-        error.append("Error creating y4m file:" + y4mName + " : " + e);
-        return false;
-      }
-
-      vpxConfig = new LibVpxEncConfig(y4mReader.getWidth(), y4mReader.getHeight());
-      vpxEncoder = new LibVpxEnc(vpxConfig);
-
-      // libwebm expects nanosecond units
-      vpxConfig.setTimebase(1, 1000000000);
-      Rational timeBase = vpxConfig.getTimebase();
-      Rational timeMultiplier = timeBase.multiply(y4mReader.getFrameRate()).reciprocal();
-      int framesIn = 1;
-
-      File pcmFile = new File(wavName);
-      WavReader wavReader = null;
-      try {
-        wavReader = new WavReader(pcmFile);
-      } catch (Exception e) {
-        error.append("Error creating wav file:" + wavName);
-        return false;
-      }
-
-      vorbisConfig = new VorbisEncoderConfig();
-      vorbisConfig.channels = wavReader.nChannels();
-      vorbisConfig.sample_rate = wavReader.nSamplesPerSec();
-      vorbisConfig.bytes_per_second = wavReader.nAvgBytesPerSec();
-      vorbisConfig.block_align = wavReader.nBlockAlign();
-      vorbisConfig.bits_per_sample = wavReader.wBitsPerSample();
-
-      vorbisEncoder = new VorbisEncoderWrapper();
-      if (!vorbisEncoder.Init(vorbisConfig)) {
-        error.append("Could not initialize Vorbis encoder.");
-        return false;
-      }
-
-      mkvWriter = new MkvWriter();
-      if (!mkvWriter.open(webmOutputName)) {
-        error.append("WebM Output name is invalid or error while opening.");
-        return false;
-      }
-
-      Segment muxerSegment = new Segment();
-      if (!muxerSegment.init(mkvWriter)) {
-        error.append("Could not initialize muxer segment.");
-        return false;
-      }
-
-      SegmentInfo muxerSegmentInfo = muxerSegment.getSegmentInfo();
-      muxerSegmentInfo.setWritingApp("y4mwavEncodeSample");
-
-      // Add video Track
-      long newVideoTrackNumber =
-          muxerSegment.addVideoTrack(vpxConfig.getWidth(), vpxConfig.getHeight(), 0);
-      if (newVideoTrackNumber == 0) {
-        error.append("Could not add video track.");
-        return false;
-      }
-
-      // Add audio Track
-      int channels = vorbisConfig.channels;
-      int sampleRate = vorbisConfig.sample_rate;
-      long newAudioTrackNumber = muxerSegment.addAudioTrack(sampleRate, channels, 0);
-      if (newAudioTrackNumber == 0) {
-        error.append("Could not add audio track.");
-        return false;
-      }
-
-      AudioTrack muxerTrack = (AudioTrack) muxerSegment.getTrackByNumber(newAudioTrackNumber);
-      if (muxerTrack == null) {
-        error.append("Could not get audio track.");
-        return false;
-      }
-
-      ByteBuffer privateData = vorbisEncoder.getCodecPrivate();
-      if (!muxerTrack.setCodecPrivate(privateData.array())) {
-        error.append("Could not add audio private data.");
-        return false;
-      }
-
-      final int maxSamplesToRead = 1000;
-      AudioFrame audioFrame = null;
-      ArrayList<VpxCodecCxPkt> encPkt = null;
-      VpxCodecCxPkt pkt = null;
-      int pktIndex = 0;
-      boolean audioDone = false;
-      boolean videoDone = false;
-      boolean encoding = true;
-      while (encoding) {
-        // Prime the audio encoder.
-        while (audioFrame == null) {
-          final int samplesLeft = wavReader.samplesRemaining();
-          final int samplesToRead = Math.min(samplesLeft, maxSamplesToRead);
-          if (samplesToRead > 0) {
-            // Read raw audio data.
-            byte[] pcmArray = null;
-            try {
-              pcmArray = wavReader.readSamples(samplesToRead);
-            } catch (Exception e) {
-              error.append("Could not read audio samples.");
-              return false;
-            }
-
-            if (!vorbisEncoder.encodeAudio(pcmArray)) {
-              error.append("Error encoding audio samples.");
-              return false;
-            }
-
-            audioFrame = vorbisEncoder.readCompressedAudio();
-
-            // Video is in nanoseconds.
-            if (audioFrame != null) audioFrame.timestamp *= 1000000;
-          } else {
-            audioDone = true;
-            break;
-          }
-        }
-
-        if (encPkt == null) {
-          // Read raw video data.
-          byte[] rawVideoArray = y4mReader.getUncompressedFrame();
-          if (rawVideoArray != null) {
-            long frameStart = timeMultiplier.multiply(framesIn - 1).toLong();
-            long nextFrameStart = timeMultiplier.multiply(framesIn++).toLong();
-
-            encPkt = vpxEncoder.encodeFrame(rawVideoArray, LibVpxEnc.VPX_IMG_FMT_I420, frameStart, nextFrameStart - frameStart);
-
-            // Get the first vpx encoded frame.
-            pktIndex = 0;
-            pkt = encPkt.get(pktIndex++);
-          } else {
-            videoDone = true;
-          }
-        }
-
-        if ((audioDone && videoDone) || framesIn >= framesToEncode) break;
-
-        if (!videoDone && (audioDone || pkt.pts <= audioFrame.timestamp)) {
-          final boolean isKey = (pkt.flags & 0x1) == 1;
-          if (!muxerSegment.addFrame(pkt.buffer, newVideoTrackNumber, pkt.pts, isKey)) {
-            error.append("Could not add video frame.");
-            return false;
-          }
-
-          // Get the next vpx encoded frame.
-          if (pktIndex < encPkt.size()) {
-            pkt = encPkt.get(pktIndex++);
-          } else {
-            // Read the next raw video frame.
-            encPkt = null;
-          }
-        } else if (!audioDone) {
-          if (!muxerSegment.addFrame(
-              audioFrame.frame.array(), newAudioTrackNumber, audioFrame.timestamp, true)) {
-            error.append("Could not add audio frame.");
-            return false;
-          }
-
-          // Read the next compressed audio frame.
-          audioFrame = vorbisEncoder.readCompressedAudio();
-          if (audioFrame != null) audioFrame.timestamp *= 1000000;
-        }
-      }
-
-      if (!muxerSegment.finalizeSegment()) {
-        error.append("Finalization of segment failed.");
-        return false;
-      }
-
-    } catch (Exception e) {
-      error.append("Caught error in main encode loop.");
-      return false;
-    } finally {
-      if (mkvWriter != null) {
-        mkvWriter.close();
-      }
-    }
-
-    return true;
-  }
-}