我想用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
我做错了什么?谢谢你的帮助
答案 0 :(得分: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