diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index ac80fa85ce..f640d5a710 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -91,6 +91,8 @@ typedef struct FFV1Context {
     struct FFV1Context *fsrc;
 
     AVFrame *cur;
+    int picture_structure;
+    AVRational sample_aspect_ratio;
     int plane_count;
     int ac;                              ///< 1=range coder <-> 0=golomb rice
     int ac_byte_count;                   ///< number of bytes used for AC coding
@@ -132,6 +134,8 @@ typedef struct FFV1Context {
     int slice_coding_mode;
     int slice_rct_by_coef;
     int slice_rct_ry_coef;
+
+    AVRational slice_sample_aspect_ratios[MAX_SLICES];
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 201630167d..8a8ab90b2b 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -167,7 +167,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs)
 {
     RangeCoder *c = &fs->c;
     uint8_t state[CONTEXT_SIZE];
-    unsigned ps, i, context_count;
+    unsigned i, context_count;
     memset(state, 128, sizeof(state));
 
     av_assert0(f->version > 2);
@@ -205,25 +205,17 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs)
         p->context_count = context_count;
     }
 
-    ps = get_symbol(c, state, 0);
-    if (ps == 1) {
-        f->cur->interlaced_frame = 1;
-        f->cur->top_field_first  = 1;
-    } else if (ps == 2) {
-        f->cur->interlaced_frame = 1;
-        f->cur->top_field_first  = 0;
-    } else if (ps == 3) {
-        f->cur->interlaced_frame = 0;
-    }
-    f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0);
-    f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0);
-
-    if (av_image_check_sar(f->width, f->height,
-                           f->cur->sample_aspect_ratio) < 0) {
+    fs->picture_structure       = get_symbol(c, state, 0);
+    fs->sample_aspect_ratio.num = get_symbol(c, state, 0);
+    fs->sample_aspect_ratio.den = get_symbol(c, state, 0);
+    /* Num or den being zero means unknown for FFV1; our unknown is 0 / 1. */
+    if (fs->sample_aspect_ratio.num == 0 || fs->sample_aspect_ratio.den == 0) {
+        fs->sample_aspect_ratio = (AVRational) { 0, 1 };
+    } else if (av_image_check_sar(f->width, f->height,
+                                  fs->sample_aspect_ratio) < 0) {
         av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
-               f->cur->sample_aspect_ratio.num,
-               f->cur->sample_aspect_ratio.den);
-        f->cur->sample_aspect_ratio = (AVRational){ 0, 1 };
+               fs->sample_aspect_ratio.num, fs->sample_aspect_ratio.den);
+        fs->sample_aspect_ratio = (AVRational) { 0, 0 };
     }
 
     if (fs->version > 3) {
@@ -251,6 +243,9 @@ static int decode_slice(AVCodecContext *c, void *arg)
     AVFrame * const p = f->cur;
     int i, si;
 
+    fs->picture_structure   = 0;
+    fs->sample_aspect_ratio = (AVRational){ 0, 0 };
+
     for( si=0; fs != f->slice_context[si]; si ++)
         ;
 
@@ -831,6 +826,28 @@ static av_cold int decode_init(AVCodecContext *avctx)
     return 0;
 }
 
+/* Macro to simplify comparisons of the rational values we deal with here.
+ * get_symbol() ensures that these fit into 32bits, so that one can just
+ * compare them in 64bits; they are also actually unsigned, so cast to that.
+ * Notice that av_image_check_sar() checks for these values to be
+ * positive integers. */
+#define CMP_Q(x, y) (FFDIFFSIGN((unsigned)(x).num * (uint64_t)(unsigned)(y).den,\
+                                (unsigned)(y).num * (uint64_t)(unsigned)(x).den))
+static int compare_sar(const void *a, const void *b)
+{
+    const AVRational x = *(const AVRational*)a;
+    const AVRational y = *(const AVRational*)b;
+    int cmp;
+
+    /* 0/0 means invalid and 0/1 means unknown.
+     * Order the fractions so that the former are at the end. */
+    if (x.den == 0 || y.den == 0)
+        return y.den - x.den;
+    cmp = CMP_Q(x, y);
+    /* For definiteness, order equivalent fractions by "lower terms last". */
+    return cmp ? cmp : y.num - x.num;
+}
+
 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 {
     uint8_t *buf        = avpkt->data;
@@ -969,9 +986,82 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
 
     if (f->last_picture.f)
         ff_thread_release_ext_buffer(avctx, &f->last_picture);
-    if ((ret = av_frame_ref(data, f->picture.f)) < 0)
+    p = data;
+    if ((ret = av_frame_ref(p, f->picture.f)) < 0)
         return ret;
 
+    if (f->version > 2) {
+        AVRational sar = f->slice_context[0]->sample_aspect_ratio;
+        int pic_structures[4] = { 0 }, picture_structure;
+        int inconsistent_sar = 0, has_sar = 0;
+
+        for (int i = 0; i < f->slice_count; i++) {
+            const FFV1Context *const fs = f->slice_context[i];
+            int slice_picture_structure = (unsigned)fs->picture_structure > 3 ?
+                                                    0 : fs->picture_structure;
+
+            pic_structures[slice_picture_structure]++;
+
+            if (fs->sample_aspect_ratio.num != sar.num ||
+                fs->sample_aspect_ratio.den != sar.den)
+                inconsistent_sar = 1;
+            sar = fs->sample_aspect_ratio;
+            if (sar.den == 0)
+                inconsistent_sar = 1;
+            else
+                has_sar = 1;
+            f->slice_sample_aspect_ratios[i] = sar;
+        }
+        if (has_sar) {
+            if (inconsistent_sar) {
+                AVRational last_sar = (AVRational){ 0, 0 };
+                qsort(f->slice_sample_aspect_ratios, f->slice_count,
+                      sizeof(f->slice_sample_aspect_ratios[0]), compare_sar);
+
+                for (int i = 0, current_run = 0, longest_run = 0;
+                     i < f->slice_count; i++) {
+                    AVRational cur_sar = f->slice_sample_aspect_ratios[i];
+
+                    if (cur_sar.den == 0)
+                        break;
+                    if (CMP_Q(cur_sar, last_sar))
+                        current_run = 1;
+                    else
+                        current_run++;
+                    /* Using >= here has the effect of preferring
+                     * bigger ratios if the runs are identical;
+                     * this ensures that a known SAR is preferred over
+                     * an unknown SAR in case there are equally many. */
+                    if (current_run >= longest_run) {
+                        longest_run = current_run;
+                        sar         = cur_sar;
+                    }
+                    last_sar = cur_sar;
+                }
+                av_log(avctx, AV_LOG_WARNING, "SAR inconsistent, using %u/%u\n",
+                       sar.num, sar.den);
+            }
+            p->sample_aspect_ratio = sar;
+        }
+
+        for (int i = 0, count = 0; i < FF_ARRAY_ELEMS(pic_structures); i++) {
+            if (pic_structures[i] > count) {
+                picture_structure = i;
+                count = pic_structures[i];
+            }
+        }
+        /* Set picture structure based upon the most commonly encountered
+         * picture structure. */
+        if (picture_structure == 1) {
+            p->interlaced_frame = 1;
+            p->top_field_first  = 1;
+        } else if (picture_structure == 2) {
+            p->interlaced_frame = 1;
+            p->top_field_first  = 0;
+        } else if (picture_structure == 3)
+            p->interlaced_frame = 0;
+    }
+
     *got_frame = 1;
 
     return buf_size;
