2

I want to write silence/zeroed audio sampled data into mov media container file inside audio data. My audio data is G711 linear PCM-mulaw encoded data with one channel. Currently my code looks like:

AVFrame* pSilentData = av_frame_alloc();
memset(&pSilentData->data[0], 0, iDataSize);
pkt.data = (uint8_t*) pSilentData;
pkt.size = iDataSize;

// ...

av_freep(&pSilentData->data[0]);
av_frame_free(&pSilentData);

But this sounds noise like dot dot instead of silence. What's the problem?

Paul R
  • 208,748
  • 37
  • 389
  • 560
Kaidul
  • 15,409
  • 15
  • 81
  • 150
  • Please post *actual code*, not an approximation, otherwise people may waste time addressing non-existent issues. Use copy and paste (i.e. don't re-type code) otherwise errors creep in. – Paul R Aug 14 '15 at 09:43
  • Sorry, that was a typo. My actual code is okay and `unit8_t*`. Really sorry for your inconvenience. :( – Kaidul Aug 14 '15 at 09:45
  • OK - down-vote removed. Please be sure to post actual code in future (copy and paste is your friend). – Paul R Aug 14 '15 at 10:06

1 Answers1

4

For µ-law audio the zero value is represented as 0xff, so change:

memset(&pSilentData->data[0], 0, iDataSize);

to:

memset(&pSilentData->data[0], 0xff, iDataSize);
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Thanks! It solved my problem. I am grateful to you despite of the downvote :) – Kaidul Aug 14 '15 at 10:02
  • 1
    The down-vote was for posting inaccurate code, but since this has now been remedied I have removed the down-vote. – Paul R Aug 14 '15 at 10:05