mateo
Posts: 3
Joined: Mon May 06, 2013 10:24 pm

arecord error

Tue May 14, 2013 3:51 pm

I have an RPi set up to record audio files (from a microphone through a USB audio preamp) at set intervals using arecord. It works well a majority of the time. However, about 15% of the time (on average), I get an error message and the audio file gets cut short. The weird part is that the error does not occur at a set interval, it seems to happen quite randomly.

This is the command I use:
arecord -D hw:1,0 -B 500000 -V stereo -f cd -d 60 /home/pi/audio/1_040213-175950.wav

It generally starts recording just fine:
Recording WAVE '/home/pi/audio/1_040213-175950.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

Except sometimes an error like this appears:
overrun!!! (at least 10.856 ms long)
arecord: pcm_read:1801:
read error: Input/output error
arecord encountered an error.
Shutting down in 30 seconds.


Usually the pre-amp is set up to run on USB power, however, I have tried running the pre-amp on battery power and on external power through an AC/DC adapter, but the error still occurs at the same amount of time.

Any one else experience this arecord error or have any ideas? Any help would be much appreciated!

teratech
Posts: 7
Joined: Sun Jun 02, 2013 4:16 pm

Re: arecord error

Tue Jun 04, 2013 10:31 pm

Greetings Mateo!

I am seeing almost the same thing that you are. I set the length of time to record for two hours. Very rarely do I get a two hour recording. Most of the time the recordings end at different times that are less then the two hour interval. I have tried two different USB audio encoders, and running the raspi from 700 to 950 MHz. Once I get the error arecord will not work unless I unplug then re-plug the usb device or reboot the raspi.

Now here is the monkey wrench: When I connect either of the audio encoders to a 4-port hub that is connected to the raspi, I don't get the error. I would use this configuration but the USB hub extremely distorts the audio signal. Is there a USB hub that passes audio signals to the raspi without distortion?

One different between our two errors is that I may or may not get several of the overrun messages before the audio encoder errors out. Additionally I am piping to lame and not a .wav file. I have spent days looking through many of the the USB issues with the raspi and your issue most closely resembles my issue.

Here is the arecord command entered twice and the resulting output. The first command was enter right after I had unplugged then re-plugged the USB audio encoder. The error can occur as quickly as a few minutes and rarely up to two hours. Mostly fails after about 10 to 20 minutes after the arecord command is entered. The 2nd time, the same arecord command is entered after the error condition has occurred and prints out more information.

pi@raspberrypi /var/mail $ arecord -f S16_LE -c2 -r44100 -d 0 -D hw:1,0 -t wav | lame - -o /home/pi/stereo/river_$(date +%y%m%d%H%M).mp3
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
overrun!!! (at least 23.666 ms long)
overrun!!! (at least 11.607 ms long)
overrun!!! (at least 46.105 ms long)
arecord: pcm_read:1801: read error: Input/output error
LAME 3.99.5 32bits (http://lame.sf.net)
Using polyphase lowpass filter, transition band: 16538 Hz - 17071 Hz
Encoding <stdin> to /home/pi/stereo/river_1306021025.mp3
Encoding as 44.1 kHz j-stereo MPEG-1 Layer III (11x) 128 kbps qval=3


pi@raspberrypi /var/mail $ arecord -f S16_LE -c2 -r44100 -d 0 -D hw:1,0 -t wav | lame - -o /home/pi/stereo/river_$(date +%y%m%d%H%M).mp3
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
arecord: set_params:1145: Unable to install hw params:
ACCESS: RW_INTERLEAVED
FORMAT: S16_LE
SUBFORMAT: STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 44100
PERIOD_TIME: (125011 125012)
PERIOD_SIZE: 5513
PERIOD_BYTES: 22052
PERIODS: (3 4)
BUFFER_TIME: 500000
BUFFER_SIZE: 22050
BUFFER_BYTES: 88200
TICK_TIME: 0
Warning: unsupported audio format
pi@raspberrypi /var/mail $

So hopefully this information will help. Oh, I almost forgot my level of Wheezy:

http://downloads.raspberrypi.org/images ... spbian.zip

# I have a "B" model Pi that I received shortly after the first of this year. It has the "Made in China" sticker.
# If I run the arecord command shown above on a Single Board Computer with an Intel N450 processor that I have running Ubuntu 12.04, it works as expected. (But the SBC uses at least 5 times the power of the raspi) I am working a battery application.
# If I run Darkice to stream MP3, the raspi will stream at 128kbps with the same hardware setup as the failing arecord example above, without a problem.
# When I power the audio encoder externally, (not through the raspi) I still get the error.

So I am out of gas for ideas as to what to look at. With my limited knowledge, I would guess the issue is related to the USB subsystem on the raspi because when I plug the 4 port expander in the USB path between the audio encoder and the raspi, the error stops.

Joel

mateo
Posts: 3
Joined: Mon May 06, 2013 10:24 pm

Re: arecord error

Sun Jun 30, 2013 5:24 pm

Hi Joel,

I still have not found a solution to the arecord issue. Have you made any progress? What kind of USB hub were you using?

-Mateo

spartacus
Posts: 28
Joined: Tue Jan 01, 2013 5:06 am
Location: california

Re: arecord error

Thu Jul 04, 2013 4:47 am

i have a similar problem with arecord and overruns.

Code: Select all

date
arecord -D hw:1,0 -r 48000 -d 600 -c 1 -f S16_LE test.wav
date

Code: Select all

Wed Jul  3 03:43:06 BST 2013
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
overrun!!! (at least 49.769 ms long)
overrun!!! (at least 2089.292 ms long)
overrun!!! (at least 36.446 ms long)
overrun!!! (at least 29.463 ms long)
overrun!!! (at least 44.115 ms long)
overrun!!! (at least 41.651 ms long)
overrun!!! (at least 43.766 ms long)
overrun!!! (at least 45.386 ms long)
overrun!!! (at least 42.235 ms long)
overrun!!! (at least 48.080 ms long)
Wed Jul  3 03:53:36 BST 2013
arecord always runs for longer than the duration i give, but the WAV files are the correct length. it must speed up the audio to fit 630 seconds of audio into a 600 second file.

any solution for this?

teratech
Posts: 7
Joined: Sun Jun 02, 2013 4:16 pm

Re: arecord error

Sun Jul 07, 2013 9:39 pm

Hi Mateo and Spartacus,

I have not found a solution. For the time being I have switched back to using a Single Board Computer with an Intel 450 on it for my project. My hopes are that someone who knows about the USB subsystem on the Raspi would look into this issue and try to sort out why arecord can not operate continuously for a 1 or 2 hour period without an error that prevents arecord from continuously working on the Raspi. Like I said before, the same commands from my first posting, that I tried on the Raspi work as expected on the Single Board Computer. I would really appreciate someone helping us because the Raspi would last 5 times longer with the same amount of batteries power in my application as the Single Board Computer I am now using.

Spartacus, I not only get the over runs, the Raspi USB bus gets into an error state that prevents continued use of the arecord command without some form of hardware reset.

Mateo asked about the hub I was using - D-link Model No. DUB-H4.

Joel

yodamauro
Posts: 1
Joined: Tue Mar 04, 2014 6:47 pm

Re: arecord error

Tue Mar 04, 2014 7:06 pm

Hi everybody. Perhaps I found a solution. I have a similar setup, just I don't use a powered mic.
I had exactly the problems you describe here (overruns) and I tried the same things you experimented with.
I am recording on an external USB stick and I noticed that the number of overrun errors was related to the way I formatted it (overclocking and sampling rate are ininfluent).
I tried EXT2, EXT4 (with and without journaling) and VFAT, all with noatime and nodiratime set. VFAT gave the best results, that is, "some" short overruns (I mean, a couple per hour). EXT2 and EXT4 were simply not acceptable (I mean, 10 to 30 per hour). Finally I tried the XFS filesystem and it just works! No overruns. I hope this can help.

teratech
Posts: 7
Joined: Sun Jun 02, 2013 4:16 pm

Re: arecord error

Sun Mar 16, 2014 8:25 pm

Hi Yodamauro!

If I understand what you are saying, you are talking about the file format in which the audio data is stored after being captured? I have been using a 16GB SD card that holds both the Wheezy Operating System and the audio data after being captured. So to experiment with your idea I would need to load a SD card with Wheezy that is formatted to XFS format?

Thank-you for your input,

Joel

POMATu
Posts: 2
Joined: Wed Mar 19, 2014 11:46 am

Re: arecord error

Wed Mar 19, 2014 11:49 am

I am not sure if rpi will load from xfs partition, however you can do the following

1) attach external drive formatted to xfs
2) create a different partition on sdcard formatted to xfs and use that partition for your project

I will test 1st method and post my feedback. Thanks for the tip

POMATu
Posts: 2
Joined: Wed Mar 19, 2014 11:46 am

Re: arecord error

Sat Mar 22, 2014 10:04 pm

I can confirm tha xfs filesystem solved his problem. Will use xfs for my future rpi projects. Thanks a lot.

teratech
Posts: 7
Joined: Sun Jun 02, 2013 4:16 pm

Re: arecord error

Sun Mar 23, 2014 12:29 am

Hi Pomat,

Thanks for the feedback and confirmation of the fix. I am currently consumed with another project now and will verify when I get a chance. I am anxious to try this solution for stream live nature sounds that I am currently using a Single Board Computer for on livenaturesongs.com. My plans are to make a xfs partition on the SD card.

Thanks to all that contributed to this issue.

Joel

shakirabbas
Posts: 10
Joined: Thu Feb 27, 2014 7:14 pm

Re: arecord error

Sun May 18, 2014 10:46 pm

This is an excellent finding by yodamauro! I can confirm too that it works well by saving the audio file to XFS partition on the pi SD card. Zero overrun errors!

This solution fixes both audio recording and video recording as well (when using raspivid). I noticed glitches in videos longer than 20 seconds or so and it appears to be addressed also by using a XFS formatted partition on the RasPi SD card! I've had problems (occasional ugly artifacts) with Logitech camera C920 h.264 native encoded recordings as well and I think this solution may also address that too. I will re-order the c920 and will test this and report back.

Shak

jstsch
Posts: 4
Joined: Fri May 30, 2014 1:19 pm

Re: arecord error

Fri May 30, 2014 1:23 pm

I can confirm that this is a problem. I suspect that the filesystem/SD-card combo can stall for a few seconds which causes overruns in arecord. Would be nice if these writes could be buffered a bit in memory somewhere...

So a workaround (without installing a different filesystem) is to record to /tmp (tmpfs) with for instance --max-file-time=60, and then moving the files when done to the place of your choosing on the SD card. No dropouts.

In my case I want small segments anyway which get encoded to MP3 (perpetual audio recorder), so the workaround is not a problem for me.

shakirabbas
Posts: 10
Joined: Thu Feb 27, 2014 7:14 pm

Re: arecord error

Fri May 30, 2014 5:29 pm

Thanks, I confirm that /tmp works as well for both arecord and raspivid. That's a lot more convenient (if you don't have files that are too large) than using XFS.

jstsch
Posts: 4
Joined: Fri May 30, 2014 1:19 pm

Re: arecord error

Sat May 31, 2014 8:16 am

I decided I didn't want small audio files after all, so in my case with encoding to MP3 the following works:

Code: Select all

arecord -D hw:1,0 -v --fatal-errors --buffer-size=192000 -f dat -t raw | dd bs=480000 | lame -r --preset standard - record.mp3
Basically I stick a big buffer between arecord and lame (10 seconds worth), so that arecord can always dump its data even if the FS stalls a bit. The maximum buffer size of arecord is limited to 262144 for some reason, and that wasn't enough to prevent overruns over a longer period.

retiredjedi
Posts: 1
Joined: Tue Oct 04, 2016 5:16 pm

Re: arecord error

Fri Aug 31, 2018 12:00 pm

The proper solution is to use a High performance file system on record storage. Think I'm using XFS formatted file system
I'm still using a version 3 pi, all of those errors stopped.

kgsnipes
Posts: 1
Joined: Fri Dec 28, 2018 5:09 pm

Re: arecord error

Fri Dec 28, 2018 5:43 pm

I too am getting the same error on arecord. Try using ffmpeg to capture the audio. On ffmpeg, I am not getting any errors for longer recroding durations on Pi Zero.

Code: Select all

ffmpeg -f alsa -ac 1 -ar 44100 -i hw:0 -t 30 out.wav

blackjack75
Posts: 1
Joined: Sat Apr 08, 2017 6:55 pm

Re: arecord error

Mon Nov 18, 2019 7:00 pm

I confirm that the issue still happens in 2019 on a Rpi3 with latest Debian Buster release and the easiest solution was indeed to format the external USB pendrive as XFS. I already had the external pendrive (Sandisk Ultra) and experienced overrun errors after about one hour. Now I can record up 8 hours (and probably more) without any errors.

User avatar
jwainwright87
Posts: 41
Joined: Wed Jul 01, 2020 10:46 am
Location: Liverpool, UK

Re: arecord error

Thu Dec 10, 2020 3:05 pm

If anyone is still having this problem I have found a solution.

Try saving the files to RAM rather than the SD. Save location: /run/shm/

However, this will depend on how much RAM you can have and how long you can record.

I tried this is a 2 minute audio clip and worked fine.

Files will need moving from the RAM directory as all data will be lost when shutdown

Return to “Troubleshooting”