Answer the question
In order to leave comments, you need to log in
How to remove crackling sound when downsampling using ffmpeg?
Hello. I'm having a problem changing sample rate and sample format after decoding using ffmpeg. More precisely, with a decrease in it from 48000 to 44100. A background crack appears in the sound. (There is no crackling when increasing from 44100 to 48000.)
After calling the function:
ErrorCode := avcodec_decode_audio4(AudioCodecContext, AudioFrame,
@FrameFinished, @Packet);
if FrameFinished = 1 then
begin
swr := swr_alloc;
try
av_opt_set_int(swr, 'in_channel_layout', AudioFrame.channel_layout, 0);
av_opt_set_int(swr, 'out_channel_layout', AV_CH_LAYOUT_STEREO, 0);
av_opt_set_int(swr, 'in_sample_rate', AudioFrame.sample_rate, 0);
av_opt_set_int(swr, 'out_sample_rate', 44100, 0);
av_opt_set_sample_fmt(swr, 'in_sample_fmt', TAVSampleFormat(AudioFrame.format), 0);
av_opt_set_sample_fmt(swr, 'out_sample_fmt', AV_SAMPLE_FMT_S16, 0);
swr_init(swr);
OutSample := av_rescale_rnd(
swr_get_delay(swr, AudioFrame.sample_rate) + AudioFrame.nb_samples,
44100, AudioFrame.sample_rate, AV_ROUND_UP );
av_samples_alloc(@OutputBuffer, nil, 2, OutSample,
AV_SAMPLE_FMT_S16, 0);
ConvertSize := swr_convert(swr, @OutputBuffer, OutSample,
@AudioFrame.data[0], AudioFrame.nb_samples);
finally
swr_free(@swr);
end;
ConvertSize := ConvertSize * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16) * 2 {channel numbers};
BufferDest.Write(OutputBuffer, ConvertSize);
av_free(outputBuffer);
Stereo (2 Channels), Signed 16 bit, 44100
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question