diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index de910c09943440475d23e3c13f5f0b693b09324a..757f7a515dd704d6bc43ba7f2c50a432688ade20 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -996,11 +996,15 @@ dshow_add_device(AVFormatContext *avctx,
             par->codec_id = AV_CODEC_ID_RAWVIDEO;
             if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) {
                 par->bits_per_coded_sample = bih->biBitCount;
+                if (par->height < 0) {
+                    par->height *= -1;
+                } else {
                 par->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE);
                 if (par->extradata) {
                     par->extradata_size = 9;
                     memcpy(par->extradata, "BottomUp", 9);
                 }
+                }
             }
         }
     } else {