Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream opus audio rtp to android device

I want to stream audio (opus codec) with ffmpeg directly to android device.

On PC i start stream:

  ./ffmpeg -re -stream_loop -1 -i akgld-c8mxm.opus -acodec libopus -ac 1 -ab 96k -vn -f rtp rtp://192.168.0.100:6000

Where 192.168.0.100 - local wifi address of my phone.

On Android device i tried to play stream:

 public void tryPlayStream() {
        String ip = Utils.wifiIpAddress(this);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
        StrictMode.setThreadPolicy(policy);
        AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE);
        audio.setMode(AudioManager.MODE_IN_COMMUNICATION);
        audioGroup = new AudioGroup();
        audioGroup.setMode(AudioGroup.MODE_ECHO_SUPPRESSION);
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByName(ip);
            audioStream = new AudioStream(inetAddress);
            audioStream.setCodec(AudioCodec.PCMA);
            audioStream.setMode(RtpStream.MODE_RECEIVE_ONLY);
            InetAddress inetAddressRemote = InetAddress.getByName(ip);
            audioStream.associate(inetAddressRemote, 6000);
            audioStream.join(audioGroup);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

In logcat i see next lines:

E/AudioRecord: AudioFlinger could not create record track, status: -1
 E/AudioGroup: cannot initialize audio device

What im doing wrong? Thanks for any help

like image 526
Yuriy Aizenberg Avatar asked Apr 27 '17 11:04

Yuriy Aizenberg


1 Answers

With RTP you start a streaming server on your PC. So in your ffmpeg commandline you have to specify your PC's IP address and not the target:

./ffmpeg -re -stream_loop -1 -i akgld-c8mxm.opus -acodec libopus -ac 1 -ab 96k -vn -f rtp rtp://YOUR_PC_S_IP_ADDRESS:6000

On the Android side you'll need a RTP/RTSP client. I'd try: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java

like image 176
Markus Schumann Avatar answered Sep 29 '22 20:09

Markus Schumann