diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index afce95042e..a632882ab2 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -4800,20 +4800,32 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s)
     // Write the major brand as the first compatible brand as well
     mov_write_ftyp_tag_internal(pb, s, has_h264, has_video, 0);
 
+    // Write compatible brands, ensuring that we don't write the major brand as a
+    // compatible brand a second time.
     if (mov->mode == MODE_ISM) {
         ffio_wfourcc(pb, "piff");
-    } else if (!(mov->flags & FF_MOV_FLAG_DEFAULT_BASE_MOOF)) {
-        ffio_wfourcc(pb, "isom");
-        ffio_wfourcc(pb, "iso2");
-        if (has_h264)
-            ffio_wfourcc(pb, "avc1");
+    } else if (mov->mode != MODE_MOV) {
+        // We add tfdt atoms when fragmenting, signal this with the iso6 compatible
+        // brand. This is compatible with users that don't understand tfdt.
+        if (mov->flags & FF_MOV_FLAG_FRAGMENT)
+            ffio_wfourcc(pb, "iso6");
+        if (mov->mode != MODE_MP4) {
+            if (mov->flags & FF_MOV_FLAG_DEFAULT_BASE_MOOF)
+                ffio_wfourcc(pb, "iso5");
+            else if (mov->flags & FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS)
+                ffio_wfourcc(pb, "iso4");
+        }
+        // Brands prior to iso5 can't be signaled when using default-base-is-moof
+        if (!(mov->flags & FF_MOV_FLAG_DEFAULT_BASE_MOOF)) {
+            // write isom for mp4 only if it it's not the major brand already.
+            if (mov->mode != MODE_MP4 || mov->flags & FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS)
+                ffio_wfourcc(pb, "isom");
+            ffio_wfourcc(pb, "iso2");
+            if (has_h264)
+                ffio_wfourcc(pb, "avc1");
+        }
     }
 
-    // We add tfdt atoms when fragmenting, signal this with the iso6 compatible
-    // brand. This is compatible with users that don't understand tfdt.
-    if (mov->flags & FF_MOV_FLAG_FRAGMENT && mov->mode != MODE_ISM)
-        ffio_wfourcc(pb, "iso6");
-
     if (mov->mode == MODE_MP4)
         ffio_wfourcc(pb, "mp41");
 
diff --git a/tests/ref/fate/binsub-movtextenc b/tests/ref/fate/binsub-movtextenc
index dacee0931e..78c05f4376 100644
--- a/tests/ref/fate/binsub-movtextenc
+++ b/tests/ref/fate/binsub-movtextenc
@@ -1 +1 @@
-66b25412f7ca699ee525ba162246edb6
+35adf776cd73e808186ae7124445f4b8
diff --git a/tests/ref/fate/copy-psp b/tests/ref/fate/copy-psp
index 44ec461265..8b2cef87fa 100644
--- a/tests/ref/fate/copy-psp
+++ b/tests/ref/fate/copy-psp
@@ -1,4 +1,4 @@
-65a177552e03123c9a62ddb942970d05 *tests/data/fate/copy-psp.psp
+8578401522773d0832f538ac915ad0b0 *tests/data/fate/copy-psp.psp
 2041445 tests/data/fate/copy-psp.psp
 #extradata 0:       51, 0xaf6d1012
 #extradata 1:        2, 0x00b200a1
diff --git a/tests/ref/fate/movenc b/tests/ref/fate/movenc
index 5e8f324ea3..68ce3f6cd9 100644
--- a/tests/ref/fate/movenc
+++ b/tests/ref/fate/movenc
@@ -2,127 +2,127 @@ write_data len 36, time nopts, type header atom ftyp
 write_data len 2389, time nopts, type header atom -
 write_data len 788, time 1000000, type sync atom moof
 write_data len 110, time nopts, type trailer atom -
-17a37691eba8b858cf15e60aa9a7dbf7 3323 non-empty-moov
+66cf48604f039aa9a51711786f5c8778 3323 non-empty-moov
 write_data len 36, time nopts, type header atom ftyp
 write_data len 2721, time nopts, type header atom -
 write_data len 908, time 966667, type sync atom moof
 write_data len 110, time nopts, type trailer atom -
-0026ffe059c06c592021f972bf2c5e79 3775 non-empty-moov-elst
+04b2e86f455af94f9258b8d66dbf71f5 3775 non-empty-moov-elst
 write_data len 36, time nopts, type header atom ftyp
 write_data len 2629, time nopts, type header atom -
 write_data len 908, time 1000000, type sync atom moof
 write_data len 110, time nopts, type trailer atom -
-c184e168ac1e5bb3d9c70e580ab6179c 3683 non-empty-moov-no-elst
-write_data len 20, time nopts, type header atom ftyp
+e9f6fa032d6d8265d67aef5de81a48bf 3683 non-empty-moov-no-elst
+write_data len 24, time nopts, type header atom ftyp
 write_data len 1171, time nopts, type header atom -
 write_data len 728, time 0, type sync atom moof
 write_data len 828, time nopts, type unknown atom -
 write_data len 728, time 1046439, type sync atom moof
 write_data len 812, time nopts, type unknown atom -
 write_data len 148, time nopts, type trailer atom -
-49bf122c4c732a344ef68b58acd19be5 4435 ismv
+a7c93f998e88fee1159580b6ca7e3d2b 4439 ismv
 write_data len 36, time nopts, type header atom ftyp
 write_data len 1123, time nopts, type header atom -
 write_data len 796, time 0, type sync atom moof
 write_data len 788, time 1000000, type sync atom moof
 write_data len 148, time nopts, type trailer atom -
-ed8506ebfce4c41732205ae26a4759fd 2891 empty-moov
+e6a4b15443d006efd727a80f6624b7db 2891 empty-moov
 write_data len 36, time nopts, type header atom ftyp
 write_data len 1123, time nopts, type header atom -
 write_data len 1068, time 0, type sync atom moof
 write_data len 908, time 1000000, type sync atom moof
 write_data len 148, time nopts, type trailer atom -
-1844ee6d19fd1e6daf2655632cf26310 3283 empty-moov-no-elst
+800f854aff2ac76dfaddebd0562c75b9 3283 empty-moov-no-elst
 write_data len 36, time nopts, type header atom ftyp
 write_data len 1123, time nopts, type header atom -
 write_data len 900, time -33333, type sync atom moof
 write_data len 908, time 966667, type sync atom moof
 write_data len 148, time nopts, type trailer atom -
-139b27dbe2a80c2dc088d0c755f26033 3115 empty-moov-no-elst-no-adjust
+eca1a945c9063dab0858af6b85925533 3115 empty-moov-no-elst-no-adjust
 write_data len 1159, time nopts, type header atom ftyp
 write_data len 796, time 0, type sync atom moof
 write_data len 788, time 1000000, type sync atom moof
 write_data len 148, time nopts, type trailer atom -
-ed8506ebfce4c41732205ae26a4759fd 2891 delay-moov
+e6a4b15443d006efd727a80f6624b7db 2891 delay-moov
 write_data len 1231, time nopts, type header atom ftyp
 write_data len 916, time -33333, type sync atom moof
 write_data len 908, time 966667, type sync atom moof
 write_data len 148, time nopts, type trailer atom -
-3ece148745cd64b4428530a4d1080a2d 3203 delay-moov-elst
+c2ecdbc80668fcee73f5a039e2dba579 3203 delay-moov-elst
 write_data len 1195, time nopts, type header atom ftyp
 write_data len 836, time 0, type sync atom moof
 write_data len 67, time nopts, type trailer atom -
-9562946a369e6fb570fb2fd7aa2fe728 2098 delay-moov-empty-track
+95d6f59a7354b0cfe7ce49927baada4e 2098 delay-moov-empty-track
 write_data len 1195, time nopts, type header atom ftyp
 write_data len 360, time 0, type sync atom moof
 write_data len 360, time 1000000, type sync atom moof
 write_data len 86, time nopts, type trailer atom -
-4c7832b81836331c6c37155dc31d95be 2001 delay-moov-empty-track-flush
+8805d72a27b340ea229c16edde78f974 2001 delay-moov-empty-track-flush
 write_data len 36, time nopts, type header atom ftyp
 write_data len 1123, time nopts, type header atom -
-b7e3c768b9094ebe2fda44979a7f8985 1159 empty-moov-header
+351ae2c8b6d35d98b4848c309cce6704 1159 empty-moov-header
 write_data len 796, time 0, type sync atom moof
 write_data len 788, time 1000000, type sync atom moof
 a0165f4a26a409212b0946e981bdefb9 1584 empty-moov-content
 write_data len 148, time nopts, type trailer atom -
 write_data len 1159, time nopts, type header atom ftyp
-b7e3c768b9094ebe2fda44979a7f8985 1159 delay-moov-header
+351ae2c8b6d35d98b4848c309cce6704 1159 delay-moov-header
 write_data len 796, time 0, type sync atom moof
 write_data len 788, time 1000000, type sync atom moof
 a0165f4a26a409212b0946e981bdefb9 1584 delay-moov-content
 write_data len 148, time nopts, type trailer atom -
-write_data len 24, time nopts, type header atom -
+write_data len 28, time nopts, type header atom -
 write_data len 1123, time nopts, type header atom -
 write_data len 884, time 0, type sync atom sidx
 write_data len 876, time 1000000, type sync atom sidx
 272a474cfd2a68cc5f05b426b14a2b7d 876 empty-moov-second-frag
 write_data len 148, time nopts, type trailer atom -
-write_data len 24, time nopts, type header atom -
+write_data len 28, time nopts, type header atom -
 write_data len 1123, time nopts, type header atom -
 write_data len 876, time 1000000, type sync atom sidx
 272a474cfd2a68cc5f05b426b14a2b7d 876 empty-moov-second-frag-discont
 write_data len 110, time nopts, type trailer atom -
-write_data len 1219, time nopts, type header atom -
+write_data len 1223, time nopts, type header atom -
 write_data len 876, time 1000000, type sync atom sidx
 272a474cfd2a68cc5f05b426b14a2b7d 876 delay-moov-second-frag-discont
 write_data len 110, time nopts, type trailer atom -
-write_data len 1219, time nopts, type header atom ftyp
-6ec3698bcc86013e0016e3d47d230363 1219 delay-moov-elst-init
+write_data len 1223, time nopts, type header atom ftyp
+b3811928793ed0749927eb2f7958421c 1223 delay-moov-elst-init
 write_data len 988, time -33333, type sync atom sidx
 write_data len 996, time 966667, type sync atom sidx
 fcae8f40e015b59aabc8d4a99a759ca1 996 delay-moov-elst-second-frag
 write_data len 148, time nopts, type trailer atom -
-write_data len 1219, time nopts, type header atom ftyp
-6ec3698bcc86013e0016e3d47d230363 1219 delay-moov-elst-init-discont
+write_data len 1223, time nopts, type header atom ftyp
+b3811928793ed0749927eb2f7958421c 1223 delay-moov-elst-init-discont
 write_data len 996, time 966667, type sync atom sidx
 fcae8f40e015b59aabc8d4a99a759ca1 996 delay-moov-elst-second-frag-discont
 write_data len 110, time nopts, type trailer atom -
-write_data len 1219, time nopts, type header atom ftyp
-c3681590a292cb9ca19a5a982e530166 1219 delay-moov-elst-signal-init
+write_data len 1223, time nopts, type header atom ftyp
+041ac8efc35a0d023c26d05eedb20403 1223 delay-moov-elst-signal-init
 write_data len 1004, time -33333, type sync atom sidx
 write_data len 996, time 966667, type sync atom sidx
 aa5462cc0d2144f72154d9c309edb57d 996 delay-moov-elst-signal-second-frag
 write_data len 148, time nopts, type trailer atom -
-write_data len 1219, time nopts, type header atom ftyp
-c3681590a292cb9ca19a5a982e530166 1219 delay-moov-elst-signal-init-discont
+write_data len 1223, time nopts, type header atom ftyp
+041ac8efc35a0d023c26d05eedb20403 1223 delay-moov-elst-signal-init-discont
 write_data len 996, time 966667, type sync atom sidx
 aa5462cc0d2144f72154d9c309edb57d 996 delay-moov-elst-signal-second-frag-discont
 write_data len 110, time nopts, type trailer atom -
-write_data len 1243, time nopts, type header atom ftyp
-dac14c8795d5cbd91ae770c6e2880c62 1243 delay-moov-elst-signal-init-discont-largets
+write_data len 1247, time nopts, type header atom ftyp
+80511a51d1ac9cde62337eed7176ae03 1247 delay-moov-elst-signal-init-discont-largets
 write_data len 996, time 279621233333, type sync atom sidx
 41cac4c3df656a87bb38363fdcd745e6 996 delay-moov-elst-signal-second-frag-discont-largets
 write_data len 110, time nopts, type trailer atom -
-write_data len 1219, time nopts, type header atom ftyp
+write_data len 1223, time nopts, type header atom ftyp
 write_data len 2572, time -333333, type sync atom sidx
 write_data len 996, time 5166667, type sync atom sidx
 write_data len 148, time nopts, type trailer atom -
-f12d4a0e054abcc508cc0d28cb320e57 4935 vfr
-write_data len 1219, time nopts, type header atom ftyp
+c3eb39921c90724784d1ab84fac58b34 4939 vfr
+write_data len 1223, time nopts, type header atom ftyp
 write_data len 2572, time -333333, type sync atom sidx
 write_data len 996, time 5166667, type sync atom sidx
 write_data len 148, time nopts, type trailer atom -
-f12d4a0e054abcc508cc0d28cb320e57 4935 vfr-noduration
+c3eb39921c90724784d1ab84fac58b34 4939 vfr-noduration
 write_data len 1231, time nopts, type header atom ftyp
 write_data len 1500, time -333333, type sync atom moof
 write_data len 1500, time nopts, type unknown atom -
@@ -131,7 +131,7 @@ write_data len 1500, time 9666667, type sync atom moof
 write_data len 1500, time nopts, type unknown atom -
 write_data len 1004, time nopts, type unknown atom -
 write_data len 148, time nopts, type trailer atom -
-3c2c3f98c8a047f0ecefff07570fd457 9299 large_frag
+5bde1358e246e715b2096daa321c9f1b 9299 large_frag
 write_data len 1231, time nopts, type header atom ftyp
 write_data len 684, time -33333, type sync atom moof
 write_data len 504, time 800000, type boundary atom moof
@@ -139,15 +139,15 @@ write_data len 420, time 1266667, type boundary atom moof
 write_data len 668, time 1566667, type sync atom moof
 write_data len 440, time 2233333, type boundary atom moof
 write_data len 262, time nopts, type trailer atom -
-edd19deae2b70afcf2cd744b89b7013d 4209 vfr-noduration-interleave
-write_data len 1231, time nopts, type header atom ftyp
+47cc2460c4b18390c67991cf3251409b 4209 vfr-noduration-interleave
+write_data len 1235, time nopts, type header atom ftyp
 write_data len 916, time 0, type sync atom moof
 write_data len 908, time 1000000, type sync atom moof
 write_data len 148, time nopts, type trailer atom -
-781dbfd228f36903178e29faa727d78b 3203 delay-moov-elst-neg-cts
-write_data len 36, time nopts, type header atom ftyp
+c272739705fb78f9d9bffd4c6376c8ce 3207 delay-moov-elst-neg-cts
+write_data len 40, time nopts, type header atom ftyp
 write_data len 1123, time nopts, type header atom -
 write_data len 1188, time 0, type sync atom moof
 write_data len 908, time 1033333, type sync atom moof
 write_data len 148, time nopts, type trailer atom -
-7630fdf358e02c79e88f312f82a260b7 3403 empty-moov-neg-cts
+26c05cd931471319def6f3d5257a6a7a 3407 empty-moov-neg-cts
diff --git a/tests/ref/lavf/ismv b/tests/ref/lavf/ismv
index 865a6913cf..e7361705fa 100644
--- a/tests/ref/lavf/ismv
+++ b/tests/ref/lavf/ismv
@@ -1,9 +1,9 @@
-bd88b50defa57766619c092ea89f25a6 *tests/data/lavf/lavf.ismv
-313165 tests/data/lavf/lavf.ismv
+4c6bc5ac805a76bbbd886a69d2e61554 *tests/data/lavf/lavf.ismv
+313169 tests/data/lavf/lavf.ismv
 tests/data/lavf/lavf.ismv CRC=0x9d9a638a
-805a2557bf952c84835f3c10b6893e15 *tests/data/lavf/lavf.ismv
-322071 tests/data/lavf/lavf.ismv
+18678627921460328ea3fed238d0d57d *tests/data/lavf/lavf.ismv
+322075 tests/data/lavf/lavf.ismv
 tests/data/lavf/lavf.ismv CRC=0xe8130120
-96053075a3f60d271131fe2d0765c267 *tests/data/lavf/lavf.ismv
-312542 tests/data/lavf/lavf.ismv
+b9a858caf55b1eff2273e746e9f72dc4 *tests/data/lavf/lavf.ismv
+312546 tests/data/lavf/lavf.ismv
 tests/data/lavf/lavf.ismv CRC=0x9d9a638a
