Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4326815 to your computer and use it in GitHub Desktop.
Save anonymous/4326815 to your computer and use it in GitHub Desktop.
Play Framework Iteratees + UNIX Pipe
object CLI {
def apply(cmd: String): Enumeratee[Array[Byte], Array[Byte]] = ...
}
object Application extends Controller {
val videoSrc = "http://ftp.nluug.nl/pub/graphics/blender/demo/movies/Sintel.2010.720p.mkv"
def stream = Action {
var downloadStream = Concurrent.unicast[Array[Byte]]( channel => {
WS.url(videoSrc).get { header =>
Iteratee.foreach[Array[Byte]](channel.push(_))
}
}, () => ())
val encoder = CLI("ffmpeg -i pipe:0 -vcodec mpeg4 -s qcif -f m4v -y pipe:1")
Ok.stream(downloadStream &> encoder).
withHeaders( (CONTENT_TYPE, "video/mpeg"),
(CACHE_CONTROL, "no-cache") )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment