Beispiel #1
0
	private void DrawImage(VideoFrameType type)
	{
		Stream str = new MemoryStream();
		BinaryWriter writer = new BinaryWriter(str);
		// LITTLE ENDIAN!!
		writer.Write(new byte[] { 0x42, 0x4D });
		writer.Write((int)(type.managedData.Length + 0x36));
		writer.Write((int)0);
		writer.Write((int)0x36);
		writer.Write((int)40);
		writer.Write((int)type.width);
		writer.Write((int)type.height);
		writer.Write((short)1);
		writer.Write((short)24);
		writer.Write((int)0);
		writer.Write((int)type.managedData.Length);
		writer.Write((int)3780);
		writer.Write((int)3780);
		writer.Write((int)0);
		writer.Write((int)0);
		for (int y = type.height - 1; y >= 0; y--)
			writer.Write(type.managedData, y * type.linesize, type.width * 3);
		writer.Flush();
		writer.Seek(0, SeekOrigin.Begin);
		Bitmap bitmap = new Bitmap(str);
		g.DrawImage(bitmap, 0, 0, mainDraw.WidthRequest, mainDraw.HeightRequest);
		writer.Close();

	}
Beispiel #2
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];
        }
Beispiel #3
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];
        }
Beispiel #4
0
 public void PutImage(VideoFrameType type)
 {
     queue.Enqueue(type);
 }
 public void PutImage(VideoFrameType type)
 {
     queue.Enqueue(type);
 }