httprtmpred5

Customize Stream Path using http instead of rtmp


I currently have a Red5 application that uses a Custom Stream Path similar to the example shown on Red5's wiki.

It works great when using the following rtmp stream:

rtmp://localhost:1935/streaming/videos/myVid.mp4

I need to be able to do the same thing with a http stream. For example:

http://localhost:8080/streaming/videos/myVid.mp4

When I change the stream url from rtmp to http the CustomFilenameGenerator class is no longer being called.

Is it possible to have a Custom Stream Path while useing http? If so, is there a configuration or something that needs added/changed to make it work?

EDIT:

Just to be clear, currently I can only stream videos to my webpage that are located in the /red5Root/webApps/myApp/videos/ directory on my server machine.

I currently can use http://my.server.ip.address/myApp/videos/videoName.mp4 inside a video tag to play a video named "videoName.mp4" located in the videos directory on my server.

I want to be able to use http://my.server.ip.address/myApp/someUniqeIdOrName and have my Red5 CustomFilenameGenerator class then return the actual path (somewhere else in the file system on my server) of the video associated with the "someUniqeIdOrName" and play the video from that location.


Solution

  • I wasn't able to find a way to get this to work with my CustomFilenameGenerator class but I found a different solution that gives me the same result.

    I added a redirect servlet. In my web.xml add the following:

        <servlet>
            <servlet-name>fileServlet</servlet-name>
            <servlet-class>com.my.package.stream.app.FileServlet</servlet-class>
        </servlet>   
        <servlet-mapping>
            <servlet-name>fileServlet</servlet-name>
            <url-pattern>/files/*</url-pattern>
        </servlet-mapping>
    

    Then I created a FileServlet class based off of the example here.

    Once you get the filename from the request you can perform whatever logic based on the file name to set and return the actual location and name of the video/file you want in the response.

    Example:

     ...
    private void processRequest(HttpServletRequest request, HttpServletResponse response, boolean content) throws IOException {
    
            // Get requested file by path info.
            String requestedFile = request.getPathInfo();
    
            // Check if file is actually supplied to the request URL.
            if (requestedFile == null) {
                // Do your thing if the file is not supplied to the request URL.
                // Throw an exception, or send 404, or show default/warning page, or just ignore it.
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
    
    
           ****** Insert logic here to set basePath and requestedFile to what you need **** 
    
    
            // URL-decode the file name (might contain spaces and on) and prepare file object.
            File file = new File(basePath, URLDecoder.decode(requestedFile, "UTF-8"));  
       ...
    

    With the above servlet and similar FileServlet class I am able to play videos anywhere on my server by setting src="http://[myip]:8080/[myApp]/files/[uniqeFileNameOrId]"inside a video tag on my webpage.

    NOTE: If you the file you are wanting to get back from your sever is not a video a simpler example of a FileServlet class is here.