diff --git a/build/cross/Dockerfile.arm64 b/build/cross/Dockerfile.arm64 index dbf059b7..2aa20c2d 100644 --- a/build/cross/Dockerfile.arm64 +++ b/build/cross/Dockerfile.arm64 @@ -60,6 +60,7 @@ RUN dpkg --add-architecture arm64 # Install cross-compiler and native build tools RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ + patch \ pkg-config \ cmake \ nasm \ @@ -250,6 +251,9 @@ RUN github_prefix="" \ && make install \ && rm -rf /tmp/opus /tmp/opus.tar.gz +# Reject raw formats smaller than the requested frame before any V4L2 upload. +COPY build/cross/patches/0001-v4l2-m2m-reject-undersized-encoder-format.patch /tmp/ffmpeg-v4l2-size.patch + # Download and build FFmpeg with RKMPP support RUN mkdir -p /tmp/ffmpeg-build && cd /tmp/ffmpeg-build \ && github_prefix="" \ @@ -261,6 +265,7 @@ RUN mkdir -p /tmp/ffmpeg-build && cd /tmp/ffmpeg-build \ && git remote add origin "${github_prefix}https://github.com/nyanmisaka/ffmpeg-rockchip.git" \ && git fetch --depth 1 origin ${FFMPEG_ROCKCHIP_REV} \ && git checkout --detach FETCH_HEAD \ + && patch -p1 < /tmp/ffmpeg-v4l2-size.patch \ && cd .. \ # Build RKMPP && mkdir -p rkmpp/build && cd rkmpp/build \ diff --git a/build/cross/Dockerfile.armv7 b/build/cross/Dockerfile.armv7 index b1c52ef5..3e1931e4 100644 --- a/build/cross/Dockerfile.armv7 +++ b/build/cross/Dockerfile.armv7 @@ -60,6 +60,7 @@ RUN dpkg --add-architecture armhf # Install cross-compiler and native build tools RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ + patch \ pkg-config \ cmake \ nasm \ @@ -239,6 +240,9 @@ RUN github_prefix="" \ && make install \ && rm -rf /tmp/opus /tmp/opus.tar.gz +# Reject raw formats smaller than the requested frame before any V4L2 upload. +COPY build/cross/patches/0001-v4l2-m2m-reject-undersized-encoder-format.patch /tmp/ffmpeg-v4l2-size.patch + # Download and build FFmpeg with RKMPP support RUN mkdir -p /tmp/ffmpeg-build && cd /tmp/ffmpeg-build \ && github_prefix="" \ @@ -250,6 +254,7 @@ RUN mkdir -p /tmp/ffmpeg-build && cd /tmp/ffmpeg-build \ && git remote add origin "${github_prefix}https://github.com/nyanmisaka/ffmpeg-rockchip.git" \ && git fetch --depth 1 origin ${FFMPEG_ROCKCHIP_REV} \ && git checkout --detach FETCH_HEAD \ + && patch -p1 < /tmp/ffmpeg-v4l2-size.patch \ && cd .. \ # Build RKMPP && mkdir -p rkmpp/build && cd rkmpp/build \ diff --git a/build/cross/patches/0001-v4l2-m2m-reject-undersized-encoder-format.patch b/build/cross/patches/0001-v4l2-m2m-reject-undersized-encoder-format.patch new file mode 100644 index 00000000..1688b34b --- /dev/null +++ b/build/cross/patches/0001-v4l2-m2m-reject-undersized-encoder-format.patch @@ -0,0 +1,36 @@ +--- a/libavcodec/v4l2_m2m_enc.c ++++ b/libavcodec/v4l2_m2m_enc.c +@@ -338,6 +338,7 @@ + V4L2m2mPriv *priv = avctx->priv_data; + enum AVPixelFormat pix_fmt_output; + uint32_t v4l2_fmt_output; ++ unsigned int output_width, output_height; + int ret; + + ret = ff_v4l2_m2m_create_context(priv, &s); +@@ -370,6 +371,25 @@ + v4l2_fmt_output = output->format.fmt.pix_mp.pixelformat; + else + v4l2_fmt_output = output->format.fmt.pix.pixelformat; ++ ++ /* Drivers may clamp the requested raw format to their supported size. ++ * The software-frame upload still uses avctx/frame dimensions, so a ++ * smaller negotiated format would overrun the mapped output buffers. ++ * Allow upward alignment, but reject frames that do not fit. ++ */ ++ if (V4L2_TYPE_IS_MULTIPLANAR(output->type)) { ++ output_width = output->format.fmt.pix_mp.width; ++ output_height = output->format.fmt.pix_mp.height; ++ } else { ++ output_width = output->format.fmt.pix.width; ++ output_height = output->format.fmt.pix.height; ++ } ++ if (output_width < avctx->width || output_height < avctx->height) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Encoder cannot fit requested %dx%d frame in negotiated %ux%u format\n", ++ avctx->width, avctx->height, output_width, output_height); ++ return AVERROR(EINVAL); ++ } + + pix_fmt_output = ff_v4l2_format_v4l2_to_avfmt(v4l2_fmt_output, AV_CODEC_ID_RAWVIDEO); + if (pix_fmt_output != avctx->pix_fmt) {