Write silence audio data into file ffmpeg C++
Asked Answered
E

1

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?

Emsmus answered 14/8, 2015 at 9:32 Comment(3)
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.Parietal
Sorry, that was a typo. My actual code is okay and unit8_t*. Really sorry for your inconvenience. :(Emsmus
OK - down-vote removed. Please be sure to post actual code in future (copy and paste is your friend).Parietal
P
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);
Parietal answered 14/8, 2015 at 9:45 Comment(2)
Thanks! It solved my problem. I am grateful to you despite of the downvote :)Emsmus
The down-vote was for posting inaccurate code, but since this has now been remedied I have removed the down-vote.Parietal

© 2022 - 2024 — McMap. All rights reserved.