Example #1
0
    public void readTsFile(SeekableByteChannel ch) throws IOException {
      ch.position(0);
      ByteBuffer buf = ByteBuffer.allocate(BUFFER_SIZE);

      for (long pos = ch.position(); ch.read(buf) != -1; pos = ch.position()) {
        buf.flip();
        while (buf.hasRemaining()) {
          ByteBuffer tsBuf = NIOUtils.read(buf, 188);
          pos += 188;
          Assert.assertEquals(0x47, tsBuf.get() & 0xff);
          int guidFlags = ((tsBuf.get() & 0xff) << 8) | (tsBuf.get() & 0xff);
          int guid = (int) guidFlags & 0x1fff;

          int payloadStart = (guidFlags >> 14) & 0x1;
          int b0 = tsBuf.get() & 0xff;
          int counter = b0 & 0xf;
          if ((b0 & 0x20) != 0) {
            NIOUtils.skip(tsBuf, tsBuf.get() & 0xff);
          }
          boolean sectionSyntax =
              payloadStart == 1 && (getRel(tsBuf, getRel(tsBuf, 0) + 2) & 0x80) == 0x80;
          if (sectionSyntax) {
            NIOUtils.skip(tsBuf, tsBuf.get() & 0xff);
          }
          if (!onPkt(guid, payloadStart == 1, tsBuf, pos - tsBuf.remaining())) return;
        }
        buf.flip();
      }
    }
Example #2
0
  public void write(Chunk chunk) throws IOException {
    SeekableByteChannel input = getInput(chunk);
    input.position(chunk.getOffset());
    long pos = out.position();

    out.write(NIOUtils.fetchFrom(input, (int) chunk.getSize()));
    offsets[curChunk++] = pos;
  }
Example #3
0
  public static void main(String[] args) throws Exception {
    if (args.length < 2) {
      System.out.println(
          "Syntax: <in.264> <out.mp4>\n"
              + "\tWhere:\n"
              + "\t-q\tLook for stream parameters only in the beginning of stream");
      return;
    }

    File in = new File(args[0]);
    File out = new File(args[1]);

    SeekableByteChannel file = writableFileChannel(out);
    MP4Muxer muxer = new MP4Muxer(file);
    FramesMP4MuxerTrack track = muxer.addTrackForCompressed(TrackType.VIDEO, 25);

    mux(track, in);

    muxer.writeHeader();

    file.close();
  }