如何使用xuggler通过RTMP捕获实时音频? [英] How to capture live audio via RTMP using xuggler?

查看:140
本文介绍了如何使用xuggler通过RTMP捕获实时音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

错误:

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)

推荐答案

您是否已将audioCoder设置为IStreamCoder? 并且IStreamCoder open()不需要参数,可以给定audioCoder.open(),并且仅当audioCoder是IStreamCoder对象时.

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.

这篇关于如何使用xuggler通过RTMP捕获实时音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆