[FFmpeg-devel] [PATCH 3/3] ffmpeg: try to guess a good value for the thread message queue.

Michael Niedermayer michaelni at gmx.at
Tue Feb 17 03:54:48 CET 2015


On Mon, Feb 16, 2015 at 10:22:17PM +0100, Nicolas George wrote:
> The current value, 8, is too low to be really useful.
> The heuristic tries to allocate enough room for 10 seconds.
> 
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
>  ffmpeg.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> 
> On my hardware, recording from v4l2 and ALSA produces ALSA underruns if the
> message queue is below ~256-512.
> 
> 
> diff --git a/ffmpeg.c b/ffmpeg.c
> index a52de20..990ce9e 100644
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -3412,9 +3412,29 @@ static void free_input_threads(void)
>      }
>  }
>  
> +static int eval_thread_queue_size(InputFile *f)
> +{
> +    int i, s;
> +    int64_t sec = 10, fps = 0;
> +
> +    for (i = 0; i < f->ctx->nb_streams; i++) {
> +        AVStream *st = f->ctx->streams[i];
> +        AVCodecContext *c = st->codec;
> +        if (c->sample_rate && c->frame_size) {
> +            fps += sec * (c->sample_rate / c->frame_size + 1);
> +        } else if (st->avg_frame_rate.num && st->avg_frame_rate.den) {
> +            fps += 1 + av_rescale(sec, st->avg_frame_rate.num, st->avg_frame_rate.den);
> +        } else {
> +            fps += 25 * sec;
> +        }
> +    }
> +    s = FFMAX(3, FFMIN(20, av_log2(fps) + 1));

iam a bit concerned about the possibility of this unneccesarily
allocating a million packets
i think IIUC this amount will actually be alloated no matter if its
needed or not

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150217/e025d888/attachment.asc>


More information about the ffmpeg-devel mailing list