[Libav-user] Output to memory instead of file

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] Output to memory instead of file

Jesper Taxbøl
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?

Kind regards

Jesper


_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Output to memory instead of file

Richard Hussong


On Wed, May 20, 2020 at 10:10 AM Jesper Taxbøl <[hidden email]> 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
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Output to memory instead of file

Jesper Taxbøl
Thank you. I will dig into this solution.

In parallel I found an example on how to setup a callback with buffer data.

Den tor. 21. maj 2020 kl. 05.17 skrev Richard Hussong <[hidden email]>:


On Wed, May 20, 2020 at 10:10 AM Jesper Taxbøl <[hidden email]> 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
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".


--
Jesper Taxbøl
+45 61627501


_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".