sws_getContext() private method

private sws_getContext ( [ srcW, [ srcH, AVPixelFormat srcFormat, [ dstW, [ dstH, AVPixelFormat dstFormat, [ flags, IntPtr srcFilter, IntPtr dstFilter, IntPtr param ) : IntPtr
srcW [
srcH [
srcFormat AVPixelFormat
dstW [
dstH [
dstFormat AVPixelFormat
flags [
srcFilter IntPtr
dstFilter IntPtr
param IntPtr
return IntPtr
Beispiel #1
0
        private void ConvertToBitmap(ref VideoFrameType t)
        {
            var frame = avFrame;
            //FFmpeg.AVFrame final = gcnew AvFrame(PIX_FMT_BGR24, this->size);
            IntPtr final = AV.avcodec_alloc_frame();

            AV.AVFrame finalFrame = new NativeGetter <AV.AVFrame>(final).Get();

            var dst_fmt = AV.AVPixelFormat.AV_PIX_FMT_BGR24;

            int count = AV.avpicture_get_size(dst_fmt, codecCtx.width, codecCtx.height);

            IntPtr bufferArr = Marshal.AllocHGlobal(count);

            AV.avpicture_fill(final, bufferArr, dst_fmt, codecCtx.width, codecCtx.height);

            IntPtr swsContext = AV.sws_getContext(codecCtx.width, codecCtx.height, codecCtx.pix_fmt,
                                                  codecCtx.width, codecCtx.height, dst_fmt, AV.SWS_BICUBIC, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            if (swsContext == IntPtr.Zero)
            {
                throw new Exception();
            }

            finalFrame = new NativeGetter <AV.AVFrame>(final).Get();
            AV.sws_scale(swsContext, frame.data, frame.linesize, 0, codecCtx.height, finalFrame.data, finalFrame.linesize);

            new NativeSetter <AV.AVFrame>(final).Set(finalFrame);
            // Array::Reverse(bufferArr);

            byte[] buffer = new byte[count];
            Marshal.Copy(bufferArr, buffer, 0, count);
            AV.av_free(final);
            Marshal.FreeHGlobal(bufferArr);


            t.width        = codecCtx.width;
            t.height       = codecCtx.height;
            t.SourceFormat = codecCtx.pix_fmt;
            t.DestFormat   = dst_fmt;
            t.managedData  = buffer;
            t.linesize     = finalFrame.linesize[0];
        }