[FFmpeg-devel] [PATCH 1/2] lavf/avio: add avio_vprintf()

Soft Works softworkz at hotmail.com
Thu Jun 16 19:23:58 EEST 2022



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of
> Nicolas George
> Sent: Sunday, June 12, 2022 7:01 PM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel at ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 1/2] lavf/avio: add avio_vprintf()
> 
> Stefano Sabatini (12022-06-12):
> > Updated.
> 
> Hi. Since it is somewhat related, I would appreciate if you gave your
> opinion on the option of having a good string API in FFmpeg:
> 
> https://ffmpeg.org/pipermail/ffmpeg-devel/2021-December/290226.html
> 
> Eventually, I would like to have the more generic writers from
> ffprobe
> (JSON, XML) in lavu to be used by diagnostic filters. But I will not
> be
> doing that with pedestrian strings.

Hi,

as mentioned a while ago, I am quite interested in this and I would be 
glad when it would be possible to find a way for going forward.
My primary interest would be the generalization of ffprobe string
writing code, from which I have two duplicates by now. I had put further
work on hold as I became aware that were plans or proposals for this.

Now I've read your "Intro to AVWriter" from April 2021 and I have some 
questions.


> ## Scenario 2: Concatenating the string into a message.
> 
> Let us say you have two foobars to present to the user. Good old C:
> 
>   char msg[2500], foo1_buf[1000], foo2_buf[1000];
>   av_foobar_to_string(foo1_buf, sizeof(foo1_buf), foo1);
>   av_foobar_to_string(foo2_buf, sizeof(foo2_buf), foo2);
>   snprintf(msg, sizeof(msg), "F%d = [ %s, %s ]", num, foo1_buf, foo2_buf);
> 
> But it's ugly. Less ugly, but more complicated:

[skip that version]

> Well, that was the first thing AVWriter was meant to do: allow to build
> strings by concatenating them together. So, the AVWraper version of this
> code:
> 
>   char msg[2500];
>   AVWriter wr = av_buf_writer_array(msg);
>   av_writer_printf(wr, "F%d = [ ", num);
>   av_foobar_write(wr, foo1);
>   av_writer_print(wr, ", ");
>   av_foobar_write(wr, foo2);
>   av_writer_print(wr, " ]");

There are cases where it might be preferable to subsequently append to 
a buffer like that, but it requires many lines of code and it's not as 
easy to get a picture of how the produced string will actually look like.
Maybe you meant it just as one possible example to use AVWriter, but in
this context it looks like as if that's the supposed way to replace the
"Good old C" version?

When you would ask me which code I would _wish_ to be able to write 
in this example case, then it would be this:

  char msg[2500];
  snprintf(msg, sizeof(msg), "F%d = [ %s, %s ]", num, foo1, foo2);


Of course it doesn't need to be snprintf, it could also be av_xprintf().
It would also be fine to have some macro around those params like 
XX(foo1). Or a custom format specifier would also be fine.
Basically I think there are a number of possible ways, but I'm not sure
whether this would be possible with regards to the automatisms you
are planning to checking for a matching string conversion function?

This might be a tough one: it would be cool when this could be used
in av_log() calls for logging, but in this case it would be of course 
required that the string writing will be performed upstream, only when 
the log level condition would be satisfied. Could that even work?


PS: Yes, I have read it to the end; the mentioned av_writer_fmt()
might be related to what I'm asking, but I wasn't sure.

Thanks,
softworkz










More information about the ffmpeg-devel mailing list