使用 hbase 处理图像、视频和音频类型

Handling Images,Video and audio types using hbase

任何人都知道如何使用 Hbase.I 处理非结构化数据,如音频、视频和图像,为此尝试了很多,但我没有得到任何 idea.please 任何帮助表示赞赏。

  • 选项1:将图像转换为字节数组,您可以准备put请求并插入到table。同样也可以实现音视频文件。

参见 https://docs.oracle.com/javase/7/docs/api/javax/imageio/package-summary.html


import javax.imageio.ImageIO;

/*       * Convert an image to a byte array
         */
    private byte[] convertImageToByteArray (String ImageName)throws IOException {

        byte[] imageInByte;
        BufferedImage originalImage = ImageIO.read(new File(ImageName));

        // convert BufferedImage to byte array
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(originalImage, "jpg", baos);
        imageInByte = baos.toByteArray();
        baos.close();

        return imageInByte;
    }
  • 选项 2:您可以使用 Apache commons lang API. 通过以下方式执行此操作,这可能是比上面更好的选项,它将适用于所有对象,包括 image/audio/video 等。这不仅可以用于 hbase 您还可以将其保存在 hdfs 中

有关详细信息,请参阅我的

例如:byte[] mediaInBytes = org.apache.commons.lang.SerializationUtils.serialize(Serializable obj)

对于反序列化,你可以这样做static Object deserialize(byte[] objectData)

请参阅上面的文档 link..

SerializationUtils

的用法示例
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.commons.lang.SerializationUtils;

public class SerializationUtilsTest {
  public static void main(String[] args) {
    try {
      // File to serialize object to it can be your image or any media file
      String fileName = "testSerialization.ser";

      // New file output stream for the file
      FileOutputStream fos = new FileOutputStream(fileName);

      // Serialize String
      SerializationUtils.serialize("SERIALIZE THIS", fos);
      fos.close();

      // Open FileInputStream to the file
      FileInputStream fis = new FileInputStream(fileName);

      // Deserialize and cast into String
      String ser = (String) SerializationUtils.deserialize(fis);
      System.out.println(ser);
      fis.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

注意:apache commons lang 的 jar 在 hadoop 集群中始终可用。(不是外部依赖项