问题
I am trying to capture a pcm stream from a Roland USB device with ffmpeg and wrap it with wav. The command line I am using is the following:
ffmpeg -f alsa -acodec pcm_s32le -ac 2 -ar 48000 -i hw:2,0 out.wav
Which comply with the settings of the hardware. I can also capture the stream with Audacity. The problem is that FFMPEG throws "cannot set sample format error". Any idea of what may be happening and how I can fix this?
Thanks in advance.
FFMPEG OUTPUT
user@user:~$ ffmpeg -f alsa -acodec pcm_s32le -ac 2 -ar 48000 -i hw:2,0 out.wav
ffmpeg version N-85548-g3390a2b Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
configuration: --enable-gpl --enable-libx264 --enable-libx265 --enable-libvpx --enable-libvorbis --enable-libopus --enable-ffplay
libavutil 55. 61.100 / 55. 61.100
libavcodec 57. 92.100 / 57. 92.100
libavformat 57. 72.101 / 57. 72.101
libavdevice 57. 7.100 / 57. 7.100
libavfilter 6. 84.101 / 6. 84.101
libswscale 4. 7.101 / 4. 7.101
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100
[alsa @ 0x34b6780] cannot set sample format 0x10008 10 (Invalid argument)
hw:2,0: Input/output error
ARECORD OUTPUT:
user@user:~$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: PCH [HDA Intel PCH], device 0: ALC3236 Analog [ALC3236 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: DUOCAPTURE [DUO-CAPTURE], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
After Deimus help I checked the setting for my card in arecord and used the correct line for FFMPEG (Notice that I have changed the capture frequency on the hardware).
ARECORD OUTPUT
user@user:~$ arecord --dump-hw-params -D hw:2,0
Recording WAVE 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
HW Params of device "hw:2,0":
--------------------
ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT: S24_3LE
SUBFORMAT: STD
SAMPLE_BITS: 24
FRAME_BITS: 48
CHANNELS: 2
RATE: 44100
PERIOD_TIME: (1020 1981429)
PERIOD_SIZE: [45 87381]
PERIOD_BYTES: [270 524286]
PERIODS: [2 1024]
BUFFER_TIME: (2040 3962858)
BUFFER_SIZE: [90 174762]
BUFFER_BYTES: [540 1048572]
TICK_TIME: ALL
--------------------
arecord: set_params:1233: Sample format non available
Available formats:
- S24_3LE
Correct command line
ffmpeg -f alsa -acodec pcm_s24le -ac 2 -ar 44100 -i hw:2,0 out.wav
回答1:
Use the --dump-hw-params
option of arecord
tool to check the supported sample formats.
Man page for arecord
Then you can use the -sample_fmt
option of ffmpeg
to specficy the format eg. s32
Audio options for ffmpeg are here
回答2:
Refer to output of
arecord --dump-hw-params -D hw:2,0
wherehw:2,0
is your target device.arecord
output will show available sample formats underFORMAT
andAvailable formats
. Other useful info is also shown such asCHANNELS
andRATE
. Example:-------------------- ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED FORMAT: S16_LE S32_LE SUBFORMAT: STD SAMPLE_BITS: [16 32] FRAME_BITS: [32 64] CHANNELS: 2 RATE: [44100 192000] PERIOD_TIME: (83 11888617) PERIOD_SIZE: [16 524288] PERIOD_BYTES: [128 4194304] PERIODS: [2 32] BUFFER_TIME: (166 23777234) BUFFER_SIZE: [32 1048576] BUFFER_BYTES: [128 4194304] TICK_TIME: ALL -------------------- Available formats: - S16_LE - S32_LE
In your
ffmpeg
command choose the appropriate decoder to match the sample format. You can also choose the channels and sample rate:ffmpeg -f alsa -c:a pcm_s32le -channels 2 -sample_rate 44100 -i hw:2,0 output.wav
Examples of decoders to use:
S16LE
=-c:a pcm_s16le
S24LE
=-c:a pcm_s24le
S32LE
=-c:a pcm_s32le
Also see ffmpeg -decoders
and FFmpeg Documentation: ALSA input.
来源:https://stackoverflow.com/questions/44049854/alsa-cannot-set-sample-formatffmpeg