[FFmpeg-devel] [PATCH] Efficiently support several output pixel formats in Cinepak decoder
sw at jkqxz.net
Sun Feb 5 14:12:37 EET 2017
On 05/02/17 10:02, u-9iep at aetey.se wrote:
> On Fri, Feb 03, 2017 at 08:21:37PM +0100, wm4 wrote:
>> With your special use-case (special as in does not fit into the API
>> conventions of libavcodec), you might be better off with creating your
>> own standalone cinepak decoder. That's not a bad thing; there's plenty
>> of multimedia software that does not use libavcodec. Part of the reason
>> is that one library can't make everyone happy and can't fit all
> To make it a bit more clear, my use case is
> - various devices and videobuffers
> - different applications which are not feasible to patch/teach/replace
> Replacing ffmpeg with something else or modifying the applications
> unfortunately does not fit there, that's also why get_format() does not help.
Even if you need to support such a use-case, doing it via the get_format() callback is still the right thing to do. Once you've done that, all normal applications (including ffmpeg.c itself) can use the standard API as it already exists to set the output format. For your decoding-into-framebuffer case the calling application must already be fully aware of the state of the framebuffer (after all, it has to be able to make a suitable AVFrame to pass to get_buffer2() so that you can avoid the extra copy), so adding get_format() support to also communicate the format is not onerous.
Then, if you have a proprietary application which cannot be modified because you don't have the source, you could make a shim layer like:
static enum AVPixelFormat get_format_by_env_var(pix_fmt_list)
requested_pix_fmt = getenv(SOMETHING);
if (requested_pix_fmt in pix_fmt_list)
int avcodec_open2(AVCodecContext *avctx)
avctx->get_format = &get_format_by_env_var;
and LD_PRELOAD it into the application to achieve the same result (insofar as that is possible - it seems unlikely that it will be able to use get_buffer() appropriately, so there are probably going to be more redundant copies in the application and you would need to patch it directly to eliminate them).
More information about the ffmpeg-devel