Skip to main content

This is a new website theme. Help me improve it and give your feedback (opens in a new tab).

Streaming video over Gopher

Published:

This blog post is more than two years old. It is preserved here in the hope that it is useful to someone, but please be aware that links may be broken and that opinions expressed here may not reflect my current views. If this is a technical article, it may no longer reflect current best practice.

Yesterday on the gopher-project mailing list, Wolfgang Faust gave a Gopher link to a streaming text file showing the current server time. Today, with his help, I have got video streaming over Gopher. In webcam streaming, Motion JPEG over HTTP is the defacto standard. The problem with Motion JPEG is that it is not actually a file format but a method of sending single JPEG frames over HTTP, one after another, as a MIME multipart document.

Gopher does however have an item type for GIF and GIF files can be animated. The solution therefore appeared to be to encode the video as an animated GIF and stream that.

#!/bin/sh

/usr/bin/ffmpeg -r 1 -s qvga -i http://localhost:8090/low.mjpeg \
    -pix_fmt rgb24 -f gif pipe:1 2>/dev/null

Above is the magic script that converts from a Motion JPEG stream into an animated GIF. Our Motion JPEG stream is produced by ffserver, a binary incuded with the ffmpeg distribution. By placing this into inetd it allows any application with access to the port it’s running on to start the transcoding of an animated GIF and stream the output.

Two examples of using this stream are:

  • PYG - for gopher using pygopherd
  • PHP - for HTTP using a webserver

I’ve requested the firewall rules on the Computing Society’s sandbox are modified to allow our Gopher server to see the webcam stream and as soon as they are, I’ll get the stream set up on our Gopher home page.