you can take this as an example you can follow
iobuffer = (unsigned char*) av_malloc(bufferSize);
pFormatCtx = avformat_alloc_context();
pFormatCtx->pb = avio_alloc_context(iobuffer, bufferSize, 0,receiver, IORead, NULL, );
err = avformat_open_input(&pFormatCtx, "", NULL, NULL);
where pFormatCtx is an AvFormatContext and ioread is a function that fills your buffer from the receiver
For your second question i've also faced the same problems and unfortunately i didn't find a solution hope you find it and share it