summaryrefslogtreecommitdiffstats
path: root/video/decode/vd_lavc.c
Commit message (Collapse)AuthorAgeFilesLines
* player/command: add video-codec-info and audio-codec-infoKacper Michajłow9 days1-0/+5
| | | | | | | | | | | Adds support for extracting codec profile. Old properties are redirected to new one and removed from docs. Likely will stay like that forever as there is no reason to remove them. As a effect of unification of properties between audio and video, video-codec will now print codec (format) descriptive name, not decoder long name as it were before. In practice this change fixes what docs says. If you really need decoder name, use the `track-list/N/decoder-desc`.
* various: make filter internal function names more descriptivenanahi14 days1-6/+6
| | | | | | | | | Lots of filters have generic internal function names like "process". On a stack trace, all of the different filters use this name, which causes confusion of the actual filter being processed. This renames these internal function names to carry the filter names. This matches what had already been done for some filters.
* ALL: use new mp_thread abstractionKacper Michajłow2023-11-051-7/+7
|
* vd_lavc: align buffers to multiple of image sizeNiklas Haas2023-10-191-0/+7
| | | | Fixes: https://github.com/mpv-player/mpv/issues/12672
* vd_lavc: by default enable cropping by decoderKacper Michajłow2023-09-101-0/+1
| | | | | | | | | | | | | | | | | | | | | While this resolves limitations of lavc decoder crop, it also introduces artifacts with some of the source files or hwdec. Depending on chroma sampler it is possible to sample outside the decoder crop area, pulling dirty pixels into the image. Some decoders left them zeroed, not black. To fix that we would need specifc solution during mapping of avframes. As most of the files require the crop only in bottom/right area, the AVCodecContext::apply_cropping works ok for those. For all other cases that require more fancy cropping like 1440x1080+240+0 user can manually set `--vd-apply-cropping=no`. Limitations of the lavc crop are explained here: https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html#a4745c7455c317272c4e139d6f369936c Fixes: 826ce82cad315f7a48f9c971d3a5fa005a9eab46
* vd_lavc: disable cropping by decoderKacper Michajłow2023-09-081-0/+3
| | | | | | | | | Cropping by decoder has limitations with regards to aligment and hwdec. It doesn't work to offset top left corner with hwdec and even with software decoding it don't crop fully when resulting data would not be aligned. VO cropping is way more robust.
* vd_lavc: repeatedly attempt to fallback if hwdec fails in reinitPhilip Langdale2023-08-061-2/+5
| | | | | | | | | | | | | | | In the same way that fallback in receive_frame() needs to be repeated until we get a working decoder, we have to do the same thing in reinit(). Calling force_fallback() only once can still yield a non functional decoder. The reason why we have these multiple paths which each require their own fallback logic is that we can fail at different stages: * hwdec init * decoder init <- repeated fallback was missing here * frame decoding Fixes #12084
* player/video: check for forced eofDudemanguy2023-07-221-0/+4
| | | | | | | | | | | It's a bit of an edge case, but since we now allow the disabling of the software fallback it's possible to have a situation where hwdec completely fails and the mpv window is still lingering from the previous item in the playlist. What needs to happen is simply that the vo_chain should uninit itself and handle force_window if needed. In order to do that, a new VDCTRL is added that checks vd_lavc if force_eof was set. player/video will then start the uninit process if needed after getting this.
* vd_lavc: respect vd-lavc-software-fallback optDudemanguy2023-07-221-2/+10
| | | | | | | | | | There's an option that's supposed to stop mpv from falling back to software decoding if hardware decoding fails. Except that it doesn't work and can fallback to software decoding anyway. Correct this by checking if all possible hwdec failed after the loop in select_and_set_hwdec and that we have this option. If so, flag a bool to force eof. In decode_frame afterwards, we then simply immediately return an EOF.
* vd_lavc: repeatedly attempt to fallback if hwdec fails in receive_framePhilip Langdale2023-07-171-2/+14
| | | | | | | | | | | | | | | | | There is an additional failure path I didn't account for in my previous work. While I ensured that a late hwdec failure in receive_frame can be recovered from by trying the next hwdec, there is a specific combination where if an hwdec fails in receive_frame, and the next hwdec is a full decoder (eg: v4l2m2m), and that also fails, we are left with no decoder and so the entire decoding process ends and playback is stopped. Basically, we must keep re-attempting the fallback in receive_frame until we get a valid decoder (software or hardware). This edge case will rarely be encountered as there are only a couple of decoder based hwdecs. Fixes #11947
* vd_lavc: map `hwdec=yes` to `hwdec=auto-safe`Philip Langdale2023-07-141-2/+2
| | | | | | To remain consistent with our belief that `auto-safe` should be the recommended mode when turning on hw decoding, let's remap `yes` from `auto` to `auto-safe`.
* vd_lavc: add `drm` and `drm-copy` to the `auto-safe` listPhilip Langdale2023-07-141-0/+2
| | | | | | | | | We have supported `hwdec=drm` for some time now, and on devices where this method is present, it is the preferred, and only, method available. Combine that with the fact that software decoding on embedded devices will not turn out well, and it's clear that we should put `drm` and `drm-copy` on the `auto-safe` list to maximise usability in simple configurations.
* vd_lavc: try other hwdecs when falling back after an hwdec failurePhilip Langdale2023-07-141-2/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | Today, if hwdec initialisation succeeds, we move on to attempting decoding, and if decoding fails, we enter a fallback path that will only do software decoding. This is suboptimal because some hwdecs and codec combinations can pass hwdec init, but then fail at hwaccel init, or even frame decoding. In these situations, we will never attempt other hwdecs in the `auto` or manually specified lists which might work. One good example is someone tries to use `vulkan,auto` and tries to play av1 content. The vulkan decoding will fail at hwaccel init time, and then fallback to software instead of going through the auto list which would allow vaapi, nvdec, etc to play the file. Instead, let's not give up immediately, and try the next hwdec after a failure, just like we do if hwdec init fails. The key part of this change is to keep track of the hwdecs we have tried, so that each time we run through hwdec selection, we don't try the same one over and over again. If we really get through the whole list with no success, we will then fall back to software decoding. Fixes #11865
* vd_lavc: fix delay_queue for videos with frames < max_delay_queueKacper Michajłow2023-07-091-3/+3
| | | | | | | | | | In case there are no packets from demuxer we cannot send EAGAIN, because we will not proceed and get stuck with one frame in queue and never output it. Just respect avcodec_receive_frame ret code and act accordingly. The only case to care about is EOF when we have to drain already queued frames. Fixes playback of 1-2 frame videos.
* vd_lavc: prefer d3d11va-copy over dxva2-copyKacper Michajłow2023-07-091-1/+1
| | | | | | There is no reason to prefer dxva2. I believe it was mistake from initial commit that added the hwdec list that has been propagated through years.
* vd_lavc: do inline string array initialisation for hwdec_apiPhilip Langdale2023-06-291-3/+1
| | | | | I couldn't work out the correct syntax, but NRK0 pointed out an example of where we'd done it elsewhere in the codebase.
* vd_lavc: let the user provide a priority list of hwdecs to considerPhilip Langdale2023-06-291-76/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | Today, the only way to make mpv consider multiple hwdecs and pick the first one that works is to use one of the `auto` modes. But the list that is considered in those cases is hard-coded. If the user wants to provide their own list, they are out of luck. And I think that there is now a significant reason to support this - the new Vulkan hwdec is definitely not ready to be in the auto list, but if you want to use it by default, it will not work with many codecs that are normally hardware decodable (only h.264, hevc and av1 if you are very lucky). Everything else will fall back to software decoding. Instead, what you really want to say is: use Vulkan for whatever it supports, and fall back to my old hwdec for everything else. One side-effect of this implementation is that you can freely mix hwdec names and special values like `auto` and `no`. The behaviour will be correct, so I didn't try and prohibit any combinations. However, some combinations will be silly - eg: sticking any further values after `no` will result in them being ignored. On the other hand, a combination like `vulkan,auto` could be very useful as that will use Vulkan if possible, and if not, run the normal auto routine. Fixes #11797
* vd_lavc: check if av_device_ref is availableKacper Michajłow2023-06-261-1/+3
| | | | | | Fixes crashes when hwdevice failed to create. Fixes: #11769
* vd_lavc: sort hwdecs without hwdevices last for autoprobingsfan52023-02-261-0/+3
| | | | | | For hwdecs without devices we can't get instant feedback during probing whether the hwdec can possibly work or not, so we definitely want to try them last. Independently this would also have solved the issue addressed by the previous commit.
* vd_lavc: prioritize mediacodec for hwdec autoprobesfan52023-02-261-0/+2
| | | | | | This fixes an issue where mpv would try mediacodec (which may not be available depending on Android version) and pick v4l2m2m next which ends up failing even though mediacodec-copy would have been available.
* options: transition options from OPT_FLAG to OPT_BOOLChristoph Heinrich2023-02-211-12/+11
| | | | | | c78482045444c488bb7948305d583a55d17cd236 introduced a bool option type as a replacement for the flag type, but didn't actually transition and remove the flag type because it would have been too much mundane work.
* various: drop unused #include "config.h"Thomas Weißschuh2023-02-201-2/+0
| | | | | | Most sources don't need config.h. The inclusion only leads to lots of unneeded recompilation if the configuration is changed.
* vd_lavc: add "auto" choice for vd-lavc-drsfan52023-01-231-4/+7
| | | | | | | | | | | | --vd-lavc-dr defaulted to "yes", which caused issues on certain hardware. Instead of disabling it, add a new "auto" value and make it the default. The "auto" choice will enable DR only when we can request host-cached buffers (as signalled by the new VO_DR_FLAG_HOST_CACHED). Co-authored-by: Nicolas F. <ovdev@fratti.ch> Co-authored-by: Niklas Haas <git@haasn.dev>
* vo: add `int flags` to the get_image signatureNiklas Haas2023-01-231-1/+1
| | | | | This is a huge disgusting mess to thread through everywhere. Maybe I'm stupid for attempting to solve the problem this way.
* vd_lavc: Set AV_HWACCEL_FLAG_UNSAFE_OUTPUT flagPhilip Langdale2022-12-121-0/+11
| | | | | | | | | | This new hwaccel flag was added to allow us to request that an hwaccel decode not implicitly copy output frames before passing them out. The only hwaccel that would implicitly copy frames is nvdec due to how it has a small output pool that cannot be grown very much. However, we already copy frames as soon as we get our hands on them (in our hwdec) so we're already safe from pool exhaustion, and the extra copy doesn't help us.
* ffmpeg: update to handle deprecation of `av_init_packet`Philip Langdale2022-12-031-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This has been a long standing annoyance - ffmpeg is removing sizeof(AVPacket) from the API which means you cannot stack-allocate AVPacket anymore. However, that is something we take advantage of because we use short-lived AVPackets to bridge from native mpv packets in our main decoding paths. We don't think that switching these to `av_packet_alloc` is desirable, given the cost of heap allocation, so this change takes a different approach - allocating a single packet in the relevant context and reusing it over and over. That's fairly straight-forward, with the main caveat being that re-initialising the packet is unintuitive. There is no function that does exactly what we need (what `av_init_packet` did). The closest is `av_packet_unref`, which additionally frees buffers and side-data. However, we don't copy those things - we just assign them in from our own packet, so we have to explicitly clear the pointers before calling `av_packet_unref`. But at least we can make a wrapper function for that. The weirdest part of the change is the handling of the vtt subtitle conversion. This requires two packets, so I had to pre-allocate two in the context struct. That sounds excessive, but if allocating the primary packet is too expensive, then allocating the secondary one for vtt subtitles must also be too expensive. This change is not conditional as heap allocated AVPackets were available for years and years before the deprecation.
* vd_lavc: update to handle deprecation of `pkt_duration`Philip Langdale2022-12-011-0/+5
| | | | This has been replaced by `duration`.
* vo: hwdec: do hwdec interop lookup by image formatPhilip Langdale2022-09-211-2/+6
| | | | | | | | | | | | | | It turns out that it's generally more useful to look up hwdecs by image format, rather than device type. In the situations where we need to find one, we generally know the image format we're dealing with. Doing this avoids us having to create mappings from image format to device type. The most significant part of this change is filling in the image format for the various hw interops. There is a hw_imgfmt field today today, but only a couple of the interops fill it in, and that seems to be because we've never actually used this piece of metadata before. Well, now we have a good use for it.
* various: fix typosCœur2022-04-251-1/+1
|
* vd_lavc: fixup unchecked usage of AV_CODEC_EXPORT_DATA_FILM_GRAINJan Ekström2022-04-131-0/+7
| | | | | | | | | | | | | | This fixes build failures with avcodec 58.113.100 or before, matching FFmpeg release versions 4.0 to 4.3. This flag was added in between avcodec 58.113.100 and 58.114.100 during the FFmpeg 4.4 development cycle. It lacks its own version bump, so instead a check for the define is utilized instead. Additionally, warn the user if they request GPU film grain with too old of an FFmpeg. Fixes #10088
* vd_lavc: fix decoder initialization when no VO is availableJan Ekström2022-04-111-6/+20
| | | | | | | | | | | | | | | | | The VO is available during decoder initialization mostly for direct rendering purposes, so if f.ex. a complex filter chain is utilized, there is no video renderer information available via mp_filter_find_stream_info during creation of the decoder filter. Thus, check for whether the VO is available before attempting to check the capabilities flag from it. Additionally - to simplify logic - makes explicitly requesting GPU film grain to always disable decoder film grain functionality. The warning is still shown if the VO is available and no support for film grain application is available. Fixes #10079
* vd_lavc: remove duplicate vd_ffmpeg_ctx pointer from init_avctxJan Ekström2022-04-111-2/+1
| | | | | Seems like in some functions this was called p and in others ctx, and thus it was added as the `p` pointer was not available.
* vd_lavc: add vo caps and option to set GPU film grain applicationLynne2022-04-051-0/+14
|
* vd_lavc: hide a deprecation warning in already handled compatible codeJan Ekström2022-04-031-1/+3
| | | | | | | | | | | The field has been deprecated, yet the upcoming new default is not yet the default. Thus, until lavc major hits 60 and the default behavior finally gets changed, we have to explicitly set the field's value. The deprecation had already been handled by adding the required version limitation for this code in bbbf3571edfbb0e849d3ef60148743352b84fe84 , this change merely just removes the warning which would otherwise appear until lavc major version gets bumped to 60.
* vo_gpu[_next]: hwdec: fix logging regression when probingPhilip Langdale2022-03-211-4/+12
| | | | | | | | | When I introduced the concept of lazy loading of hwdecs by img format, I did not propagate the probing flag correctly, leading to the new normal loading path not runnng with probing set, meaning that any errors would show up, creating unnecessary noise. This change fixes this regression.
* hwdec: warn on unsupported hwdec option valueAvi Halachmi (:avih)2022-03-071-5/+10
| | | | | | | | | | | | | | | | | | | | | | | Previously, when mpv was invoked with unsupported hwdec value, such as --hwdec=foobar, there was no indication that it doesn't exist. The reason it's not validated during options parsing is that the name is only evaluated when selecting hwdec for actual decoding, by matching it against runtime list of names from ffmpeg. Additionally, when selecting hwdec for decoding, matching the name came after filtering by codec, hence overall never-matched-name did not necessarily indicate it's unsupported (doesn't exist at all). Now we check the name before filtering by codec, and when done, warn if no hwdec with that name exists at all. This means that an unsupported name will now generate such warning whenever we try to choose a hwdec, i.e. possibly more than once. It's much better than no notification at all, and arguably adequate for a sort of configuration error (linked ffmpeg has no such hwdec name) which we don't validate during option parsing.
* vo_gpu: hwdec: load hwdec interops on-demand by defaultPhilip Langdale2022-02-171-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | Historically, we have treated hwdec interop loading as a completely separate step from loading the hwdecs themselves. Some hwdecs need an interop, and some don't, and users generally configure the exact hwdec they want, so interops that aren't relevant for that hwdec shouldn't be loaded to save time and avoid warning/error spam. The basic approach here is to recognise that interops are tied to hwdecs by imgfmt. The hwdec outputs some format, and an interop is needed to get that format to the vo without read back. So, when we try to load an hwdec, instead of just blindly loading all interops as we do today, let's pass the imgfmt in and only load interops that work for that format. If more than one interop is available for the format, the existing logic (whatever it is) will continue to be used to pick one. We also have one callsite in filters where we seem to pre-emptively load all the interops. It's probably possible to trace down a specific format but for now I'm just letting it keep loading all of them; it's no worse than before. You may notice there is no documentation update - and that's because the current docs say that when the interop mode is `auto`, the interop is loaded on demand. So reality now reflects the docs. How nice.
* vd_lavc: enable hwdec for prores by defaultrcombs2021-12-291-1/+1
|
* options: Make validation and help possible for all option typesPhilip Langdale2021-03-281-23/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Today, validation is only possible for string type options. But there's no particular reason why it needs to be restricted in this way, and there are potential uses, to allow other options to be validated without forcing the option to have to reimplement parsing from scratch. The first part, simply making the validation function an explicit field instead of overloading priv is simple enough. But if we only do that, then the validation function still needs to deal with the raw pre-parsed string. Instead, we want to allow the value to be parsed before it is validated. That in turn leads to us having validator functions that should be type aware. Unfortunately, that means we need to keep the explicit macro like OPT_STRING_VALIDATE() as a way to enforce the correct typing of the function. Otherwise, we'd have to have the validator take a void * and hope the implementation can cast it correctly. For help, we don't have this problem, as help doesn't look at the value. Then, we turn validators that are really help generators into explicit help functions and where a validator is help + validation, we split them into two parts. I have, however, left functions that need to query information for both help and validation as single functions to avoid code duplication. In this change, I have not added an other OPT_FOO_VALIDATE() macros as they are not needed, but I will add some in a separate change to illustrate the pattern.
* vd_lavc: wrap use of deprecated AVCodecContext.thread_safe_callbacks in #ifsfan52021-03-021-0/+2
| | | | For compatibility once FFmpeg removes it entirely.
* vd_lavc: add VP8 to the default allowed hwdec codec listEmmanuel Gil Peyrot2020-12-301-1/+1
| | | | | It is supported at least on Intel, from gen8 to gen11, and still gives a pretty welcome reduction of CPU usage on my gen9.
* vd_lavc: add AV1 to the default allowed hwdec codec listJan Ekström2020-11-031-1/+1
| | | | | Now that the first hwaccel implementations are coming in, it makes sense to allow this format.
* options: make imgfmt options always accept "no"wm42020-04-091-1/+1
| | | | | | | | This was optional, with the intention that normally such options require a valid format. But there is no reason for this (at least not anymore), and it's actually more logical to accept "no" in all situations this option type is used. This also gets rid of the weird min field special use.
* vd_lavc: make hwdec fallback message more consistentwm42020-03-241-4/+1
| | | | | | | | | | | The "rule" is that a fallback warning message should be shown only shown if software decoding was used before, or in other words when either hwdec was enabled before, but the stream suddenly falls back, or it was attempted to enable it at runtime, and it didn't work. The message wasn't printed the first time in the latter case, because hwdec_notified was not set in forced software decoding mode. Fix it with this commit. Fortunately, the logic becomes simpler.
* options: change option macros and all option declarationswm42020-03-181-23/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change all OPT_* macros such that they don't define the entire m_option initializer, and instead expand only to a part of it, which sets certain fields. This requires changing almost every option declaration, because they all use these macros. A declaration now always starts with {"name", ... followed by designated initializers only (possibly wrapped in macros). The OPT_* macros now initialize the .offset and .type fields only, sometimes also .priv and others. I think this change makes the option macros less tricky. The old code had to stuff everything into macro arguments (and attempted to allow setting arbitrary fields by letting the user pass designated initializers in the vararg parts). Some of this was made messy due to C99 and C11 not allowing 0-sized varargs with ',' removal. It's also possible that this change is pointless, other than cosmetic preferences. Not too happy about some things. For example, the OPT_CHOICE() indentation I applied looks a bit ugly. Much of this change was done with regex search&replace, but some places required manual editing. In particular, code in "obscure" areas (which I didn't include in compilation) might be broken now. In wayland_common.c the author of some option declarations confused the flags parameter with the default value (though the default value was also properly set below). I fixed this with this change.
* options: change how option range min/max is handledwm42020-03-131-1/+2
| | | | | | | | | | | | | | | | | Before this commit, option declarations used M_OPT_MIN/M_OPT_MAX (and some other identifiers based on these) to signal whether an option had min/max values. Remove these flags, and make it use a range implicitly on the condition if min<max is true. This requires care in all cases when only M_OPT_MIN or M_OPT_MAX were set (instead of both). Generally, the commit replaces all these instances with using DBL_MAX/DBL_MIN for the "unset" part of the range. This also happens to fix some cases where you could pass over-large values to integer options, which were silently truncated, but now cause an error. This commit has some higher potential for regressions.
* Remove remains of Libav compatibilitywm42020-02-161-5/+0
| | | | |