Decoder return of av_find_best_stream vs. avcodec_find_decoder
<p>The docs for libav's <a href="https://libav.org/documentation/doxygen/release/11/group__lavf__decoding.html#gaa6fa468c922ff5c60a6021dcac09aff9" rel="nofollow"><code>av_find_best_stream</code></a> function (libav 11.7, Windows, i686, GPL) specify a parameter that can be used to receive a pointer to an appropriate <code>AVCodec</code>:</p>

<blockquote>
  <p>decoder_ret - if non-NULL, returns the decoder for the selected stream</p>
</blockquote>

<p>There is also the <a href="https://libav.org/documentation/doxygen/release/11/group__lavc__decoding.html#ga19a0ca553277f019dd5b0fec6e1f9dca" rel="nofollow"><code>avcodec_find_decoder</code></a> function which can find an <code>AVCodec</code> given an ID.</p>

<p>However, the official <a href="https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/demuxing_decoding.c#L158" rel="nofollow">demuxing + decoding example</a> uses <code>av_find_best_stream</code> to find a stream, but chooses to use <code>avcodec_find_decoder</code> to find the codec in lieu of <code>av_find_best_stream</code>'s codec return parameter:</p>

<pre><code>ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0);
...
stream_index = ret;
st = fmt_ctx-&gt;streams[stream_index];
...
/* find decoder for the stream */
dec = avcodec_find_decoder(st-&gt;codecpar-&gt;codec_id);
</code></pre>

<p>As opposed to something like:</p>

<pre><code>ret = av_find_best_stream(fmt_ctx, type, -1, -1, &amp;dec, 0);
</code></pre>

<p>My question is pretty straightforward: Is there a difference between using <code>av_find_best_stream</code>'s return parameter vs. using <code>avcodec_find_decoder</code> to find the <code>AVCodec</code>? </p>

<p>The reason I ask is because the example chose to use <code>avcodec_find_decoder</code> rather than the seemingly more convenient return parameter, and I can't tell if the example did that for a specific reason or not. The documentation itself is a little spotty and disjoint, so it's hard to tell if things like this are done for a specific important reason or not. I can't tell if the example is implying that it "should" be done that way, or if the example author did it for some more arbitrary personal reason.</p>