[FFmpeg-devel] [PATCH 07/23] fftools/sync_queue: allow requesting a specific number of audio samples
James Almer
jamrial at gmail.com
Thu Mar 30 02:41:28 EEST 2023
On 3/25/2023 4:15 PM, Anton Khirnov wrote:
> +static void offset_audio(AVFrame *f, int nb_samples)
> +{
> + const int planar = av_sample_fmt_is_planar(f->format);
> + const int planes = planar ? f->ch_layout.nb_channels : 1;
> + const int bps = av_get_bytes_per_sample(f->format);
> + const int offset = nb_samples * bps * (planar ? 1 : f->ch_layout.nb_channels);
> +
> + av_assert0(bps > 0);
> + av_assert0(nb_samples < f->nb_samples);
> +
> + for (int i = 0; i < planes; i++) {
> + f->extended_data[i] += offset;
This apparently can end up unaligned. It's (afaict) the source of the
segmentation fault Michael reported. If you run his command with
-cpuflags 0 it doesn't crash.
You may need to allocate a new frame and copy the data instead of making
a reference in such scenarios.
> + if (i < FF_ARRAY_ELEMS(f->data))
> + f->data[i] = f->extended_data[i];
> + }
> + f->linesize[0] -= offset;
> + f->nb_samples -= nb_samples;
> + f->duration = av_rescale_q(f->nb_samples, (AVRational){ 1, f->sample_rate },
> + f->time_base);
> + f->pts += av_rescale_q(nb_samples, (AVRational){ 1, f->sample_rate },
> + f->time_base);
> +}
More information about the ffmpeg-devel
mailing list