mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-20 21:00:41 +08:00
doc/examples/encode_audio: fix hardcoded stereo sample stride
The sample generation loop hardcodes a stride of 2 (stereo) with samples[2*j], but the channel count is dynamically selected by select_channel_layout() which picks the layout with the highest channel count. If the encoder supports more than 2 channels, samples will be written at wrong offsets. Use c->ch_layout.nb_channels as the stride instead. Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
This commit is contained in:
@@ -218,10 +218,10 @@ int main(int argc, char **argv)
|
||||
samples = (uint16_t*)frame->data[0];
|
||||
|
||||
for (j = 0; j < c->frame_size; j++) {
|
||||
samples[2*j] = (int)(sin(t) * 10000);
|
||||
samples[c->ch_layout.nb_channels*j] = (int)(sin(t) * 10000);
|
||||
|
||||
for (k = 1; k < c->ch_layout.nb_channels; k++)
|
||||
samples[2*j + k] = samples[2*j];
|
||||
samples[c->ch_layout.nb_channels*j + k] = samples[c->ch_layout.nb_channels*j];
|
||||
t += tincr;
|
||||
}
|
||||
encode(c, frame, pkt, f);
|
||||
|
||||
Reference in New Issue
Block a user