On Wed, May 20, 2020 at 10:10 AM Jesper Taxbøl <jes...@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.
avio_open_dyn_buf(&avContext->pb);
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
}
av_free(buffer);

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

- Richard


> Kind regards
>
> Jesper
>
> _______________________________________________
> Libav-user mailing list
> Libav-user@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-requ...@ffmpeg.org with subject "unsubscribe".
_______________________________________________
Libav-user mailing list
Libav-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
libav-user-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to