---
title: "Hadoop学习笔记－读取视频流给Flash播放器"
author: "andy_ghg"
date: "2011-09-25T00:12:34Z"
tags: []
categories: ["开源软件"]
slug: "hadoop-flash"
draft: false
lastmod: "2011-09-25T00:12:34Z"
id: 1179848
url: "https://andy-ghg.iteye.com/blog/1179848"
---

首先下载一个测试用的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主要代码如下：

```java

	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页面中进行测试应该会看到视频如下图所示：
![](http://dl.iteye.com/upload/attachment/559805/5cb0c6b3-e579-3055-8391-3d33712a1813.png)