Ejemplo n.º 1
0
        unsafe public VideoFormat(int width, int height, AVPixelFormat pixelFormat, int align = 8)
        {
            if (!align.IsPowOf2())
            {
                throw new ArgumentException($"对齐数必须是2的整数幂", nameof(align));
            }

            Width       = width;
            Height      = height;
            PixelFormat = pixelFormat;
            Align       = align;
            Bytes       = FF.av_image_get_buffer_size(pixelFormat, width, height, align).CheckFFmpegCode();
            PlaneCount  = FF.av_pix_fmt_count_planes(pixelFormat).CheckFFmpegCode();

            //--- 参考 imgutils.c 的 av_image_fill_arrays
            var stridesTmp = stackalloc int[4];

            FF.av_image_fill_linesizes(stridesTmp, pixelFormat, width).CheckFFmpegCode();

            strides = new int[PlaneCount];
            for (int i = 0; i < PlaneCount; i++)
            {
                strides[i] = (stridesTmp[i] + (align - 1)) & ~(align - 1);
            }
            //---
        }