How to capture live audio via RTMP using xuggler?

与世无争的帅哥 提交于 2019-12-25 04:51:19

问题


I am trying to live microphone stream (SPEEX codec) using xuggler but I am getting warning that codec as null. What is fix for this issue?

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

Errror:

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)

回答1:


Have u set audioCoder as IStreamCoder?? and an IStreamCoder open() doesn't need arguments, jus give audioCoder.open() , and this is only if audioCoder is an IStreamCoder object.



来源:https://stackoverflow.com/questions/16803621/how-to-capture-live-audio-via-rtmp-using-xuggler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!