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页面中进行测试应该会看到视频如下图所示:
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20