Opened 3 years ago

Last modified 7 weeks ago

#6156 reopened defect

Issue with FFMPEG ALSA CPU usage — at Initial Version

Reported by: mushm0m Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords: alsa
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I am on a Raspberry Pi Zero with a Pi Camera and an I2S MEMS mic, running the latest Raspbian Jessie. I am attempting to livestream audio and video. I've discovered that when I record ALSA audio with FFMPEG, that process takes 95% of my CPU and produces stuttering, unusable audio in the stream.

I have compiled FFMPEG with ALSA following this: http://vpaste.net/cXV9F

I isolated the issue to the following:

  1. ffmpeg -f alsa -acodec pcm_s32le -i mic_sv temp.wav

This single command takes 95% of my CPU.

  1. arecord -Dmic_sv -c2 -r48000 -fS32_LE -twav temp.wav

This single command takes <5% of my CPU.

I have added a custom hook to ffmpeg so we can see the PCM settings. I have ensured that settings (buffer size, period size, etc.) are identical between the two commands.

Here is the full console output of FFMPEG: http://vpaste.net/2M5gk
Here is the console output of Arecord: http://vpaste.net/CPk3A

After a long chat in the FFMPEG IRC channel, we believe there may be a bug in the way FFMPEG waits for ALSA packets. Arecord uses snd_pcm_wait() to wait for packets, and this command is not used in FFMPEG sources. Inserting '-re' before -i into my FFMPEG command reduces CPU usage to <5%, but is not the right approach, and causes other problems (bitrate is almost 0kbps, audio file generated is <5 kilobytes).

Change History (0)

Note: See TracTickets for help on using tickets.