0

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!

Kaidul
  • 15,409
  • 15
  • 81
  • 150

1 Answers1

2

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).

Ronald S. Bultje
  • 10,828
  • 26
  • 47
  • Many thanks for your answer! Well, I understand when I was using G711 PCM data for which `CODEC_ID_PCM_MULAW` has match. But now I am using raw PCM data (`short *`G711 PCM data after decoding) and for this what should be the correct AVCodecID? And what should the sample format? `AV_SAMPLE_FMT_S16` ? And should I change the length of data like `dataSize >>= 1` like here: http://ffmpeg.org/doxygen/trunk/muxing-example_8c-source.html 119 line? – Kaidul Aug 07 '15 at 08:41
  • If you want to write raw audio in a file, use AV_CODEC_ID_PCM_S16LE. I'd follow the example code if that helps get it working, I don't know what your code looks like exactly. – Ronald S. Bultje Aug 07 '15 at 12:35
  • Sir, can you take a look http://stackoverflow.com/questions/31917032/pts-and-dts-calculation-for-video-and-audio-frames ? – Kaidul Aug 10 '15 at 10:21