Stream opus audio rtp to android device
Asked Answered
S

1

10

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

Stead answered 27/4, 2017 at 11:47 Comment(1)
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>?Anodyne
C
2

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

Closeup answered 7/2, 2018 at 21:3 Comment(2)
In the Android client should it specify the PC's IP address from the ffmpeg command line or use it's own IP address?Unguinous
Yes - the Android client needs to use the URL specified in the ffmpeg command line which contains the PCs IP address.Closeup

© 2022 - 2024 — McMap. All rights reserved.