[Libav-user] Output to memory instead of file

Richard Hussong rhussong at westpond.com
Thu May 21 06:16:48 EEST 2020

On Wed, May 20, 2020 at 10:10 AM Jesper Taxbøl <jesper at taxboel.dk> wrote:

> Hi,
> I am using libavformat to encapsulate video and audio in a mpegts
> container.
> I have it working when I outputting to a file, but I need the data in
> memory for further distribution.
> I have been seeking for a callback or some other way to extract the bytes
> normally is written to the output file.
> How would I go about outputting the data to memory instead?

Use avio_open_dyn_buf and avio_close_dyn_buf to get libavformat to write to
a buffer and return the buffer address. The usual way to do it is:

// Create a dynamic buffer for your AVFormatContext and do some writes.
av_write_frame(avContext, ...);
// Get the buffer contents and length, and do what you like with them.
uint8_t *buffer = 0;
int nbytes = avio_close_dyn_buf(&avContext->pb, &buffer);
if (nbytes > 0) {
  // whatever

You need to do this little dance for each block of output data you want to

- Richard

> Kind regards
> Jesper
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200520/60713f2e/attachment.html>

More information about the Libav-user mailing list