使用gstreamer在安卓上录制音频(使用Qt5)



尝试使用 gstreamer 在 android 上录制音频(已经启用音频录制的权限(,我更喜欢 gstreamer 而不是 java api,因为将来需要添加更多功能,例如 将音频转换为特定格式(S16LE,通道= 1,速率= 16000等(,编码为WAV,单独的视频/音频等

我正在使用的管道是

openslessrc ! audioconvert ! wavenc ! fakesink

openslessrc ! audioconvert ! wavenc ! openslessink location="%1"

但是他们都给了我错误消息

E IAudioFlinger: createRecord returned error -22
E AudioRecord: AudioFlinger could not create record track, status: -22
E libOpenSLES: android_audioRecorder_realize(0xcea58a00) error creating AudioRecord object; status -22
W libOpenSLES: Leaving Object::Realize (SL_RESULT_CONTENT_UNSUPPORTED)

我的 .pro 文件的一部分

#plugins
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstcoreelements.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgsttypefindfunctions.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstvideoconvert.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstvideorate.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstvideoscale.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstvideofilter.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstautodetect.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstvideotestsrc.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstplayback.a
#LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstsoup.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstx264.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstvideoparsersbad.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstandroidmedia.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstopengl.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstopensles.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstaudioconvert.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstaudiotestsrc.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstautodetect.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstautoconvert.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstaudioresample.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstplayback.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstwavenc.a
LIBS += $${GSTREAMER_ROOT}/lib/gstreamer-1.0/libgstvoaacenc.a
LIBS += -lOpenSLES
#LIBS += $${GSTREAMER_ROOT}/lib/libavcodec.a

#plugin libs
LIBS += $${GSTREAMER_ROOT}/lib/liborc-0.4.a
LIBS += $${GSTREAMER_ROOT}/lib/libgstgl-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgraphene-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libpng16.a
LIBS += $${GSTREAMER_ROOT}/lib/libjpeg.a
LIBS += $${GSTREAMER_ROOT}/lib/libx264.a
LIBS += $${GSTREAMER_ROOT}/lib/libgstvideo-1.0.a
#LIBS += $${GSTREAMER_ROOT}/lib/libgstbadbase-1.0.a
#LIBS += $${GSTREAMER_ROOT}/lib/libgstbadvideo-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgstaudio-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgstpbutils-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgsttag-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgstphotography-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgstcontroller-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgstcodecparsers-1.0.a
LIBS += -lEGL -lGLESv2
#gstreamer libs
LIBS += $${GSTREAMER_ROOT}/lib/libgstbase-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgstreamer-1.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgmodule-2.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libgobject-2.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libglib-2.0.a
LIBS += $${GSTREAMER_ROOT}/lib/libffi.a
#LIBS += $${GSTREAMER_ROOT}/lib/libpcre.a
LIBS += $${GSTREAMER_ROOT}/lib/libiconv.a
LIBS += $${GSTREAMER_ROOT}/lib/libintl.a
LIBS += $${GSTREAMER_ROOT}/lib/libz.a

gstreamer的初始化代码,在主.cpp

extern "C"
{
#include <gst/gst.h>
#ifdef Q_OS_ANDROID
GST_PLUGIN_STATIC_DECLARE(coreelements);
GST_PLUGIN_STATIC_DECLARE(typefindfunctions);
GST_PLUGIN_STATIC_DECLARE(videoconvert);
GST_PLUGIN_STATIC_DECLARE(videorate);
GST_PLUGIN_STATIC_DECLARE(videoscale);
GST_PLUGIN_STATIC_DECLARE(videofilter);
GST_PLUGIN_STATIC_DECLARE(autodetect);
GST_PLUGIN_STATIC_DECLARE(playback);
GST_PLUGIN_STATIC_DECLARE(videotestsrc);
GST_PLUGIN_STATIC_DECLARE(playback);
//GST_PLUGIN_STATIC_DECLARE(soup);
GST_PLUGIN_STATIC_DECLARE(x264);
GST_PLUGIN_STATIC_DECLARE(videoparsersbad);
GST_PLUGIN_STATIC_DECLARE(androidmedia);
GST_PLUGIN_STATIC_DECLARE(opengl);
//GST_PLUGIN_STATIC_DECLARE(qmlgl);
GST_PLUGIN_STATIC_DECLARE(opensles);
GST_PLUGIN_STATIC_DECLARE(audioconvert);
GST_PLUGIN_STATIC_DECLARE(audiotestsrc);
GST_PLUGIN_STATIC_DECLARE(autodetect);
GST_PLUGIN_STATIC_DECLARE(autoconvert);
GST_PLUGIN_STATIC_DECLARE(audioresample);
GST_PLUGIN_STATIC_DECLARE(playback);
GST_PLUGIN_STATIC_DECLARE(wavenc);
//GST_PLUGIN_STATIC_DECLARE(voaacenc);
#endif
}
int main(int argc, char *argv[])
{
gst_init (&argc, &argv);
#ifdef Q_OS_ANDROID
GST_PLUGIN_STATIC_REGISTER(coreelements);
GST_PLUGIN_STATIC_REGISTER(typefindfunctions);
GST_PLUGIN_STATIC_REGISTER(videoconvert);
GST_PLUGIN_STATIC_REGISTER(videorate);
GST_PLUGIN_STATIC_REGISTER(videoscale);
GST_PLUGIN_STATIC_REGISTER(videofilter);
GST_PLUGIN_STATIC_REGISTER(autodetect);
GST_PLUGIN_STATIC_REGISTER(playback);
//GST_PLUGIN_STATIC_REGISTER(soup);
GST_PLUGIN_STATIC_REGISTER(videotestsrc);
GST_PLUGIN_STATIC_REGISTER(x264);
GST_PLUGIN_STATIC_REGISTER(videoparsersbad);
GST_PLUGIN_STATIC_REGISTER(androidmedia);
GST_PLUGIN_STATIC_REGISTER(opengl);
//GST_PLUGIN_STATIC_REGISTER(qmlgl);
GST_PLUGIN_STATIC_REGISTER(opensles);
GST_PLUGIN_STATIC_REGISTER(audioconvert);
GST_PLUGIN_STATIC_REGISTER(audiotestsrc);
GST_PLUGIN_STATIC_REGISTER(autodetect);
GST_PLUGIN_STATIC_REGISTER(autoconvert);
GST_PLUGIN_STATIC_REGISTER(audioresample);
GST_PLUGIN_STATIC_REGISTER(playback);
GST_PLUGIN_STATIC_REGISTER(wavenc);
//GST_PLUGIN_STATIC_REGISTER(voaacenc);
gst_debug_set_active(TRUE);
gst_debug_set_default_threshold(GST_LEVEL_NONE);
#endif

谢谢

我找到了一个解决方案,问题是我没有注册适当的插件,正确的插件应该是

GST_PLUGIN_STATIC_DECLARE(coreelements);
GST_PLUGIN_STATIC_DECLARE(coretracers);
GST_PLUGIN_STATIC_DECLARE(adder);
GST_PLUGIN_STATIC_DECLARE(audioconvert);
GST_PLUGIN_STATIC_DECLARE(audiomixer);
GST_PLUGIN_STATIC_DECLARE(audiorate);
GST_PLUGIN_STATIC_DECLARE(audioresample);
GST_PLUGIN_STATIC_DECLARE(audiotestsrc);
GST_PLUGIN_STATIC_DECLARE(typefindfunctions);
GST_PLUGIN_STATIC_DECLARE(videoconvert);
GST_PLUGIN_STATIC_DECLARE(videorate);
GST_PLUGIN_STATIC_DECLARE(videoscale);
GST_PLUGIN_STATIC_DECLARE(videotestsrc);
GST_PLUGIN_STATIC_DECLARE(volume);
GST_PLUGIN_STATIC_DECLARE(autodetect);
GST_PLUGIN_STATIC_DECLARE(videofilter);
GST_PLUGIN_STATIC_DECLARE(playback);
GST_PLUGIN_STATIC_DECLARE(audioparsers);
GST_PLUGIN_STATIC_DECLARE(auparse);
GST_PLUGIN_STATIC_DECLARE(multipart);
GST_PLUGIN_STATIC_DECLARE(wavenc);
GST_PLUGIN_STATIC_DECLARE(wavpack);
GST_PLUGIN_STATIC_DECLARE(wavparse);
GST_PLUGIN_STATIC_DECLARE(androidmedia);
GST_PLUGIN_STATIC_DECLARE(opengl);
GST_PLUGIN_STATIC_DECLARE(opensles);
GST_PLUGIN_STATIC_DECLARE(autoconvert);
GST_PLUGIN_STATIC_DECLARE(amrnb);
GST_PLUGIN_STATIC_DECLARE(amrwbdec);

它们不是插件的最小列表,我还没有时间优化它,我不需要编译 libgstreamer_android.so 来使它们在我的手机上工作,但它们仍然可以工作。

相关内容

  • 没有找到相关文章

最新更新