From e802b6a08a6243aefcecfe6b6c6a9385d7b8d4a962c380326094cee132c0228d Mon Sep 17 00:00:00 2001 From: copecone Date: Tue, 13 Oct 2026 15:43:29 +0900 Subject: [PATCH] Fix Odd Resolution Video Background Decoding --- Util/FFmpeg/FFmpegNativeDecoder.cs | 6 +++--- Util/VideoBGPlayer.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Util/FFmpeg/FFmpegNativeDecoder.cs b/Util/FFmpeg/FFmpegNativeDecoder.cs index e9adc68..0e67974 100644 --- a/Util/FFmpeg/FFmpegNativeDecoder.cs +++ b/Util/FFmpeg/FFmpegNativeDecoder.cs @@ -1125,7 +1125,7 @@ internal sealed unsafe class FFmpegNativeDecoder : IDisposable /// /// Pointer to destination buffer for Y plane (Width * Height bytes). /// Row stride in bytes for Y plane. - /// Pointer to destination buffer for interleaved UV plane (Width * (Height / 2) bytes). + /// Pointer to destination buffer for interleaved UV plane (((Width + 1) / 2) * 2 * ((Height + 1) / 2) bytes). /// Row stride in bytes for UV plane. /// Timestamp of the output frame in seconds. /// True if a frame was successfully retrieved; false on EOF. @@ -1178,7 +1178,7 @@ internal sealed unsafe class FFmpegNativeDecoder : IDisposable int w = Width; int h = Height; int uvH = (h + 1) / 2; - int uvRowBytes = (w / 2) * 2; + int uvRowBytes = ((w + 1) / 2) * 2; // Copy Y plane (row by row to safely skip linesize GPU padding) for (int y = 0; y < h; y++) @@ -1239,7 +1239,7 @@ internal sealed unsafe class FFmpegNativeDecoder : IDisposable int w = Width; int h = Height; int uvH = (h + 1) / 2; - int uvRowBytes = (w / 2) * 2; + int uvRowBytes = ((w + 1) / 2) * 2; if (yBuffer.Length < (long)w * h || uvBuffer.Length < (long)uvRowBytes * uvH) { diff --git a/Util/VideoBGPlayer.cs b/Util/VideoBGPlayer.cs index def447a..b9ac9d1 100644 --- a/Util/VideoBGPlayer.cs +++ b/Util/VideoBGPlayer.cs @@ -97,7 +97,7 @@ internal class VideoBGPlayer : MonoBehaviour _kernelIndex = _computeShader.FindKernel("CSMain_NV12ToRGBA"); _textureY = new Texture2D(w, h, TextureFormat.R8, false); - _textureUV = new Texture2D(w / 2, h / 2, TextureFormat.RG16, false); + _textureUV = new Texture2D((w + 1) / 2, (h + 1) / 2, TextureFormat.RG16, false); ConfigureTexture(_textureY); ConfigureTexture(_textureUV); @@ -118,8 +118,8 @@ internal class VideoBGPlayer : MonoBehaviour _kernelIndex = _computeShader.FindKernel("CSMain_YUV420PToRGBA"); _textureY = new Texture2D(w, h, TextureFormat.R8, false); - _textureU = new Texture2D(w / 2, h / 2, TextureFormat.R8, false); - _textureV = new Texture2D(w / 2, h / 2, TextureFormat.R8, false); + _textureU = new Texture2D((w + 1) / 2, (h + 1) / 2, TextureFormat.R8, false); + _textureV = new Texture2D((w + 1) / 2, (h + 1) / 2, TextureFormat.R8, false); ConfigureTexture(_textureY); ConfigureTexture(_textureU); ConfigureTexture(_textureV);