[Libav-user] avformat_find_stream_info() causes problems in packet decoding

Ronny Wegener max_schmerz at gmx.net
Thu Jan 10 04:44:20 CET 2013


i have a simple program that reads all video packets from a file,
decodes them into a frame and prints the corresponding timestamps.
This works fine.

Output (test.avi):

  packet.pts=0 => frame.pts=0
  packet.pts=1 => frame.pts=1
  packet.pts=2 => frame.pts=2
  packet.pts=3 => frame.pts=3
  packet.pts=4 => frame.pts=4
  packet.pts=5 => frame.pts=5
  packet.pts=6 => frame.pts=6

when i use the avformat_find_stream_info() function in advance, which
is reading some packets to determine information about the streams,
the first packets are not decoded successfully and the following
decoded frames got a "shifted" timestamp.

Output (test.avi):

  packet.pts=0 => FRAME NOT FINISHED
  packet.pts=1 => FRAME NOT FINISHED
  packet.pts=2 => FRAME NOT FINISHED
  packet.pts=3 => FRAME NOT FINISHED
  packet.pts=4 => frame.pts=0
  packet.pts=5 => frame.pts=1
  packet.pts=6 => frame.pts=2

i guess the internal packet buffer is not flushed correctly after
avformat_find_stream_info(). I already tried to free the packet_buffer
and raw_packet_buffer in AVFormatContext, but this didn't worked. So
any suggestions how to fix this without closing and re-opening the

Code to reproduce the problem: http://pastebin.com/UzTuZBL6
Project to reproduce the problem: http://rghost.net/42877696

More information about the Libav-user mailing list