diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 8ef23f134f9710b27131e5f33e972de0a0c9e1a1..bf1cf25770ad2e69d3fce2a684fa55ce2a60cde5 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -167,6 +167,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         av_log(avctx, AV_LOG_ERROR,
                "Invalid combination -slices %d and -max_nal_size %d.\n",
                avctx->slices, s->max_nal_size);
+        err = AVERROR(EINVAL);
         goto fail;
     }
 
@@ -195,6 +196,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         } else {
             av_log(avctx, AV_LOG_ERROR, "Invalid -max_nal_size, "
                    "specify a valid max_nal_size to use -slice_mode dyn\n");
+            err = AVERROR(EINVAL);
             goto fail;
         }
     }