Alsa cannot set sample format[FFMPEG]
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
ffmpeg default audio codec instead of specifying it with acodec option
I figured this one out myself by reading ffmpeg source code. It seems when codec is not specified and alsa device is used. FFmpeg will default to pcm 16-bit samples instead. Code to set the default here and the default macro here.
PyAv av.open() specify used codec
I'll answer my own question because I figured it out. I read ffmpeg source code and saw that when using alsa audio device and codec is not specified ffmpeg will default to use signed 16-bit pcm samples. Code here. By further exploring the source code the codec value comes from AVFormatContext::audio_codec_id struct field.
Now figuring out that PyAV using Cython to use FFmpeg and by reading PyAV source code of Container class I noticed it holds AVFormatContext
in it's self.ptr
variable. Then reading InputContainer
source code and especially before calling avformat_open_input function to open the alsa device. Specifying the used audio codec is not supported by PyAV.
I forked the library and ended quickly hacking the solution for me. Now the question is would it be possible to add this feature to PyAV to force the codec used for the audio? In this case when the device is using pcm samples and relying ffmpeg to use choose the default one it will always use 16-bit samples and in my case I needed to use 32-bit samples.
Hopefully this helps someone and save them the trouble I went through :) I also posted this same answer for PyAV issue here.
ffmpeg fails with: Unable to find a suitable output format for 'pipe:'
typo
Use -preset
, not - preset
(notice the space). ffmpeg
uses -
to indicate a pipe, so your typo is being interpreted as a piped output.
pipe requires the -f
option
For users who get the same error, but actually want to output via a pipe, you have to tell ffmpeg
which muxer the pipe should use.
Do this with the -f
output option. Examples: -f mpegts
, -f nut
, -f wav
, -f matroska
. Which one to use depends on your video/audio formats and your particular use case.
You can see a list of muxers with ffmpeg -muxers
(not all muxers can be used with pipe).
ALSA: asound.conf file read but not used with arecord
Putting entries like format
and rate
into a slave definition restricts the possible configurations that an application can choose.
Most applications ask the device what configurations it actually supports. However, aplay
/arecord
do not; they always try to use the configuration you have set with parameters (or their silly defaults).
ALSA programming
The problem is that capture_handle
is NULL.
You cannot drain a device that does not exist.
Related Topics
How to Run Elasticsearch 2.1.1 as Root User in Linux MAChine
How to Change the Soname of a Binary Directly
How to Read the Last Line of a Text File into a Variable Using Bash
Ldd Doesn't Work on Dynamically Linked Binary
Iterating Over Lists in Makefiles
Configure and Build Opencv to Custom Ffmpeg Install
"Current" in Linux Kernel Code
How to Force a Firefox Page Refresh from Linux Console
How to Tail -F the Latest Log File with a Given Pattern
How to Implement a Practical Fiber Scheduler
Poorly-Balanced Socket Accepts with Linux 3.2 Kernel VS 2.6 Kernel
How to Limit the Cache Used by Copying So There Is Still Memory Available for Other Caches
Calculate Total Used Disk Space by Files Older Than 180 Days Using Find