hwcontext_vaapi maps different VA fourcc to the same pix_fmt for U/V plane swap cases, however duplicate formats are not expected in sw_format list when merging formats. For example: ffmpeg -loglevel debug -init_hw_device vaapi -filter_hw_device vaapi0 \ -f lavfi -i smptebars -vf \ "hwupload=derive_device=vaapi,scale_vaapi,hwdownload,format=yuv420p" \ -vframes 1 -f null - Without this fix, an auto scaler is required for the above command Duplicate formats in ff_merge_formats detected [auto_scaler_0 @ 0x560df58f4550] Setting 'flags' to value 'bicubic' [auto_scaler_0 @ 0x560df58f4550] w:iw h:ih flags:'bicubic' interl:0 [Parsed_hwupload_0 @ 0x560df58f0ec0] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 0:0' and the filter 'Parsed_hwupload_0'
Unified · Split
| @@ -268,14 +268,24 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev, · 267 unmodified lines | ||
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | for (i = j = 0; i < attr_count; i++) { |
| 271 | + int k; | |
| 272 | + | |
| 271 | 273 | if (attr_list[i].type != VASurfaceAttribPixelFormat) |
| 272 | 274 | continue; |
| 273 | 275 | fourcc = attr_list[i].value.value.i; |
| 274 | 276 | pix_fmt = vaapi_pix_fmt_from_fourcc(fourcc); |
| 275 | − if (pix_fmt != AV_PIX_FMT_NONE) | |
| 277 | + | |
| 278 | + if (pix_fmt == AV_PIX_FMT_NONE) | |
| 279 | + continue; | |
| 280 | + | |
| 281 | + for (k = 0; k < j; k++) { | |
| 282 | + if (constraints->valid_sw_formats[k] == pix_fmt) | |
| 283 | + break; | |
| 284 | + } | |
| 285 | + | |
| 286 | + if (k == j) | |
| 276 | 287 | constraints->valid_sw_formats[j++] = pix_fmt; |
| 277 | 288 | } |
| 278 | − av_assert0(j == pix_fmt_count); | |
| 279 | 289 | constraints->valid_sw_formats[j] = AV_PIX_FMT_NONE; |
| 280 | 290 | } |
| 281 | 291 | } else { |
| @@ -287,9 +297,19 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev, · 5 unmodified lines | ||
| 287 | 297 | err = AVERROR(ENOMEM); |
| 288 | 298 | goto fail; |
| 289 | 299 | } |
| 290 | − for (i = 0; i < ctx->nb_formats; i++) | |
| 291 | − constraints->valid_sw_formats[i] = ctx->formats[i].pix_fmt; | |
| 292 | − constraints->valid_sw_formats[i] = AV_PIX_FMT_NONE; | |
| 300 | + for (i = j = 0; i < ctx->nb_formats; i++) { | |
| 301 | + int k; | |
| 302 | + | |
| 303 | + for (k = 0; k < j; k++) { | |
| 304 | + if (constraints->valid_sw_formats[k] == ctx->formats[i].pix_fmt) | |
| 305 | + break; | |
| 306 | + } | |
| 307 | + | |
| 308 | + if (k == j) | |
| 309 | + constraints->valid_sw_formats[j++] = ctx->formats[i].pix_fmt; | |
| 310 | + } | |
| 311 | + | |
| 312 | + constraints->valid_sw_formats[j] = AV_PIX_FMT_NONE; | |
| 293 | 313 | } |
| 294 | 314 | |
| 295 | 315 | constraints->valid_hw_formats = av_malloc_array(2, sizeof(pix_fmt)); |