Giter Site home page Giter Site logo

mmaitre314 / mediacapturewpf Goto Github PK

View Code? Open in Web Editor NEW
51.0 3.0 26.0 499 KB

Camera preview in WPF Desktop apps using WinRT MediaCapture

Home Page: http://mmaitre314.github.io/MediaCaptureWPF

License: Apache License 2.0

C# 12.71% C++ 72.70% C 2.13% Batchfile 2.65% PowerShell 9.81%

mediacapturewpf's Introduction

Build status NuGet package Symbols

CameraPreview allows previewing the camera video stream of the WinRT MediaCapture API in Desktop WPF apps.

Preview

CameraPreview derives from D3DImage and can be used anywhere a GPU-accelerated ImageSource can be. For instance, inside an <Image> XAML element:

<Grid>
    <Image Name="Preview"/>
</Grid>

The C# code behind creates MediaCapture, initializes it, and passes it to CameraPreview. This object is then set as source of the <Image> element and preview is started.

var capture = new MediaCapture();
await capture.InitializeAsync();

var preview = new CapturePreview(capture);
Preview.Source = preview;
await preview.StartAsync();

References

mediacapturewpf's People

Contributors

erikipedia avatar mmaitre314 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mediacapturewpf's Issues

Target VC runtime 2017

Would it be possible to use the 2017 version of the VC runtime? The one from 2013 does not allow app-local deployment which requires the users of apps that use this package to also have the runtime installed. If the newer one is used the runtime files can be used without installation.

EDIT: FYI we have done this change for use in our product and we can use the component now by just shipping the VC runtime DLLs with our app instead of needing to install them separately.

Dependency description of MSVCR120.DLL and MSVCP120.DLL

Hi, guys.
I've been using this library (I got it from nuget). Thank you.

By the way, I have found that this library has a dependency between MSVCR120.DLL and MSVCP120.DLL and appears to crash unexplained when I launch an application that created this library on a clean target PC.

You need to install "Visual C++ Redistributable Packages for Visual Studio 2013" to resolve this dependency.

To avoid confusion, why don't you put this in a readme file to alert people?
(That seems to me to be far more effective than checking every issue.)

Thanks in advance.
コメント 2020-09-09 150220

COMException (E_NOINTERFACE) raised inside CapturePreviewNative when run inside Parallels Desktop

I am running Windows 10 Pro (v1809 build 17763.292) inside Parallels Desktop Pro (v14.1.0 (45387)) on macOS Mojave (v10.14.1 (18B75)). I have three cameras connected; one conventional USB webcam and the two integrated FaceTime cameras built into my displays, connected over Thunderbolt. All three cameras work fine in the built-in Windows Camera app.

When I run CaptureTestApp on this machine, I get the following managed exception:

System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=Exception has been thrown by the target of an invocation.
  Source=mscorlib
  StackTrace:
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at CaptureTestApp.App.Main()

Inner Exception 1:
COMException: Exception of type 'System.Runtime.InteropServices.COMException' was thrown.

I installed the debugging symbols to get the detail about the inner exception. It is reported as follows:

System.Runtime.InteropServices.COMException
  HResult=0x80004002
  Message=Exception of type 'System.Runtime.InteropServices.COMException' was thrown.
  Source=MediaCaptureWPF.Native
  StackTrace:
   at MediaCaptureWPF.Native.CapturePreviewNative.RefreshPreview() in c:\users\matthieu\source\repos\mediacapturewpf\mediacapturewpf.native\capturepreviewnative.cpp:line 126

Despite the stack trace indicating line 126, the debugger is broken on line 127:

CHK(buffer.QueryInterface(&bufferDxgi));

Note that I've loaded the NuGet version of MediaCaptureWPF into the CaptureTestApp project because I don't have the C++ SDKs installed on my machine. I'm not sure if that makes any difference in this case.

When I look up HResult 0x80004002 it's reported as E_NOINTERFACE.

As mentioned above, the cameras work fine in Microsoft's native Camera app, and also in a very basic UWP app with the following code:

var capture = new MediaCapture();
await capture.InitializeAsync(new MediaCaptureInitializationSettings
{
    StreamingCaptureMode = StreamingCaptureMode.Video
});

capturePreview.Source = capture;
await capture.StartPreviewAsync();

When I boot into Windows using Boot Camp, the cameras all work fine even inside MediaCaptureWPF, so I'm expecting this is going to be caused in some way by Parallels' Direct3D drivers (and I intend to raise this issue with them too), but since an uncaught exception is raised inside MediaCaptureWPF (and it doesn't happen when using the cameras inside UWP even inside Parallels), I figured I'd report it here too.

I'm happy to provide any extra detail or perform extra testing if need be to further diagnose this issue (it would be very helpful for me to be able to develop this app inside Parallels).

Requirements - Windows 10 x64 new machine

What are the requirements to get wpfmediacapture.dll work on a new machine. Windows 10 x64.

My application is Wpf and works on development computer. It has been tested with a build x86 and with a build x64.

I installed visual c++ 2013 runtime x64 et x86 on the target machine windows 10.

I have zero error. Nothing is catched in exceptions. My camera is well detected. But i am not able to get the capture preview.

It just do nothing.

Has someone encountered that?
Any ideas?

NET 6.0

Hello and thanx for your beautiful work. I'm still using it, because WPF still not have a D3D solution. As the years go by, I now need to port MediacaputreWPF on NET 6.0. I tried to get it working: everything is compiling, but I get and exception (invalid cast exception in WINRT) that i do not understand when I try to start the preview. The NET 6.0 version is here: https://github.com/puckkk/MediaCaptureWPF-master-mmaitre-net-6.0
Do you have any ideas?

CapturePreview.Native.dll couldn´t be loaded on a fresh installed Win 8.1 - x64 machine, please help!

Hi, i hope you can help me out!

It seems that trying to open the C++-Projects of your Source in Visual Studio 2015 doesn´t work for some reason. (Only possible when (re)installing VS 2013).

I even couldn´t get the executable (build in VS 2013) to run on a machine without Visual Studio 2013 installed. Am I missing importand dependencies, that comes with the VS installation routine?

Thanks in advance!

Unable to see preview of camera on specific machine

I am not able to see preview of video device on specific machine.
But I am able to get the resolutions and take the screenshot from the video device.

Below is the code snippet to show preview from selected video device.

**DeviceInformation selectedDevice = Devices.SelectedItem as DeviceInformation;

        if (preview != null)
        {
            await preview.StopAsync();
            Preview.Source = null;
            preview = null;
        }

        var settings = new MediaCaptureInitializationSettings();
        settings.AudioDeviceId = "";
        settings.VideoDeviceId = selectedDevice.Id;
        settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
        capture = new MediaCapture();
        await capture.InitializeAsync();

        preview = new CapturePreview(capture);
        Preview.Source = preview;
        await preview.StartAsync();

        PopulateComboBox(MediaStreamType.Photo, Resolutions, true);**

Here is the code snippet to take screenshot.

**try
{
ImageEncodingProperties format = ImageEncodingProperties.CreatePng();
//generate file in local folder:
StorageFile capturefile;
StorageFolder folder = KnownFolders.SavedPictures;
capturefile = await folder.CreateFileAsync("photo_" + DateTime.Now.Ticks.ToString() + ".png", CreationCollisionOption.ReplaceExisting);
//take & save photo
await capture.CapturePhotoToStorageFileAsync(format, capturefile);
//show captured photo

            if (!Directory.Exists(@"C:\Exports\CameraCaptures\"))
            {
                Directory.CreateDirectory(@"C:\Exports\CameraCaptures\");
            }

            string filePath = @"C:\Exports\CameraCaptures\" + Path.GetFileName(capturefile.Path);
            File.Copy(capturefile.Path, filePath);

            BitmapImage img = new BitmapImage(new Uri(filePath, UriKind.RelativeOrAbsolute));
            Captured.Source = img;
            Captured.Visibility = Visibility.Visible;
            Preview.Visibility = Visibility.Collapsed;

            await capturefile.DeleteAsync(StorageDeleteOption.PermanentDelete);
        }
        catch (Exception ex)
        {
            LogHelper.WriteException(ex);
        }**

Please find configuration of the machine shown in the image.

image

System.Runtime.InteropServices.COMException

Hello

I'm trying to get your MediaCaptureWPF working, in my the sample project I just want to show preview
but the functuion (preview.StartAsync();) makes bug in MediaCaptureWPF.Native

ERROR CODE 0x80004002

VS2017/Win10

Exception "System.Runtime.InteropServices.COMException"

Hello !
I'm trying to get your MediaCaptureWPF working, for two days long now. I've downloaded your source code, build the libraries, and launched it, but I get a "System.Runtime.InteropServices.COMException" in mscorlib.dll...
I tried to add the package in my project where I need it, but the same exception is thrown.
I get this exception when the program tries to create a new 'CapturePreviewNative' object, in the CapturePreview.cs.
Hope you can help !
Thanks in advance ! ;)

Exception while initializing media capture

I am getting {"Exception from HRESULT: 0xC00DABE0"} on Line 26 of MainWindow.xaml.cs (await capture.InitializeAsync....)

Following is the stack trace
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at CaptureTestApp.MainWindow.d__1.MoveNext() in ...\CaptureTestApp\MainWindow.xaml.cs:line 26

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.