0

我正在尝试使用 xuggler 直播麦克风流(SPEEX 编解码器),但我收到警告说编解码器为空。这个问题有什么解决办法?

public void audioCapture(String streamName, String sessionId) {
        IContainer readContainer = IContainer.make();
        readContainer.setInputBufferLength(4096);
        String url = "rtmp://127.0.0.1:1935/live/Session_"
                + sessionId + "/" + streamName + " live=1";
        if (readContainer.open(url, IContainer.Type.READ, null, true, false) < 0) {
            // if(readContainer.open(url, IContainer.Type.READ, null) < 0){
            throw new RuntimeException("unable to open read container");
        }
        int numStreamAudio = readContainer.getNumStreams();
        System.out.println("Numer of audio stream: " + numStreamAudio);
        IStream stream = readContainer.getStream(0);
        audioCoder = readContainer.getStream(0).getStreamCoder();
        int st = audioCoder.open(null, null);
        // if(st<0) throw new RuntimeException("cant open audio coder");
        // if(audioCoder.open() <0) throw new
        // RuntimeException("cant open audio coder");
        System.out.println(" audio coder prop channels"
                + audioCoder.getChannels() + "  sample rate "
                + audioCoder.getSampleRate() + " bit rate "
                + audioCoder.getBitRate() + " codec type  "
                + audioCoder.getCodecType().toString() + " codec tag "
                + audioCoder.getCodecTag() + " audio frame size "
                + audioCoder.getAudioFrameSize() + " codec id "
                + audioCoder.getCodecID().toString() + " num properties "
                + audioCoder.getNumProperties());

        writer.addAudioStream(1, 1, 1, 16000);
        IPacket packet = IPacket.make();
        while (readContainer.readNextPacket(packet) >= 0) {
            IAudioSamples samples = IAudioSamples.make(1024, 1);
            int offset = 0;
            while (offset < packet.getSize()) {
                int bytesDecoded = audioCoder.decodeAudio(samples, packet,
                        offset);

                // if(bytesDecoded < 0) throw new
                // RuntimeException("got error decoding audio in: " );
                offset += bytesDecoded;
            }
        }

        // IAudioSamples samples = IAudioSamples.make(numSamples, numChannels)
    }

错误:

20:24:25,569 INFO  [stdout] (http-0.0.0.0-0.0.0.0-8081-2) 20:24:25.568 [http-0.0.0.0-0.0.0.0-8081-2] WARN  com.xuggle.xuggler - Attempting to decode when not ready; codec not opened (../../../../../../../csrc/com/xuggle/xuggler/StreamCoder.cpp:873)

20:25:41,517 INFO  [stdout] (http-0.0.0.0-0.0.0.0-8081-2) 20:25:41.517 [http-0.0.0.0-0.0.0.0-8081-2] WARN  com.xuggle.xuggler - Attempting to decode when not ready; codec not opened (../../../../../../../csrc/com/xuggle/xuggler/StreamCoder.cpp:873)

20:25:42,621 INFO  [stdout] (http-0.0.0.0-0.0.0.0-8081-2) 20:25:42.621 [http-0.0.0.0-0.0.0.0-8081-2] WARN  com.xuggle.xuggler - Attempting to decode when not ready; codec not opened (../../../../../../../csrc/com/xuggle/xuggler/StreamCoder.cpp:873)

20:25:43,485 INFO  [stdout] (http-0.0.0.0-0.0.0.0-8081-2) 20:25:43.485 [http-0.0.0.0-0.0.0.0-8081-2] WARN  com.xuggle.xuggler - Attempting to decode when not ready; codec not opened (../../../../../../../csrc/com/xuggle/xuggler/StreamCoder.cpp:873)
4

1 回答 1

0

你有没有将audioCoder设置为IStreamCoder??并且 IStreamCoder open() 不需要参数,只需给出 audioCoder.open() ,这仅适用于 audioCoder 是 IStreamCoder 对象。

于 2013-06-12T15:18:41.217 回答