使用hbase处理图像,视频和音频类型 [英] Handling Images,Video and audio types using hbase
问题描述
任何人有任何想法,如何处理非结构化数据,如音频,视频和图像使用Hbase.I尝试了很多,但我没有得到任何idea.please任何帮助表示赞赏。$ b $选项1:将图像转换为字节数组,您可以准备放入请求并插入到表格中。同样的音频和视频文件也可以实现。
请参阅 https://docs.oracle.com/javase/7/docs/api/javax/imageio/ package-summary.html
import javax.imageio.ImageIO ;
$ b $ * * *将图像转换为字节数组
* /
private byte [] convertImageToByteArray(String ImageName)throws IOException {
byte [ ] imageInByte;
BufferedImage originalImage = ImageIO.read(new File(ImageName));
//将BufferedImage转换为字节数组
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage,jpg,baos);
imageInByte = baos.toByteArray();
baos.close();
return imageInByte;
}
-
选项2:您可以做以下面的方式使用Apache commons lang API。可能这是最好的选择比以上将适用于包括图像/音频/视频等所有对象。这可以不仅用于hbase你可以保存在hdfs以及
请参阅我的回答更多细节。
例如: byte [] mediaInBytes = org.apache.commons.lang.SerializationUtils.serialize(Serializable obj)
对于反序列化,您可以这样做 static Object deserialize(byte [] objectData)
请参阅上述链接中的文档。
SerializationUtils
import java.io.FileInputStr EAM;
import java.io.FileOutputStream;
import org.apache.commons.lang.SerializationUtils;
public class SerializationUtilsTest {
public static void main(String [] args){
try {
//序列化对象的文件可以是您的图片或任何媒体文件
String fileName =testSerialization.ser;
//文件的新文件输出流
FileOutputStream fos = new FileOutputStream(fileName);
//序列化字符串
SerializationUtils.serialize(SERIALIZE THIS,fos);
fos.close();
//将FileInputStream打开到文件
FileInputStream fis = new FileInputStream(fileName);
//反序列化并转换为字符串
String ser =(String)SerializationUtils.deserialize(fis);
System.out.println(ser);
fis.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
注意:jar of apache commons lang始终在hadoop集群中可用( not external dependency )
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.
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)
这篇关于使用hbase处理图像,视频和音频类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!