[FFmpeg-devel] [PATCH] avfilter: Temporary hack to fix format negotiation for hw formats

Mark Thompson sw at jkqxz.net
Wed Jan 3 22:46:04 EET 2024


hw_frames_ctx on the input link is only set when the input link is
configured, which hasn't happened yet.  This temporarily hacks around
the problem (in a way no worse than before the format negotiation
changes) until a proper fix can be applied.
---
Suggested full fix is to carry sw_format through the format negotiation separately so that we don't need hw_frames_ctx to be set (which also has other benefits like hwdownload being able to set its output format).

This hack is needed until that is ready because all hw formats are broken right now.


  libavfilter/avfiltergraph.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 727eff81ee..bc503f6ebe 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -667,8 +667,11 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
      if (link->type == AVMEDIA_TYPE_VIDEO) {
          enum AVPixelFormat swfmt = link->format;
          if (av_pix_fmt_desc_get(swfmt)->flags & AV_PIX_FMT_FLAG_HWACCEL) {
-            av_assert1(link->hw_frames_ctx);
-            swfmt = ((AVHWFramesContext *) link->hw_frames_ctx->data)->sw_format;
+            // FIXME: this is a hack to work around hw_frames_ctx not yet
+            // being available to return the real sw_format.  Once that is
+            // fixed, this should instead be:
+            // swfmt = ((AVHWFramesContext *) link->hw_frames_ctx->data)->sw_format;
+            swfmt = AV_PIX_FMT_YUV420P;
          }

          if (!ff_fmt_is_regular_yuv(swfmt)) {
-- 
2.39.2


More information about the ffmpeg-devel mailing list