Search code examples
javared5rtmp

How to extract audio from live video stream on Red5?


I need to extract audio from a live stream on red5 and stream it separately.
On nginx with rtmp module I'd just retranslate this stream via ffmpeg without videodata, but I have no idea how to do anything like this (with or without ffmpeg) on Red5.

The first link on google gave me this:

just register IStreamListeners on your IClientStreams, and then separate AudioData from VideoData in the RTMPEvents

But this doesn't help much. To be honest, this doesn't help at all. What are these IStreamListeners and how do I register them on IClientStream?

And, what is more misterious, how do I separate AudioData from VideoData in some RTMPEvents?


Solution

  • This is how your extend RTMPClient and capture the Audio or Video events

    private class TestClient extends RTMPClient {
      private int audioCounter;
      private int videoCounter;
      public void connect() {
        private IEventDispatcher streamEventDispatcher = new IEventDispatcher() {
          public void dispatchEvent(IEvent event) {
        System.out.println("ClientStream.dispachEvent()" + event.toString());
        String evt = event.toString();
        if (evt.indexOf("Audio") >= 0) {
          audioCounter++;
        } else if (evt.indexOf("Video") >= 0) {
          videoCounter++;
        }
          }
        };
      }
    }
    

    This simply counts the a/v events, but it will get you part of the way there. I suggest looking though the unit tests in red5 and there you can learn a lot.