[Libav-user] ffmpeg read multiple packets and keep them in buffer.

Mohamed-Ismail Mejri imejri at sabsystem.com
Tue Jan 24 12:59:33 EET 2017


I want to decode same packets before send it to the player, because 
avformat_find_stream_info() take long time to scan, I want to replace it 
by a simple function, but now I am losing the decoded packets after this 
function and this make the player take time to show the first picture. 
So, how I can read multiple packets in ffmpeg without deleting it after 
In otherwise how I can repointing to the first packet decoded after 
terminate scanning with this function.
Or if you have any another idea to speed up the scan process?

my function:

if (found == AVERROR(EAGAIN))
     return false;
pkt = &pkt1;
str = m_pFormatContext->streams[pkt->stream_index];
if (str->codec->codec_type == AVMEDIA_TYPE_VIDEO && testv < 2)  {
     gotFrame = 0;
     frame = av_frame_alloc();
     if (avcodec_open2(str->codec, m_codec, NULL) >= 0) {
         fine = avcodec_decode_video2(str->codec, frame, &gotFrame, pkt);
         if (fine >= 0)
             testv = testv + gotFrame + 1;

Reply to me if you need more information.
I hope what I have requested is possible.
Best regards,
Ismail MEJRI.

More information about the Libav-user mailing list