2017-04-27 20 views
10

Tôi muốn phát trực tuyến âm thanh (codec opus) bằng ffmpeg trực tiếp vào thiết bị Android.Phát trực tuyến âm thanh rtp sang thiết bị android

Trên PC tôi bắt đầu dòng:

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

đâu 192.168.0.100 - địa chỉ wifi địa phương của điện thoại của tôi.

Trên điện thoại Android tôi đã cố gắng để chơi dòng:

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

Trong logcat tôi thấy dòng tiếp theo:

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

im làm gì sai? Cảm ơn bạn đã giúp đỡ

+0

? – fionbio

Trả lời

1

Với RTP bạn khởi động máy chủ phát trực tuyến trên PC của mình. Vì vậy, trong commandline ffmpeg của bạn, bạn phải xác định địa chỉ IP của máy tính của bạn và không phải là mục tiêu:

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

Về phía Android, bạn sẽ cần một khách hàng RTP/RTSP. Tôi muốn thử: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java

+0

Trong ứng dụng Android, nó có nên chỉ định địa chỉ IP của PC từ dòng lệnh ffmpeg hoặc sử dụng địa chỉ IP riêng của nó không? – gregm

+0

Có - ứng dụng khách Android cần sử dụng URL được chỉ định trong dòng lệnh ffmpeg chứa địa chỉ IP của máy tính cá nhân. –

Các vấn đề liên quan