2

Anybody have any idea about,How to handle unstructured data like Audio,Video and Images using Hbase.I tried for this alot but i didn't get any idea.please any help is appreciated.

Ram Ghadiyaram
  • 28,239
  • 13
  • 95
  • 121
user6608138
  • 381
  • 1
  • 4
  • 20
  • What do you mean by "handling"? If possible,please share your usecase for clarity. – Abhishek Kumar Dec 16 '16 at 05:02
  • we are getting images/videos from cameras.Just we have to store and retrieve those images/videos from hadoop,no need of any processing. For this which one is better and How to do this one. – user6608138 Dec 16 '16 at 05:42
  • This has many answers and helpful links [link] http://stackoverflow.com/questions/16546040/store-images-videos-into-hadoop-hdfs [link]http://stackoverflow.com/questions/31399843/how-to-store-and-retrieve-video-files-and-image-files-in-hbase-table [link]https://www.quora.com/How-can-I-load-and-retrieve-the-images-from-and-to-the-Hadoop-Hive-HDFS-and-HBase-Where-can-I-get-an-example-of-this-being-implemented [link]https://www.quora.com/Which-is-best-storing-images-in-Hadoop-or-storing-it-in-HBase-and-creating-an-index-to-it-How-can-we-do-that – Abhishek Kumar Dec 16 '16 at 07:52
  • Thank for your reply.I need sample code for inserting and accessing images/videos in hbase.If you have, can you please share with me.I tried but its not displaying anything in hbase shell. – user6608138 Dec 16 '16 at 08:20
  • anybody have any idea how to store and access please share with me.I worked on this alot.But i didn't get any proper answer for this.any help is appreciated. – user6608138 Dec 16 '16 at 13:58
  • just check below snippet which uses pure java – Ram Ghadiyaram Dec 16 '16 at 14:59
  • Was my answer helpful? – Ram Ghadiyaram Dec 19 '16 at 05:46
  • yes,this is more helpfull for me.Thanks alot.......... – user6608138 Dec 19 '16 at 06:26

1 Answers1

1
  • Option 1: convert image to byte array and you can prepare put request and insert to table. Similarly audio and video files also can be achieved.

See 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;
    }
  • Option 2 : You can do that in below way using Apache commons lang API. probably this is best option than above which will be applicable to all objects including image/audio/video etc.. This can be used NOT ONLY for hbase you can save it in hdfs as well

See my answer for more details.

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

for deserializing, you can do this static Object deserialize(byte[] objectData)

see the doc in above link..

Example usage of the 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();
    }
  }
}

Note :jar of apache commons lang always available in hadoop cluster.(not external dependency)

Community
  • 1
  • 1
Ram Ghadiyaram
  • 28,239
  • 13
  • 95
  • 121
  • can i pass this byte[] mediaInBytes as an value of put cmd in hbase column. – user6608138 Dec 19 '16 at 07:16
  • I am poor in wrtiting java code,can you please tell me how and where to pass image name as an argument,and how to pass this byte[] as an arg to hbase column value. – user6608138 Dec 19 '16 at 07:33