pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.54k stars 771 forks source link

Is there any code sample to use it with android audio recording and broadcast to RTSP server #1456

Open rescue1155 opened 6 months ago

rescue1155 commented 6 months ago

Hey there,

Is there any code sample in JAVA to use it with android audio recording and broadcast to RTSP server ?

thanks

pedroSG94 commented 6 months ago

Hello,

If you only want audio you can try this way:

        int bitrate = 128 * 1000;
        int samplerate = 44100;
        boolean isStereo = true;
        RtspOnlyAudio rtspOnlyAudio = new RtspOnlyAudio(connectChecker);
       //start stream
        if (rtspOnlyAudio.prepareAudio(bitrate, samplerate, isStereo)) {
            rtspOnlyAudio.startStream(url);
        }
       //stop stream
        rtspOnlyAudio.stopStream();
legosaro commented 3 weeks ago

Hello Pedro, I used RtspOnlyAudio with the Opus codec. The streaming works perfectly, but the audio file produced by the startRecord method is not playable. Is there a specific setting I need to adjust? Thanks!

pedroSG94 commented 3 weeks ago

Hello,

Record a file using opus is not allowed. The app should crash if you try to record using g711 or opus. This is a bug.

pedroSG94 commented 3 weeks ago

The reason is that the currents record controller implementations don't support g711 or opus.

You can create your own implementation to support it.

pedroSG94 commented 3 weeks ago

Maybe I can add an implementation for it. Maybe using a media muxer to create a webm or ogg file this can works

pedroSG94 commented 3 weeks ago

Hello,

I added a RecordController to allow record webm files that support Opus codec: https://github.com/pedroSG94/RootEncoder/commit/a069fa6438339a922ff81befc5a9eaeeeb72bd75

This will be available in the next version. Meanwhile you can copy that class and set the record controller using setRecordController. Remember save the file with name extension webm.

legosaro commented 2 weeks ago

Hello,

Thank you very much, Pedro. The new RecordController solves my problem. Will it be possible to use Opus for video recording in the future?

pedroSG94 commented 2 weeks ago

Hello,

Webm only supports VP8 and VP9 video codecs so It will be possible only when I add support for those codecs.

I have plans to support at least VP9 in RTMP and RTSP but it is not a priority.