[Error record] FFmpeg push stream error ( FLV does not support sample rate 8000, choose from (44100, 22050, 11025) )

Article directory





1. Error message



In the Android platform, first use MediaRecorder to compress the audio collected from the microphone into a file,

Use the cross-compiled FFmpeg executable program to execute the file push command,

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

The following error message is prompted:

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 #

insert image description here





2. Solutions



The audio recorded by MediaRecorder has a default sampling rate of 8000 Hz, which is not supported by FFmpeg streaming;

FFmpeg push streaming only supports 44100, 22050, 11025 sampling rates;

Here, set the sampling rate of MediaRecorder to 11025 Hz;

mMediaRecorder.setAudioSamplingRate(11025);

Note that you need to set the sampling rate before calling the prepare() method, otherwise it will be invalid;

Guess you like

Origin blog.csdn.net/han1202012/article/details/123874019