diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index cc917edb7f..03c3d0ab13 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -444,7 +444,7 @@ FF_MPV_COMMON_OPTS
     { "left",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "pred" },
     { "plane",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "pred" },
     { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, VE, "pred" },
-{ "huffman", "Huffman table strategy", OFFSET(huffman), AV_OPT_TYPE_INT, { .i64 = HUFFMAN_TABLE_DEFAULT }, 0, NB_HUFFMAN_TABLE_OPTION - 1, VE, "huffman" },
+{ "huffman", "Huffman table strategy", OFFSET(huffman), AV_OPT_TYPE_INT, { .i64 = HUFFMAN_TABLE_OPTIMAL }, 0, NB_HUFFMAN_TABLE_OPTION - 1, VE, "huffman" },
     { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = HUFFMAN_TABLE_DEFAULT }, INT_MIN, INT_MAX, VE, "huffman" },
     { "optimal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = HUFFMAN_TABLE_OPTIMAL }, INT_MIN, INT_MAX, VE, "huffman" },
 { NULL},
diff --git a/tests/ref/vsynth/vsynth1-mjpeg b/tests/ref/vsynth/vsynth1-mjpeg
index 11de0207f6..aa441d312a 100644
--- a/tests/ref/vsynth/vsynth1-mjpeg
+++ b/tests/ref/vsynth/vsynth1-mjpeg
@@ -1,4 +1,4 @@
-9ff18b19d12bb9bb2ed434a79f212888 *tests/data/fate/vsynth1-mjpeg.avi
-1515906 tests/data/fate/vsynth1-mjpeg.avi
+63ea9bd494e16bad8f3a0c8dbb3dc11e *tests/data/fate/vsynth1-mjpeg.avi
+1391380 tests/data/fate/vsynth1-mjpeg.avi
 9a3b8169c251d19044f7087a95458c55 *tests/data/fate/vsynth1-mjpeg.out.rawvideo
 stddev:    7.87 PSNR: 30.21 MAXDIFF:   63 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth1-mjpeg-422 b/tests/ref/vsynth/vsynth1-mjpeg-422
index bd760a1c8d..dda3928a4b 100644
--- a/tests/ref/vsynth/vsynth1-mjpeg-422
+++ b/tests/ref/vsynth/vsynth1-mjpeg-422
@@ -1,4 +1,4 @@
-3b19da06ffe23cb804bca7a9a86eb3d5 *tests/data/fate/vsynth1-mjpeg-422.avi
-1756304 tests/data/fate/vsynth1-mjpeg-422.avi
+82d8874bfe13f56ec466b206a08a4402 *tests/data/fate/vsynth1-mjpeg-422.avi
+1611832 tests/data/fate/vsynth1-mjpeg-422.avi
 c35eea486c6d72050f4848eab64032b5 *tests/data/fate/vsynth1-mjpeg-422.out.rawvideo
 stddev:    7.45 PSNR: 30.69 MAXDIFF:   63 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth1-mjpeg-444 b/tests/ref/vsynth/vsynth1-mjpeg-444
index 42a9be3278..66a0efcf95 100644
--- a/tests/ref/vsynth/vsynth1-mjpeg-444
+++ b/tests/ref/vsynth/vsynth1-mjpeg-444
@@ -1,4 +1,4 @@
-9591b754ca151f3802738840fa5c26c0 *tests/data/fate/vsynth1-mjpeg-444.avi
-1989784 tests/data/fate/vsynth1-mjpeg-444.avi
+2dd741cbee9b3499826beca7c7d3b8dc *tests/data/fate/vsynth1-mjpeg-444.avi
+1831614 tests/data/fate/vsynth1-mjpeg-444.avi
 313a4a76af13d5879ea4910107b7ea74 *tests/data/fate/vsynth1-mjpeg-444.out.rawvideo
 stddev:    7.37 PSNR: 30.77 MAXDIFF:   63 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth1-mjpeg-trell b/tests/ref/vsynth/vsynth1-mjpeg-trell
index b97efcbf74..cf2a7ff16e 100644
--- a/tests/ref/vsynth/vsynth1-mjpeg-trell
+++ b/tests/ref/vsynth/vsynth1-mjpeg-trell
@@ -1,4 +1,4 @@
-03d14b3db6232f46c0d931477801a7a6 *tests/data/fate/vsynth1-mjpeg-trell.avi
-1454308 tests/data/fate/vsynth1-mjpeg-trell.avi
-218d4dc8086fdef15d5382e6ba97df0b *tests/data/fate/vsynth1-mjpeg-trell.out.rawvideo
-stddev:    7.71 PSNR: 30.39 MAXDIFF:   62 bytes:  7603200/  7603200
+d9410fa80c07edbd2a2b44ceb06086ca *tests/data/fate/vsynth1-mjpeg-trell.avi
+1360456 tests/data/fate/vsynth1-mjpeg-trell.avi
+0266b223bdd7928426a951164bb4a366 *tests/data/fate/vsynth1-mjpeg-trell.out.rawvideo
+stddev:    7.68 PSNR: 30.42 MAXDIFF:   62 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mjpeg b/tests/ref/vsynth/vsynth2-mjpeg
index 98b257ef01..cf80937dc6 100644
--- a/tests/ref/vsynth/vsynth2-mjpeg
+++ b/tests/ref/vsynth/vsynth2-mjpeg
@@ -1,4 +1,4 @@
-c76100bdc3f4c8e2580bb263accda9ec *tests/data/fate/vsynth2-mjpeg.avi
-830154 tests/data/fate/vsynth2-mjpeg.avi
+9bf00cd3188b7395b798bb10df376243 *tests/data/fate/vsynth2-mjpeg.avi
+792742 tests/data/fate/vsynth2-mjpeg.avi
 2b8c59c59e33d6ca7c85d31c5eeab7be *tests/data/fate/vsynth2-mjpeg.out.rawvideo
 stddev:    4.87 PSNR: 34.37 MAXDIFF:   55 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mjpeg-422 b/tests/ref/vsynth/vsynth2-mjpeg-422
index ddedda68fe..b162bb32c7 100644
--- a/tests/ref/vsynth/vsynth2-mjpeg-422
+++ b/tests/ref/vsynth/vsynth2-mjpeg-422
@@ -1,4 +1,4 @@
-1c8dd65c901ce48ef82d73b80e38c735 *tests/data/fate/vsynth2-mjpeg-422.avi
-920364 tests/data/fate/vsynth2-mjpeg-422.avi
+e37720892c9ee9d02842cc50bf20181e *tests/data/fate/vsynth2-mjpeg-422.avi
+877786 tests/data/fate/vsynth2-mjpeg-422.avi
 4a1b18eeb8b0f3dccc2c0e6a9f8c876d *tests/data/fate/vsynth2-mjpeg-422.out.rawvideo
 stddev:    4.69 PSNR: 34.69 MAXDIFF:   55 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-mjpeg-trell b/tests/ref/vsynth/vsynth2-mjpeg-trell
index ce6d917c18..e1acb33d88 100644
--- a/tests/ref/vsynth/vsynth2-mjpeg-trell
+++ b/tests/ref/vsynth/vsynth2-mjpeg-trell
@@ -1,4 +1,4 @@
-4fdbd2327ed16fc4448eb421def22b5e *tests/data/fate/vsynth2-mjpeg-trell.avi
-765628 tests/data/fate/vsynth2-mjpeg-trell.avi
-ce145393bece26d49076b26cf1a2e52e *tests/data/fate/vsynth2-mjpeg-trell.out.rawvideo
+a59d99d31d24875161504820d4266e4d *tests/data/fate/vsynth2-mjpeg-trell.avi
+734728 tests/data/fate/vsynth2-mjpeg-trell.avi
+42376126213c73c86b408882e24ba015 *tests/data/fate/vsynth2-mjpeg-trell.out.rawvideo
 stddev:    5.03 PSNR: 34.09 MAXDIFF:   67 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth3-mjpeg b/tests/ref/vsynth/vsynth3-mjpeg
index c69338fbc0..4b3371ec22 100644
--- a/tests/ref/vsynth/vsynth3-mjpeg
+++ b/tests/ref/vsynth/vsynth3-mjpeg
@@ -1,4 +1,4 @@
-7d7a2fa8559a3652db52b7a70267d1a3 *tests/data/fate/vsynth3-mjpeg.avi
-64808 tests/data/fate/vsynth3-mjpeg.avi
+eec435352485fec167179a63405505be *tests/data/fate/vsynth3-mjpeg.avi
+48156 tests/data/fate/vsynth3-mjpeg.avi
 c4fe7a2669afbd96c640748693fc4e30 *tests/data/fate/vsynth3-mjpeg.out.rawvideo
 stddev:    8.60 PSNR: 29.43 MAXDIFF:   58 bytes:    86700/    86700
diff --git a/tests/ref/vsynth/vsynth3-mjpeg-422 b/tests/ref/vsynth/vsynth3-mjpeg-422
index b50e4792ed..c364c79a11 100644
--- a/tests/ref/vsynth/vsynth3-mjpeg-422
+++ b/tests/ref/vsynth/vsynth3-mjpeg-422
@@ -1,4 +1,4 @@
-34c57632d23c4322d2e508368e7c8e36 *tests/data/fate/vsynth3-mjpeg-422.avi
-69462 tests/data/fate/vsynth3-mjpeg-422.avi
+396394fab0d456443a3929a33f8c0d59 *tests/data/fate/vsynth3-mjpeg-422.avi
+52606 tests/data/fate/vsynth3-mjpeg-422.avi
 a332893cb0603f2f505fe5d3bf105519 *tests/data/fate/vsynth3-mjpeg-422.out.rawvideo
 stddev:    8.23 PSNR: 29.82 MAXDIFF:   58 bytes:    86700/    86700
diff --git a/tests/ref/vsynth/vsynth3-mjpeg-444 b/tests/ref/vsynth/vsynth3-mjpeg-444
index d701f667cc..0e38744fd2 100644
--- a/tests/ref/vsynth/vsynth3-mjpeg-444
+++ b/tests/ref/vsynth/vsynth3-mjpeg-444
@@ -1,4 +1,4 @@
-0900258953e90ab97a95ccaccb7b0d8a *tests/data/fate/vsynth3-mjpeg-444.avi
-70588 tests/data/fate/vsynth3-mjpeg-444.avi
+3f2dca7be789eb7818c69ec716c0d831 *tests/data/fate/vsynth3-mjpeg-444.avi
+53958 tests/data/fate/vsynth3-mjpeg-444.avi
 79a901f2ed85d82cf1c674fab3d3ef72 *tests/data/fate/vsynth3-mjpeg-444.out.rawvideo
 stddev:    8.21 PSNR: 29.84 MAXDIFF:   58 bytes:    86700/    86700
diff --git a/tests/ref/vsynth/vsynth3-mjpeg-trell b/tests/ref/vsynth/vsynth3-mjpeg-trell
index 9178d02475..5b386c7eed 100644
--- a/tests/ref/vsynth/vsynth3-mjpeg-trell
+++ b/tests/ref/vsynth/vsynth3-mjpeg-trell
@@ -1,4 +1,4 @@
-6f815acb8fce5458561aa902703e6189 *tests/data/fate/vsynth3-mjpeg-trell.avi
-63994 tests/data/fate/vsynth3-mjpeg-trell.avi
-4fed1e12c80df7b67df292b153c3cf16 *tests/data/fate/vsynth3-mjpeg-trell.out.rawvideo
-stddev:    8.27 PSNR: 29.77 MAXDIFF:   61 bytes:    86700/    86700
+484fa337b71c06a0206243814c4894b0 *tests/data/fate/vsynth3-mjpeg-trell.avi
+47816 tests/data/fate/vsynth3-mjpeg-trell.avi
+f0ccfe4584d193fd6d690a85a70db188 *tests/data/fate/vsynth3-mjpeg-trell.out.rawvideo
+stddev:    8.27 PSNR: 29.78 MAXDIFF:   55 bytes:    86700/    86700
diff --git a/tests/ref/vsynth/vsynth_lena-mjpeg b/tests/ref/vsynth/vsynth_lena-mjpeg
index 1487641831..e30ddc7677 100644
--- a/tests/ref/vsynth/vsynth_lena-mjpeg
+++ b/tests/ref/vsynth/vsynth_lena-mjpeg
@@ -1,4 +1,4 @@
-40c5ba1b15006799773617f888c2808b *tests/data/fate/vsynth_lena-mjpeg.avi
-673178 tests/data/fate/vsynth_lena-mjpeg.avi
+007c989af621445dc7c9bd248b9df3b4 *tests/data/fate/vsynth_lena-mjpeg.avi
+635498 tests/data/fate/vsynth_lena-mjpeg.avi
 9d4bd90e9abfa18192383b4adc23c8d4 *tests/data/fate/vsynth_lena-mjpeg.out.rawvideo
 stddev:    4.32 PSNR: 35.40 MAXDIFF:   49 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mjpeg-422 b/tests/ref/vsynth/vsynth_lena-mjpeg-422
index 23dd1a257d..f94ae5815d 100644
--- a/tests/ref/vsynth/vsynth_lena-mjpeg-422
+++ b/tests/ref/vsynth/vsynth_lena-mjpeg-422
@@ -1,4 +1,4 @@
-4a1f72cf4c8e562f4e805f0c7912515b *tests/data/fate/vsynth_lena-mjpeg-422.avi
-746534 tests/data/fate/vsynth_lena-mjpeg-422.avi
+e867bc5e8e4e4555846c61b3cb4580a6 *tests/data/fate/vsynth_lena-mjpeg-422.avi
+707376 tests/data/fate/vsynth_lena-mjpeg-422.avi
 451ac80989c4e14445cf951fd7f83b6d *tests/data/fate/vsynth_lena-mjpeg-422.out.rawvideo
 stddev:    4.18 PSNR: 35.70 MAXDIFF:   49 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mjpeg-444 b/tests/ref/vsynth/vsynth_lena-mjpeg-444
index 1dc103c199..cb4c0a12db 100644
--- a/tests/ref/vsynth/vsynth_lena-mjpeg-444
+++ b/tests/ref/vsynth/vsynth_lena-mjpeg-444
@@ -1,4 +1,4 @@
-969ac14cbc77d5475f4871cefe3cc6b0 *tests/data/fate/vsynth_lena-mjpeg-444.avi
-851446 tests/data/fate/vsynth_lena-mjpeg-444.avi
+9a36b201c4f68051441b1ee1307a2cc2 *tests/data/fate/vsynth_lena-mjpeg-444.avi
+807628 tests/data/fate/vsynth_lena-mjpeg-444.avi
 34edcb9c87ff7aac456a4fb07f43504b *tests/data/fate/vsynth_lena-mjpeg-444.out.rawvideo
 stddev:    4.05 PSNR: 35.96 MAXDIFF:   49 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth_lena-mjpeg-trell b/tests/ref/vsynth/vsynth_lena-mjpeg-trell
index d37d5a2714..86332b2010 100644
--- a/tests/ref/vsynth/vsynth_lena-mjpeg-trell
+++ b/tests/ref/vsynth/vsynth_lena-mjpeg-trell
@@ -1,4 +1,4 @@
-61c12b5e0f95c352c1ff2f3b95d88274 *tests/data/fate/vsynth_lena-mjpeg-trell.avi
-613612 tests/data/fate/vsynth_lena-mjpeg-trell.avi
-ee4999fcc0913e01e69fe689b4229cbe *tests/data/fate/vsynth_lena-mjpeg-trell.out.rawvideo
-stddev:    4.51 PSNR: 35.03 MAXDIFF:   60 bytes:  7603200/  7603200
+6eb36ab28a082f496f1f3bc165704a68 *tests/data/fate/vsynth_lena-mjpeg-trell.avi
+582534 tests/data/fate/vsynth_lena-mjpeg-trell.avi
+dcb183a6a5fa06e7234d46dd97ceb8ec *tests/data/fate/vsynth_lena-mjpeg-trell.out.rawvideo
+stddev:    4.51 PSNR: 35.05 MAXDIFF:   60 bytes:  7603200/  7603200
