[Libav-user] How to get the byte position of a just written av_write_frame?

Matthew Czarnek mczarnek at edge360.com
Wed Jan 29 18:06:06 EET 2020

Thank you Strahinja. Yeah I probably could do something like that. Would
have to be extremely careful to get precisely the right byte, even when we
have audio in there too. Seems a little fragile but might be something to

At the moment, playing around with an idea that involves using AVIOContext
to create a custom write_packet function that allows me to spy on the
process of writing the frame(s) to the file. In this way, I believe I can
write to the file and flush it every frame and at the same time I can grab
the file pointer upon writing. Also not sure about multiple streams and
what will popup but think I can make it work.

Seems like someone who knows what they are doing and codes for ffmpeg
really should alter the pos member of AVPacket after it's written out as
well as read in for anyone else encountering this issue though. I'm sure
I'm not the only one who would like to do something like this.


On Wed, Jan 29, 2020 at 1:58 AM Strahinja Radman <dr.strashni at gmail.com>

>> I've tried looking for callbacks, looking at the packet itself, looking at
>> the AVFormatContext, AVIO, AVStream, etc. And I can't find a way to do it.
>> Would be really nice if av_write_frame would set the new pos after writing
>> the packet to the file.
> I am guessing that FLV container has a known header size. Maybe you can use
> size value of a AVPacket + header + all the AVPackets before and based on
> that
> calculate what your offset for that IDR packet is? Just an idea, not sure
> if it will work.
> --
> Regards
> Strahinja Radman
> _______________________________________________
> 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/20200129/1d0286fd/attachment.html>

More information about the Libav-user mailing list