Skip to content

Commit 3bd4c2f

Browse files
committed
fix planar audio format buffer size
1 parent 2550f63 commit 3bd4c2f

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

FFmpegTutorial/Classes/common/FFTPlayerHeader.m

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@
1919
const char * av_sample_fmt_to_string(int format)
2020
{
2121
return av_get_sample_fmt_name(format);
22-
if (AV_SAMPLE_FMT_S16 == format) {
23-
return "s16";
24-
} else if (AV_SAMPLE_FMT_S16P == format) {
25-
return "s16p";
26-
} else if (AV_SAMPLE_FMT_FLT == format) {
27-
return "float";
28-
} else if (AV_SAMPLE_FMT_FLTP == format) {
29-
return "floatp";
30-
} else {
31-
return "unknow";
32-
}
3322
}
3423

3524
enum AVSampleFormat MRSampleFormat2AV (MRSampleFormat mrsf){
@@ -164,6 +153,10 @@ int audio_buffer_size(AVFrame *frame)
164153
{
165154
const int fmt = frame->format;
166155
int chanels = frame->ch_layout.nb_channels;
156+
//如果是平面的,那么上层需要的是一个平面的,所以改为1
157+
if (av_sample_fmt_is_planar(frame->format)) {
158+
chanels = 1;
159+
}
167160
int data_size = av_samples_get_buffer_size(NULL, chanels, frame->nb_samples, fmt, 1);
168161
return data_size;
169162
}

0 commit comments

Comments
 (0)