[FFmpeg-devel] [RFC] Unified string / stream API

Nicolas George george at nsup.org
Thu Feb 25 13:43:02 EET 2021


We have more and more users demanding a better output for the side
information generated by filters and other components than savage log
output.

That probably means moving the formatted writer features of ffprobe into
proper libavutil APIs. But ffprobe only outputs to standard output, a
proper API should be capable of writing to a memory buffer or an AVIO
context. And it needs to be efficient, as it can happen once per frame
or more: no dynamic allocation if it can be avoided.

The enhancement I propose below addresses that and more. I am
considering working on at least one writer (probably JSON) soon.

Please comment.

Regards,

-- 
  Nicolas George


Nicolas George (12020-12-31):
> This mail is about a project I have to make FFmpeg's API and
> infrastructure more convenient. For a common introduction, see this thread:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2020-December/274167.html
> 
> int av_foo_to_string(char *buf, size_t buf_size, AVFoo *foo);
> int av_bar_to_string(char *buf, AVBar *bar); /**< buf should be at least 42 */
> int av_qux_to_string(char **buf, AVQux *qux); /**< av_freep() buf after */
> 
> This is annoyingly inconsistent. To make the API more pleasant, a consistent
> way of returning strings and byte buffers is needed. Unfortunately, only the
> method with dynamic allocation is generic enough to serve everywhere, but it
> is also the most expensive and annoying to use.
> 
> Fact: we have frame and buffer pools. It means we consider that dynamic
> allocations that happen at least once per frame are worth optimizing, even
> at the cost of non-trivial code.
> 
> The AVWriter API is a more elegant and generic version of the AVBPrint API.
> By default, it works with a buffer on stack but switches to dynamic
> allocation as soon as needed, with many extra features.
> 
> The benefits I promise from this:
> 
> - Factored error handling, with only a single test at the end.
> 
> - Unified string return API, with the efficiency of static buffers when
>   possible and the power of dynamic allocation when necessary.
> 
> - The ability to use for byte buffers as well.
> 
> - On-the-fly filtering, for example escaping or changing the character
>   encoding, without intermediate buffers.
> 
> - The ability to directly plug with the string objects used by other
>   libraries or languages.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20210225/35d4b4f7/attachment.sig>


More information about the ffmpeg-devel mailing list