1 diff --git a/libavfilter/formats.c b/libavfilter/formats.c
2 index de4315369d..f430908343 100644
3 --- a/libavfilter/formats.c
4 +++ b/libavfilter/formats.c
5 @@ -107,11 +107,13 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
6 possibly causing a lossy conversion elsewhere in the graph.
7 To avoid that, pretend that there are no common formats to force the
8 insertion of a conversion filter. */
9 - if (type == AVMEDIA_TYPE_VIDEO)
10 - for (i = 0; i < a->nb_formats; i++)
11 + if (type == AVMEDIA_TYPE_VIDEO) {
12 + for (i = 0; i < a->nb_formats; i++) {
13 + const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
14 + if( !adesc ) continue;
15 for (j = 0; j < b->nb_formats; j++) {
16 - const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
17 const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
18 + if( !bdesc ) continue;
19 alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
20 chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
21 if (a->formats[i] == b->formats[j]) {
22 @@ -119,6 +121,8 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
23 chroma1|= adesc->nb_components > 1;
29 // If chroma or alpha can be lost through merging then do not merge
30 if (alpha2 > alpha1 || chroma2 > chroma1)