首先下载一个测试用的Flash视频播放器Strobe Media Playback
[url]http://osmf.org/strobe_mediaplayback.html[/url]
然后在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主要代码如下:
在Strobe Media Playback player setup页面中进行测试应该会看到视频如下图所示:
[img]http://dl.iteye.com/upload/attachment/559805/5cb0c6b3-e579-3055-8391-3d33712a1813.png[/img]
[url]http://osmf.org/strobe_mediaplayback.html[/url]
然后在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页面中进行测试应该会看到视频如下图所示:
[img]http://dl.iteye.com/upload/attachment/559805/5cb0c6b3-e579-3055-8391-3d33712a1813.png[/img]