I would like a simple working example of using just libavformat to mux video. There are nice examples (doc/examples/muxing.c) that show encoding with libavcodec, muxing with libavformat and saving the data with libavio. However, there is no example I know of that uses libavformat by itself, feeding in encoded data in a buffer and getting muxed data in a buffer.
The difficulty is two-fold: one, adding a stream with avformat_new_stream(AVFormatContext *s, const AVCodec *c) requires a reference to the codec; and two, the output from muxing is passed to AVFormatContext->pb which is an AVIOContext*. Thus there seems to be no (obvious) way to extricate libavformat from the other libav libraries.
See also: This question mentions a way to not use libavio: Get TS packets into buffer from libavformat
You can avoid dependencies on libavcodec library, but you need the header files (for example, avcodec.h).
The scheme is as follows:
To get the output, you always have to use the concept of
AVIOContext. You can avoid using the built-in protocols. To do this you need to create your ownAVIOContext(::avio_alloc_context).UPD
To create your own
AVIOContext, you have to do something like this