[Libav-user] How to pass custom information to AVPacket and receive it in AVFrame?

Wodzu brucedickinson at wp.pl
Sun Sep 29 13:56:10 EEST 2024


Hello,   I am decoding a raw h264 stream based on example from:  github.com https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/decode_video.c   The problem is that I need to somehow tie up a custom information to AVPacket and receive it in AVFrame. Because it is raw h264, I am sure that one AVPacket sent is equal to one AVFrame received.   I've tried the following: AVPacket->opaque but this field is not passed to AVFrame->opaque.  So I've tried some ugly hacks and use one of these fields:   av_packet->duration =   av_packet->pts =   av_packet->dts =   av_packet->pos =    These can be read from frame after calling: avcodec_receive_frame(codec_context, frame);   However, there are two strange things that are occurring:   When I am sending the very first IFrame (which also contains PPS and SPS) via avcodec_send_packet(codec_context, packet) and then I want to receive a corresponding frame via avcodec_receive_frame(), the function will return me AVERROR(EAGAIN). I don't understand why it needs more data if what it got is a full IFrame?. I need to send two more packets (each containing exactly one frame) to get first frame out of avcodec_receive_frame(). Why the decoder decides to store two frames in its buffer before sending me anything.  Even though the frames are received in correct order (I've saved them as images and checked them), the fields like av_packet->pos which was passed to frame and can be read through frame->pkt_pos are in not correct order. Take a look:   avcodec_send_packet - (av_packet->pos): 0  avcodec_send_packet - (av_packet->pos): 1  avcodec_send_packet - (av_packet->pos): 2  avcodec_receive_frame - (frame->pkt_pos): 0 <- first frame received after sending three packets, each containing one frame.  avcodec_send_packet - (av_packet->pos): 3  avcodec_receive_frame - (frame->pkt_pos): 2 <- mixed order, pkt_pos should be 1?  avcodec_send_packet - (av_packet->pos): 4  avcodec_receive_frame - (frame->pkt_pos): 1  avcodec_send_packet - (av_packet->pos): 5  avcodec_receive_frame - (frame->pkt_pos): 3  avcodec_send_packet - (av_packet->pos): 6  avcodec_receive_frame - (frame->pkt_pos): 4  avcodec_send_packet - (av_packet->pos): 7  avcodec_receive_frame - (frame->pkt_pos): 5  avcodec_send_packet - (av_packet->pos): 8  avcodec_receive_frame - (frame->pkt_pos): 6  avcodec_send_packet - (av_packet->pos): 9  flush called  avcodec_receive_frame - (frame->pkt_pos): 8 <- again mixed order, should be 7.  avcodec_receive_frame - (frame->pkt_pos): 7  avcodec_receive_frame - (frame->pkt_pos): 9   I would be grateful if you could:  1. Show me how can I force decoder to send me a frame immediately rather thanb keeping it in its buffer. 2. Show me how to fix that strange ordering.  3. Given any other advice how could I pass information in AVPacket and receive it in corresponding AVFrame.   Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20240929/96536c07/attachment.htm>


More information about the Libav-user mailing list