public static void main(String[] args) throws Exception {
    TransportStream stream = new TransportStream(new SourceURL("http://cb00.virtual/rtl.ts"));
    stream.setLimit(100L);
    stream.init();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Data item = stream.read();
    int items = 0;
    long bytesWritten = 0L;

    while (item != null) {
      // log.info("item: {}", item);

      int pid = (Integer) item.get("packet:pid");
      if (pid == 0) {

        if (bytesWritten > 0) {
          log.info("Closing old block...");
          baos.close();

          File file =
              new File("/Volumes/RamDisk/video-block-" + System.currentTimeMillis() + ".ts");
          FileOutputStream fos = new FileOutputStream(file);
          fos.write(baos.toByteArray());
          fos.close();
          log.info("Write TS chunk of size {} to {}", bytesWritten, file);
          baos = new ByteArrayOutputStream();
          bytesWritten = 0;
        }
      }

      if (baos != null) {
        byte[] data = (byte[]) item.get("packet:data");
        baos.write(data);
        bytesWritten += data.length;
      }

      items++;
      item = stream.read();
    }

    if (baos != null) {
      baos.close();
    }

    log.info("{} items read.", items);
    stream.close();
  }
Example #2
0
  @Override
  public Data process(Data data) {

    Data item = DataFactory.create();
    item.put("time", LocalDateTime.now().toString());

    String[] evKeys = {"@stream"};
    for (String key : evKeys) {
      if (data.containsKey(key)) {
        item.put(key, data.get(key));
      }
    }

    // add objects by specified keys to data item
    for (String key : keys) {
      item.put(key, data.get(key));
    }

    try {
      if (writeBlock && !firstLine) {
        bw.write(",");
      }
      bw.write(gson.toJson(item));

      bw.newLine();
      bw.flush();
      firstLine = false;
    } catch (IOException ioex) {
      ioex.printStackTrace();
    }
    return data;
  }
  @Override
  public Data process(Data item, ImageRGB img) {

    final ImageRGB borderimage = new ImageRGB(img.getWidth(), img.getHeight());

    // Setting outer pixels to white
    for (int x = 0; x < borderimage.getWidth(); x++) {
      borderimage.setRGB(x, 0, 255, 255, 255);
      borderimage.setRGB(x, borderimage.getHeight() - 1, 255, 255, 255);
    }
    for (int y = 1; y < borderimage.getHeight() - 1; y++) {
      borderimage.setRGB(0, y, 255, 255, 255);
      borderimage.setRGB(borderimage.getWidth() - 1, y, 255, 255, 255);
    }

    // Compute borders for all inner pixels
    // border= black, no border= white
    for (int x = 1; x < img.getWidth() - 1; x++) {
      for (int y = 1; y < img.getHeight() - 1; y++) {

        int sameneighbors = 0;
        if (img.getRGB(x, y) == img.getRGB(x - 1, y)) {
          sameneighbors++;
        }
        if (img.getRGB(x, y) == img.getRGB(x + 1, y)) {
          sameneighbors++;
        }
        if (img.getRGB(x, y) == img.getRGB(x, y - 1)) {
          sameneighbors++;
        }
        if (img.getRGB(x, y) == img.getRGB(x, y + 1)) {
          sameneighbors++;
        }

        if (sameneighbors >= 4 - tolerance) {
          borderimage.setRGB(x, y, 255, 255, 255);
        } else {
          borderimage.setRGB(x, y, 0, 0, 0);
        }
      }
    }

    item.put(output, borderimage);
    return item;
  }