demux_lavf: fix initial video stream selection
One bug in initial video stream selection when opening the demuxer was
fixed earlier by
cb4394aea32 ("demux_lavf: fix initial "-vid"-based
video selection"). However, this still doesn't always work right due
to the nonsensical way demuxer->video->id is initialized. Before
demuxer-specific code runs, demuxer.c initializes it to the value of
the --vid option, or -2 for disabled or -1 for autoselect. However, in
a running demuxer, the value of the field is demuxer->v_streams[]
index which does not need to match --vid value for the stream. The
demux_lavf video selection code considered each stream one by one as
they were being added. As a result, the code could first select one
stream based on the demuxer->video->id value from demuxer.c, set
demuxer->video->id to the corresponding v_streams index value, and
then later reinterpret that as --vid specifying a _different_ stream.
Move video stream selection to the end of demuxer initialization. This
ensures there is no ambiguity whether demuxer->video->id is still the
--vid value or after-stream-selection v_streams index. It also ensures
the code will not try to autoselect a stream that is added later after
demuxer initialization (which, while perhaps desirable in some cases,
would not work correctly without extra code). Also, remove some code
which set demuxer->audio->sh and demuxer->video->sh in fill_buffer();
this should not be needed if other code is working correctly, as
anything selecting the stream should have already initialized those
fields.