首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用xuggler通过RTMP采集直播音频?

如何使用xuggler通过RTMP采集直播音频?
EN

Stack Overflow用户
提问于 2013-05-29 08:29:25
回答 1查看 1.1K关注 0票数 0

我正在尝试使用xuggler直播麦克风流(SPEEX编解码器),但我收到警告,编解码器为空。此问题的修复方法是什么?

代码语言:javascript
复制
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)
    }

错误:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2013-06-12 23:18:41

你把audioCoder设置为IStreamCoder了吗??IStreamCoder open()不需要参数,只需给出audioCoder.open(),而且只有当audioCoder是IStreamCoder对象时才会这样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16803621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档