public VideoFrameConverter(Size sourceSize, AVPixelFormat sourcePixelFormat, Size destinationSize, AVPixelFormat destinationPixelFormat) { _destinationSize = destinationSize; _pConvertContext = ffmpeg.sws_getContext(sourceSize.Width, sourceSize.Height, sourcePixelFormat, destinationSize.Width, destinationSize.Height, destinationPixelFormat, ffmpeg.SWS_FAST_BILINEAR, null, null, null); if (_pConvertContext == null) { throw new ApplicationException("Could not initialize the conversion context."); } var convertedFrameBufferSize = ffmpeg.av_image_get_buffer_size(destinationPixelFormat, destinationSize.Width, destinationSize.Height, 1); _convertedFrameBufferPtr = Marshal.AllocHGlobal(convertedFrameBufferSize); var dstData = new byte_ptrArray4(); var dstLinesize = new int_array4(); ffmpeg.av_image_fill_arrays(ref dstData, ref dstLinesize, (byte *)_convertedFrameBufferPtr, destinationPixelFormat, destinationSize.Width, destinationSize.Height, 1); _dstLinesize = dstLinesize.ToArray(); _dstData = dstData.ToArray(); for (uint i = 0; i < 4; i++) { dstData[i] = null; } ffmpeg.av_free(&dstLinesize); }
public static int[] GetStrides(PixelFormat pixelFormat, int width, int align) { // Ensure align is a power of two... // Based on: // https://github.com/ibukisaar/SaarFFmpeg/blob/9310b8e8dea99712c9dfec4df746cfb5b8f72d25/SaarFFmpeg/CSharp/VideoFormat.cs // MIT Licenced // Copyright (c) 2018 Saar Ibuki var avFormat = pixelFormat.ToAVFormat(); int planeCount = ffmpeg.av_pix_fmt_count_planes(avFormat); var temp = new int_array4(); ffmpeg.av_image_fill_linesizes(ref temp, avFormat, width); var tempValues = temp.ToArray(); var strides = new int[planeCount]; for (int i = 0; i < planeCount; i++) { strides[i] = (tempValues[i] + (align - 1)) & ~(align - 1); } return(strides); }