【错误记录】FFmpeg 推流报错 ( FLV does not support sample rate 8000, choose from (44100, 22050, 11025) )「建议收藏」

【错误记录】FFmpeg 推流报错 ( FLV does not support sample rate 8000, choose from (44100, 22050, 11025) )「建议收藏」[flv@0xe9e24600]FLVdoesnotsupportsamplerate8000,choosefrom(44100,22050,11025)[flv@0xe9e24600]Audiocodecmp3notcompatiblewithflv

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

一、报错信息


在 Android 平台中 , 先使用 MediaRecorder 将从 麦克风 采集到的 音频压缩到文件中 ,

使用 交叉编译的 FFmpeg 可执行程序 , 执行 文件 推流命令 ,

./ffmpeg -re -i 20220331_152049.m4a -f flv rtmp://192.168.1.17:8088/audio

提示如下报错信息 :

walleye:/data/data/cn.zkhw.client/files # ./ffmpeg -re -i 20220331_152049.m4a -f flv rtmp://192.168.1.17:8088/audio
ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8 (GCC)
  configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '20220331_152049.m4a':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2022-03-31 07:20:59
    com.android.version: 9
  Duration: 00:00:09.86, start: 0.000000, bitrate: 14 kb/s
    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 12 kb/s (default)
    Metadata:
      creation_time   : 2022-03-31 07:20:59
      handler_name    : SoundHandle
[flv @ 0xe9e24600] FLV does not support sample rate 8000, choose from (44100, 22050, 11025)
[flv @ 0xe9e24600] Audio codec mp3 not compatible with flv
Output #0, flv, to 'rtmp://192.168.1.17:8088/audio':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    com.android.version: 9
    encoder         : Lavf57.25.100
    Stream #0:0(eng): Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 8000 Hz, mono, fltp (default)
    Metadata:
      creation_time   : 2022-03-31 07:20:59
      handler_name    : SoundHandle
      encoder         : Lavc57.24.102 libmp3lame
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> mp3 (libmp3lame))
Could not write header for output file #0 (incorrect codec parameters ?): Function not implemented
1|walleye:/data/data/cn.zkhw.client/files #
1|walleye:/data/data/cn.zkhw.client/files #
1|walleye:/data/data/cn.zkhw.client/files #
1|walleye:/data/data/cn.zkhw.client/files #
1|walleye:/data/data/cn.zkhw.client/files #

在这里插入图片描述

二、解决方案


MediaRecorder 录下的音频 , 默认采样率为 8000 Hz , FFmpeg 推流不支持该采样率 ;

FFmpeg 推流只支持 44100, 22050, 11025 三种采样率 ;

这里设置 MediaRecorder 的采样率为 11025 Hz 即可 ;

mMediaRecorder.setAudioSamplingRate(11025);

注意要在调用 prepare() 方法之前设置采样率 , 否则无效 ;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/181238.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号