[Libav-user] Output to memory instead of file

Jesper Taxbøl jesper at taxboel.dk
Thu May 21 17:21:02 EEST 2020


Thank you. I will dig into this solution.

In parallel I found an example on how to setup a callback with buffer data.
https://gist.github.com/AlexVestin/15b90d72f51ff7521cd7ce4b70056dff

Den tor. 21. maj 2020 kl. 05.17 skrev Richard Hussong <rhussong at westpond.com
>:

>
>
> 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.
> 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 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".
>
> _______________________________________________
> 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".



-- 
Jesper Taxbøl
+45 61627501
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200521/141f426c/attachment.html>


More information about the Libav-user mailing list