1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-08 07:08:12 +00:00
mpv/filters
wm4 3c123281a7 audio: change format negotiation, remove channel remix fudging
The audio format neogitation code was pretty complicated, although the
idea was simple: when the format changes (or on the first audio frame),
filter only the new frame through the entire filter chain, discard the
resulting frame, but use the format to initialize the AO.

This was useful for "fudging" the channel remix behavior (upmix or
downmix), and moving it before other filters. Apparently this was useful
for things like DRC filters, which might work better in stereo, and
which also can only achieve the desired volume levels by doing it before
a downmix, which would modify the volume. This mechanism was introduced
in commit 60048b7eb9 (which the commit message also describes as
"idiotic heuristic"). Knowing the output format is inherently necessary
for this, because otherwise we can't know what the hell the user defined
filters will do.

There were problems with robustness. Some filters needed more than one
frame. Resampling in particular would discard initial audio at high
resampling ratios. Some filters might drop audio intentionally (like
clipping data on timestamp ranges). There were also allegations that
some decoders output 0 length frames (although that is invalid in
libavcodec). The state machine was excessively complex and hard to
understand too.

There are 3 things that could have been done:

1. Fix robustness problems by doing more heuristics, like repeating
   audio frames or simply decoding several frames. Since filters can
   behave differently, this would have added lots of complexity.
2. Make use of libavfilter's format negotiation, and add the same to
   mpv builtin filters. This is sort of annoying, because the format
   negotiation in libavfilter changes the state of the filters. It also
   reports only some parameters (mostly all for audio, but a lot of
   holes for video). It would remove some of the state machine, but not
   all.
3. Drop the channel remix fudging, and do the same as the video chain.
   This would not require format negotiation, but instead you can just
   filter the audio frames, and look what comes out of it. If nothing
   comes out, simply never create an AO.

This commit selects option 3. It removes the remix fudging, which means
the loss of a feature. Users can instead add "--af=format=channels=2"
before their DRC filter, or something. I'm also considering changing the
default for --audio-channels back to stereo, and downmix in the decoder
or at the start of the filter chain, which would give the same results,
except requiring more configuration.

Implementation-wise, this is still a bit different from the video path.
The VO always remains the same instance, while the AO might have to be
recreated on configuration changes. This still requires explicit format
change handling + draining old data, but by putting it into
f_autoconvert, not much new code is needed.
2018-04-15 23:11:33 +03:00
..
f_auto_filters.c video: fix --video-rotate in some cases 2018-02-18 16:21:56 +01:00
f_auto_filters.h
f_autoconvert.c audio: change format negotiation, remove channel remix fudging 2018-04-15 23:11:33 +03:00
f_autoconvert.h audio: change format negotiation, remove channel remix fudging 2018-04-15 23:11:33 +03:00
f_decoder_wrapper.c f_decoder_wrapper: retry decoding if libavcodec returns invalid state 2018-03-26 19:47:08 +02:00
f_decoder_wrapper.h audio: move back PTS jump detection to before filter chain 2018-02-13 17:45:29 -08:00
f_demux_in.c f_demux_in: give it a slightly better filter name 2018-02-05 02:47:14 -08:00
f_demux_in.h video: make decoder wrapper a filter 2018-01-30 03:10:27 -08:00
f_hwtransfer.c f_hwtransfer: more detailed logging 2018-03-15 23:13:53 -07:00
f_hwtransfer.h
f_lavfi.c f_lavfi: use new libavfilter iteration API 2018-04-03 20:08:15 +03:00
f_lavfi.h f_lavfi: fix typo in comment 2018-02-13 17:45:29 -08:00
f_output_chain.c audio: change format negotiation, remove channel remix fudging 2018-04-15 23:11:33 +03:00
f_output_chain.h f_output_chain: remove unused got_input_eof field 2018-02-03 05:01:32 -08:00
f_swresample.c swresample: minor simplification 2018-02-03 05:01:34 -08:00
f_swresample.h swresample: limit output size of audio frames 2018-02-03 05:01:29 -08:00
f_swscale.c
f_swscale.h
f_utils.c f_utils: fix leak in frame duration filter 2018-02-03 05:01:30 -08:00
f_utils.h
filter_internal.h
filter.c filter: fix potential NULL pointer deref 2018-02-16 22:04:15 -08:00
filter.h filter: extend documentation comments 2018-02-13 17:45:29 -08:00
frame.c video: make decoder wrapper a filter 2018-01-30 03:10:27 -08:00
frame.h video: make decoder wrapper a filter 2018-01-30 03:10:27 -08:00
user_filters.c options: slightly improve filter help output for lavfi bridge 2018-02-03 05:00:52 -08:00
user_filters.h