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

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

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

MSC_Edge
Hope no one minds me posting twice, different topic this time. Since there
appears to be an ffmpeg error with writing out segmented flv files, I
decided to do what the ffmpeg was doing using command line by myself in
code. Especially since for our project we need to store an index of
key-frames associated with the flv file for fast access of frames during
playback.

So, I can get the 'pos' of an AVPacket that has been read from a file using
av_read_frame.

However, I can't get the 'pos' of the AVPacket that has just been written
using av_write_frame.

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.

If I try to use avformat_open_input to open the same file that's already
open for writing, it throws an error: "Invalid data found when processing
input".  This still happens even if I write the head, first packet, and
flush too.

Anyone know how to do this in real time like I'd like to do? Or do I need to
work around it?



--
Sent from: http://libav-users.943685.n4.nabble.com/
_______________________________________________
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: How to get the byte position of a just written av_write_frame?

Strahinja Radman

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
[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: How to get the byte position of a just written av_write_frame?

MSC_Edge
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 it.
 
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.

-Matt

On Wed, Jan 29, 2020 at 1:58 AM Strahinja Radman <[hidden email]> wrote:

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