title: Cannot get first frames using avformat_seek_file
body: <p>I want to seek for an arbitrary frame in a video using <code>libav</code>. More precisely, using the function <code>avformat_seek_file</code>, which apparently uses <code>av_seek_frame</code> internally.</p>
  
  <p>I want to make a backward search (i.e. to get the closest possible frame <em>before</em> the one I seek), so that I can then go forward until I find <em>precisely</em> the one I want. For this, I use the function as follows:</p>
  
  <pre><code>avformat_seek_file(..., ...,
                     std::numeric_limits&lt;boost::int64_t&gt;::min(),
                     target_pts,
                     target_pts,
                     ...);
  </code></pre>
  
  <p>Which means that I don't have any tolerance about finding a frame that comes after my target_pts, but I am happy with any frame coming before.</p>
  
  <p>I am using the <a href="http://www.bigbuckbunny.org/index.php/download/" rel="nofollow">Big Buck Bunny videos</a> for testing. Using the 480p H.264 video, I can seek any <code>pts</code> without problems. But using the 480p OGG video, I can't. Actually, I can seek for any frame after <code>pts = 73</code>, but not before. Seeking for <code>pts = 0</code> sets the video to <code>pts = 73</code>.</p>
  
  <p>One might think that the stream actually begins at <code>pts = 73</code>, but this is not what <code>&lt;stream&gt;.start_time</code> returns. Moreover, if I only load the video and read the frames in order, I can get the first 73 frames without any problem. The issue is that I can never come back to one of those frames by using <code>avformat_seek_file</code>.</p>
  
  <p>Last point: if I use the flag <code>AVSEEK_FLAG_ANY</code>, then it works. But that might result in me decoding only a part of the frame I want, which is not a solution for me.</p>
  
  <p>Can anybody explain this weird behavior?</p>