Search code examples
javajettygstreamerhttp-live-streaming

HTTP Live Streaming not working with GStreamer


I am trying to create a live stream over HTTP using GStreamer. I used the following command for the HLS sink:

gst-launch-1.0 videotestsrc is-live=true pattern=snow ! x264enc ! mpegtsmux ! hlssink max-files=5

There are no errors or warnings. The generated ts and m3u8 files are located in src/main/resources/videos. This folder is part of a Maven project that also contains a Jetty server. Here is the main class:

public class Main {
    private static final int PORT = 1778;
    private static final String RESOURCE_BASE = "./src/main/resources";
    private static final String WELCOME_FILE = "index.html";

    public static void main(String[] args) throws Exception {
        final Server jettyServer = new Server(PORT);

        final ResourceHandler resourceHandler = new ResourceHandler();

        resourceHandler.setDirectoriesListed(true);
        resourceHandler.setWelcomeFiles(new String[]{WELCOME_FILE});
        resourceHandler.setResourceBase(RESOURCE_BASE);

        final HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler() });
        jettyServer.setHandler(handlers);

        try {
            jettyServer.start();
            jettyServer.join();
        } finally {
            jettyServer.stop();
            jettyServer.destroy();
        }
    }
}

And the src/main/resources/index.html file:

<!DOCTYPE html>
<html>
  <body>
    <video src="./videos/playlist.m3u8" controls="" autoplay="" width="960" height="540"></video>
  </body>
</html>

When I start the server, I get the following screen on Safari (the picture does not change): HTTP Live Streaming Screen on Safari The ts files are correctly generated and playlist.m3u8 is being found successfully (the player gives an error otherwise). Why am I not getting a live stream of the default snow pattern?

In case it is relevant, I am running this on OS X Yosemite 10.10.5 and the Safari version is Version 10.1 (10603.1.30.0.34).


Solution

  • Try forcing a specific H.264 profile. If you don't do that videotestsrc and x264enc may agree on a format not supported by the decoder.

    ... x264enc ! video/x-h264, profile=main ! mpegtsmux ...