/*When it is not a planar arrangement, data[1] is empty, and all the data is interleaved in data[0]. This can result in a segmentation fault when accessing data[ch] .*/ //So I delete the code below: for (i = 0; i < frame->nb_samples; i++) for (ch = 0; ch < dec_ctx->ch_layout.nb_channels; ch++) fwrite(frame->data[ch] + data_size*i, 1, data_size, outfile); //And I write this instead // L R data order if (av_sample_fmt_is_planar(dec_ctx->sample_fmt)) { // planar£ºLLL...RRR... in different data[ch] for (ch = 0; ch < dec_ctx->ch_layout.nb_channels; ch++) { fwrite(frame->data[ch], 1, frame->linesize[0], outfile); // only linesize[0] has data. } } else { // not planar£ºLRLR...all in data[0] fwrite(frame->data[0], 1, frame->linesize[0], outfile); }