`
andy_ghg
  • 浏览: 291153 次
  • 性别: Icon_minigender_1
  • 来自: 扬州
社区版块
存档分类
最新评论

Hadoop学习笔记-读取视频流给Flash播放器

 
阅读更多
首先下载一个测试用的Flash视频播放器Strobe Media Playback

http://osmf.org/strobe_mediaplayback.html

然后在hadoop中添加一个flv文件,我在此处是demo.flv,在根路径下。命令行代码:

bin/hadoop fs -copyFromLocal /Users/alex/Desktop/test.flv hdfs://localhost:9000/demo.flv

打开localhost:50070验证是否成功将视频放入到hdfs中。

然后在MyEclipse中新增一个web工程,将hadoop所需jar包加入到类路径中。新建一个Servlet,我在xml中配置其名字为getMov主要代码如下:
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("application/octet-stream");
		FileContext fc = FileContext.getFileContext(URI.create("hdfs://localhost:9000"));
		FSDataInputStream fsInput = fc.open(new Path("/demo.flv"));
		//int size = fsInput.available();
		
		//byte[] data = new byte[size];
		OutputStream os = response.getOutputStream();
		IOUtils.copyBytes(fsInput, os, 4090,false);
		os.flush();
		os.close();
	}


在Strobe Media Playback player setup页面中进行测试应该会看到视频如下图所示:
  • 大小: 412.6 KB
0
4
分享到:
评论
1 楼 ycwycf 2011-11-22  
谢谢分享,我先试下!

相关推荐

Global site tag (gtag.js) - Google Analytics