1

这是我的代码。基本上我正在尝试使用 rtsp 将 android 屏幕流式传输到 vlc 媒体播放器,但我设法完美地流式传输视频,但音频没有播放。我正在使用 AMRNB 编码方法在本地套接字上发送流。我可以通过使用日志看到有音轨也正在发送,但不知道为什么它没有被播放。

        mMediaRecorder.setAudioSource (mAudioSource);
        mMediaRecorder.setOutputFormat (mOutputFormat);
        mMediaRecorder.setAudioEncoder (mAudioEncoder);
        mMediaRecorder.setAudioChannels (1);
        mMediaRecorder.setAudioSamplingRate (mQuality.samplingRate);
        mMediaRecorder.setAudioEncodingBitRate (mQuality.bitRate);
        mMediaRecorder.setOutputFile (mSender.getFileDescriptor());
        mMediaRecorder.prepare();
        mMediaRecorder.start();
        Log.d(" audio ", mMediaRecorder.toString ());

        try {
            // mReceiver.getInputStream contains the data from the camera
            // the mPacketizer encapsulates this stream in an RTP stream and send it over the network
            mPacketizer.setDestination (mDestination, mRtpPort, mRtcpPort);
            mPacketizer.setInputStream (mReceiver.getInputStream ( ));
            mPacketizer.start ( );
            Log.d(" packetizer ", mPacketizer.toString ());
            mStreaming = true;
        } catch (IOException e) {
            stop ( );
            throw new IOException ("Something happened with the local sockets :/ Start failed !");
        }

这是我的 Logcat

E/RtspServer: SETUP 192.168.1.86:25670/trackID=0
D/dest: 192.168.1.89
V/MediaStream: Requested audio with 32kbps at 8kHz
D/MediaRecorder: Constructor MediaRecorder
I/MediaRecorderJNI: setup
I/MediaRecorderJNI: setAudioSource(1)
I/MediaRecorderJNI: setAudioEncoder(2)
    setParameter()
I/MediaRecorderJNI: setParameter()
I/MediaRecorderJNI: setParameter()
I/MediaRecorderJNI: setOutputFile
    prepare
I/MediaRecorderJNI: start
E/MediaRecorder: start failed: -38
D/RtspServer: RTSP/1.0 200 OK
    Server: MajorKernelPanic RTSP Server
    Cseq: 4
    Content-Length: 0
    Transport: RTP/AVP/UDP;unicast;destination=192.168.1.89;client_port=5010-5011;server_port=33462-44704;ssrc=f6dc348c;mode=play
    Session: 1185d20035702ca
    Cache-Control: no-cache
E/RtspServer: SETUP 192.168.1.86:25670/trackID=1
D/dest: 192.168.1.89
D/H264Packetizer: H264 packetizer started !
    header is  0 0 0 1 33  ts = 76657985454000 nalu len = 24
D/RtspServer: RTSP/1.0 200 OK
    Server: MajorKernelPanic RTSP Server
    Cseq: 5
    Content-Length: 0
    Transport: RTP/AVP/UDP;unicast;destination=192.168.1.89;client_port=36882-36883;server_port=51731-41042;ssrc=e0e9342d;mode=play
    Session: 1185d20035702ca
    Cache-Control: no-cache
D/H264Packetizer: header is  -128 0 0 0 1  ts = 76658035880000 nalu len = 1333
D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10362; state: ENABLED
4

2 回答 2

0

在调试时,我发现我正在使用媒体记录器来记录音频,并使用媒体编解码器来记录视频,这就是为什么我的媒体记录器为空并且无法启动媒体记录器的原因。

但音频仍然无法正常工作

于 2021-10-09T13:02:55.940 回答
0

更新

在处理这个问题时,我发现我正在 android Lolipop 上测试我的项目,并且无法直接在 LocalSockets 上读写。您必须使用ParcelFileDiscriptor流式传输音频。

于 2021-11-06T15:11:31.413 回答