Click here to Skip to main content
15,036,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the input mp3 is single channel with 32000 sample rate, 16bit signed.

I am using ffmpeg 2.6 to decode mp3 on ios9.3.2 pad. It get white noise only. but it works on windows.I record the decoded PCM to file and use tool to play it. when I changed the bit set to 32. I can hear the original sound with noise in background ,and faster playing speed. if set to 8bit or 16bit, only white noise can be heard.

When I update the ffmpeg to 3.1.1, decoding failed for inconsistent channel configuration. I was really puzzled , how could this happened. I have not set any channel parameter yet nor necessary.

please help me.

What I have tried:

I have compare the input mp3 frame and output pcm on both system.
the input is the same as I read the mp3 frame from mp3 file , but get the totally different output. code as below.

int FfmpegAudioDecoder::InitDecoderFFMpeg()
	codec_ = avcodec_find_decoder((AVCodecID)param_->codec_id);

	if (!codec_)
		failed_ = true;
		av_log(0, log_level_, "Unsupported codec!");
		return -1;

	codec_ctx_ = avcodec_alloc_context3(codec_);

	if (avcodec_open2(codec_ctx_, codec_, 0)  < 0)
		failed_ = true;
		return -1;

	if (!decoded_frame_) {
		if (!(decoded_frame_ = av_frame_alloc())) {
			av_log(0, log_level_, "Could not allocate audio frame\n");
			return -1;

<pre>int FfmpegAudioDecoder::DecodeAudio(const WktData * encode_packet , WktData* pcm_packet)
	int len = 0;
	int pkt_size = 0;
	unsigned char * pkt_data = 0;

	AVPacket avpkt; = encode_packet->data;
	avpkt.size = encode_packet->data_length;


	int got_frame = 0;
	pkt_size = avpkt.size;
	pkt_data =;

	while (pkt_size > 0)
		len = avcodec_decode_audio4(codec_ctx_, decoded_frame_, &got_frame, &avpkt);
		if (len < 0)
			return -1;

		/*if (EncodeAudio(decoded_frame) < 0)
			return -1;*/

	/*	int data_size = av_get_bytes_per_sample(codec_ctx_->sample_fmt);
		int i, ch;
		for (i = 0; i<decoded_frame_->nb_samples; i++)
			for (ch = 0; ch<codec_ctx_->channels; ch++)
				fwrite(decoded_frame_->data[ch] + data_size*i, 1, data_size, outfile);*/
		pkt_size -= len;
		pkt_data += len;

	return 0;
Updated 30-Nov-16 0:30am

1 solution

the solution looks really simple.
AVPacket avpkt;

// set values AFTER init = encode_packet->data;
avpkt.size = encode_packet->data_length;

I am a bit confused that your old code works on Windows. But I know that the Objective-C runtime initializes all values to null, but on Windows nothing happens.

PS: since iOS 9.3.3 you can decode H.264 like HD-TV
Charly LEE 30-Nov-16 21:37pm
yes, it runs good on windows. what do you mean by "initailize all values to null" in the code? since the encodeing package is a user defined struct which will be set for each calling.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900