问题
I am trying to write PCMU G.711 enocded data into avi
multimedia container using below program which yields Error occurred when opening output file: Operation not permitted
and when using mov
container, it yields Error occurred when opening output file: Invalid argument
. I set AV_CODEC_ID_PCM_U16LE
as audio codec of output format and AV_SAMPLE_FMT_S16
as sample format.
What's the problem here? Thanks in advance!
回答1:
You're writing AV_CODEC_ID_PCM_U16LE, which isn't G711, but raw PCM unsigned 16bits data. AVI/mov don't support this (they support signed 16 bits PCM data, or 8 bits unsigned PCM data, but not unsigned 16-bits PCM data). So that's why you're getting this error. But anyway, you don't want to use that anyway, since it's not G711.
G711 comes in two types: mu-law or a-law, so you have to decide which of the two you want, and then use the correct AVCodecID (AV_CODEC_ID_PCM_ALAW or CODEC_ID_PCM_MULAW).
来源:https://stackoverflow.com/questions/31846650/avformat-write-header-return-error-code-when-trying-to-write-pcmu-encoded-frame