[FFmpeg-user] FFMPEG and ALSA

william keeling williamkeeling at hotmail.com
Sat Feb 1 01:18:20 EET 2020


Not user why FFMPEG/ALSA uses so mush more cpu than native ALSA using arecord.  Same results the without S32_LE to S16_LE conversion (-acodec copy).

native ALSA with arecord run at less than 2% CPU at a sample rate of 96000:
pi at raspberrypi:~ $ arecord -D plughw:1 -c2 -r 96000 -f S32_LE -d 15 junk.wav
Recording WAVE 'junk.wav' : Signed 32 bit Little Endian, Rate 96000 Hz, Stereo

FFMPEG at 44100 sample rate uses 99% CPU and gets buffer xrun errors:
pi at raspberrypi:~ $ ffmpeg -f alsa -acodec pcm_s32le -ar 44100 -i plughw:1 -t 15 ffmpeg.wav
ffmpeg version N-96343-g029cc9883f Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 8 (Raspbian 8.3.0-6+rpi1)
  configuration: --enable-network --enable-protocol=tcp --enable-protocol=udp --enable-demuxer=rtsp --enable-decoder=h264 --enable-gpl --enable-libx264 --enable-nonfree --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-mmal --enable-omx --enable-omx-rpi --enable-libfreetype
  libavutil      56. 38.100 / 56. 38.100
  libavcodec     58. 65.103 / 58. 65.103
  libavformat    58. 35.102 / 58. 35.102
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 71.100 /  7. 71.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'plughw:1':
  Duration: N/A, start: 1580512286.852102, bitrate: 2822 kb/s
    Stream #0:0: Audio: pcm_s32le, 44100 Hz, stereo, s32, 2822 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s32le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to 'ffmpeg.wav':
  Metadata:
    ISFT            : Lavf58.35.102
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc58.65.103 pcm_s16le
[alsa @ 0x2fe63c0] ALSA buffer xrun.rate=1411.4kbits/s speed=0.324x
[alsa @ 0x2fe63c0] ALSA buffer xrun.rate= 658.6kbits/s speed=0.696x
[alsa @ 0x2fe63c0] ALSA buffer xrun.rate= 411.8kbits/s speed=0.782x
[alsa @ 0x2fe63c0] ALSA buffer xrun.rate= 290.1kbits/s speed=0.849x
[alsa @ 0x2fe63c0] ALSA buffer xrun.rate= 447.6kbits/s speed=0.89x
[alsa @ 0x2fe63c0] ALSA buffer xrun.rate= 359.3kbits/s speed=0.896x
[alsa @ 0x2fe63c0] ALSA buffer xrun.rate= 455.4kbits/s speed=0.919x
size=     863kB time=00:00:13.94 bitrate= 507.1kbits/s speed=0.903x
video:0kB audio:863kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.008826%



FFMPEG at 22050 sample rate use 98% CPU and no buffer xrun errors:
pi at raspberrypi:~ $ ffmpeg -f alsa -acodec pcm_s32le -ar 22050 -i plughw:1 -t 15 ffmpeg.wav
ffmpeg version N-96343-g029cc9883f Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 8 (Raspbian 8.3.0-6+rpi1)
  configuration: --enable-network --enable-protocol=tcp --enable-protocol=udp --enable-demuxer=rtsp --enable-decoder=h264 --enable-gpl --enable-libx264 --enable-nonfree --enable-decoder=h264_mmal --enable-encoder=h264_omx --enable-mmal --enable-omx --enable-omx-rpi --enable-libfreetype
  libavutil      56. 38.100 / 56. 38.100
  libavcodec     58. 65.103 / 58. 65.103
  libavformat    58. 35.102 / 58. 35.102
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 71.100 /  7. 71.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'plughw:1':
  Duration: N/A, start: 1580512389.671800, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s32le, 22050 Hz, stereo, s32, 1411 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s32le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to 'ffmpeg.wav':
  Metadata:
    ISFT            : Lavf58.35.102
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, stereo, s16, 705 kb/s
    Metadata:
      encoder         : Lavc58.65.103 pcm_s16le
size=    1292kB time=00:00:15.00 bitrate= 705.6kbits/s speed=   1x
video:0kB audio:1292kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.005896%




________________________________
From: ffmpeg-user <ffmpeg-user-bounces at ffmpeg.org> on behalf of Paul B Mahol <onemda at gmail.com>
Sent: Friday, January 31, 2020 9:44 AM
To: FFmpeg user questions <ffmpeg-user at ffmpeg.org>
Subject: Re: [FFmpeg-user] FFMPEG and ALSA

On 1/31/20, william keeling <WilliamKeeling at hotmail.com> wrote:
> Why is FFMPEG use so much CPU vs native ALSA tools.  For example I am able
> to record using ALSA device and arecord at a sample rate of 96000 with no
> issues and using very little CPU. But FFMPEG must be at 22050 to not get
> buffer xrun errors and it uses 100% of one core of the PI.
>

Full uncut ffmpeg command and its output missing.

>
> Great tool even with this issue.
>
>
>
> Thanks
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
ffmpeg-user at ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-user mailing list