+Elixir and Erlang provide [`Port`](https://hexdocs.pm/elixir/Port.html) a Port for running external programs. However, communicating with these programs over stdio can lead to various issues. [`ExCmd`](https://hexdocs.pm/ex_cmd/readme.html) and [`Exile`](https://hexdocs.pm/exile/readme.html) libraries address these concerns. Along with that they provide beloved streaming capabilities. In otherwords they let you stream input, output _all the way down_.
+
+Let's take an example to illustrate the streaming capabilities. Here, we'll create an HTTP server to watermark a video.
+
+The server should perform the following:
+
+* accept request with video URL and watermark text
+* stream input video
+* adds text as watermark using FFmpeg
+* stream output video as response, using chunked encoding
+
+## FFmpeg
+
+We need a sample video to test. Let's fetch and display it using `Kino`
+The method with `System.cmd` works, but it makes us create and deal with temporary files unnecessarily. If you're using the output right away and then throwing it away, a better way is to use streams. Ffmpeg can read from and write to UNIX pipes, and you can use this easily with `ExCmd`.
+With that, the only thing remaining is to set up the HTTP server. We utilize Plug to create a `GET /watermark` route. This route accepts a video URL and watermark text as query parameters and returns the output video as a stream using chunked response, maximizing the streaming capability.
+
+### Streaming Input
+
+ExCmd facilitates input streaming by supporting both `Enumerable` and `Collectable`. Given that HTTP Client (`Req`) we are using supports pushing responses to `Collectable`, we can simply leverage that capability.
+
+<!-- livebook:{"force_markdown":true} -->
+
+```elixir
+output_stream =
+ ExCmd.stream!(cmd,
+ input: fn ex_cmd_sink ->
+ # Req pushes video input to ex_cmd as chunks
+ Req.get!(video_url, into: ex_cmd_sink)
+ end)
+```
+
+### Streaming Output
+
+Achieving streaming response can be done using `Plug.Conn.chunk/2`, allowing us to push chunks as soon as they become available from the ffmpeg command.
+Notice the logs in the Livebook cell above. As you watch the video, observe how the video chunks are fetched, encoded, and pushed as responses in chunks, together, on the fly!
+
+Another noteworthy feature is that if the connection drops midway (close `ffplay` using `Ctrl+C`), the streaming pipeline stops gracefully, avoiding the wasteful encoding of the entire video.