【问题标题】:Stream opus audio rtp to android device将作品音频 rtp 流式传输到 android 设备
【发布时间】:2017-09-25 04:42:37
【问题描述】:

我想使用 ffmpeg 将音频(opus 编解码器)直接流式传输到 android 设备。

在 PC 上我开始直播:

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

192.168.0.100 - 我手机的本地 wifi 地址。

在 Android 设备上我尝试播放流:

 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();
        }
    }

在 logcat 我看到下一行:

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

我做错了什么?感谢您的帮助

【问题讨论】:

  • ?

标签: android audio ffmpeg audio-streaming opus


【解决方案1】:

使用 RTP,您可以在 PC 上启动流媒体服务器。因此,在您的 ffmpeg 命令行中,您必须指定 PC 的 IP 地址而不是目标:

./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

在 Android 端,您需要一个 RTP/RTSP 客户端。我会尝试: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java

【讨论】:

  • 在Android客户端中是应该从ffmpeg命令行指定PC的IP地址还是使用它自己的IP地址?
  • 是 - Android 客户端需要使用 ffmpeg 命令行中指定的 URL,其中包含 PC 的 IP 地址。
猜你喜欢
  • 2012-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-24
  • 1970-01-01
相关资源
最近更新 更多