AForge.Video.FFMPEG XamlParseException - c#

I'm trying to set up a simple C# application where I want to record multiple USB webcams and save their feeds to some files. I'm using AForge.NET since this seems to be the most popular option for this sort of application. I can record video fine using the AForge.Video.VFW AVIWriter but due to a number of reasons I need to use the AForge.Video.FFMPEG VideoFileWriter. Whenever I try to use this class however, I get a System.Windows.Markup.XamlParseException with no additional information or inner exceptions apart from a little additional information which is quite useless.
I have a simple code example to trigger the exception:
using AForge.Video.FFMPEG;
namespace CameraPrototype {
public partial class MainWindow {
public MainWindow() {
InitializeComponent();
VideoFileWriter videoFileWriter = new VideoFileWriter();
}
}
}
I've also googled a bit around and tried some suggestion mentioned elsewhere:
Checking all the boxes in Exceptions Settings, enabling breaks on all types of exceptions. I had hoped this would give me some more info when the exception was thrown, unfortunately it doesn't change anything.
Copying the FFMPEG DLLs (swscale-2.dll, postproc-52.dll, etc) into the same folder as the application's built executable (../bin/Debug/). I 'm pretty sure the exception has something to do with ffmpeg, but this particular solution isn't working. Perhaps I'm doing something wrong here or I'm missing something for ffmpeg to work?
If anyone have any idea what I might be doing wrong or how I can get more information about the exception, I would really appreciate any help. Let me know if I need to post any other information. Thanks!
Edit:
Though it doesn't really answer the question, I'm also open to suggestions for alternatives to AForge.NET, as long as it lets me record and save video from multiple USB webcams.

You could give Accord.NET a try, it has ffmpeg bundled with the Accord.Video.FFMPEG, no extra setup needed. It provides the same features and functions as AForge.NET plus a little extra, but unless you need extended machine learning functionality, there isn't really a difference.

Related

OpenHardwareMonitor not publishing to WMI

According to the docs, OpenHardwareMonitor should publish 2 class (Hardware and Sensor) to the WMI but I cannot see any. I OpenHardwareMonitor has full read & write access to WMI so I'm not sure what's wrong. Am I even going about it the right way and should you be able to see those classes?
EDIT
Probably a cause of the same problem but when attempting to use the namespace OpenHardwareMonitor in my c# app
using OpenHardwareMonitor;
it does not recognise it
I forgot to add the .dll to my resources. Rookie error

visual c# button opens file without specifying drive

I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.

Is there a way of capturing debug messages in C# and then outputting them to a separate window?

I have spent 3 days looking this up and I cannot find a solid answer. I want to capture debug messages and than output them to a list log. I am trying to do this in C#. Would love some help from the community to point me in the right direction.
Well, sure that's possible. Debug output is not limited to being displayed in the Output Window.
All you have to do is write a custom listener and add it to the Debug.Listeners collection. You can find the full documentation about adding trace listeners here on MSDN.
The only thing to watch out for is that the listeners are shared for debug and trace output, so if you add one, you'll receive both types of messages.
If that sounds like too much work and you just need a quick-and-dirty solution, you can download the free DebugView utility from Sysinternals. This neat little tool is a separate application that you run, and it listens to all debugging output from all of the programs installed on the machine. If you use this, you won't even have to change a single line of code in your application—all of the output send to Debug.Write will show up in the DebugView window.
Alternatively, if you're looking for something long-term that you could perhaps even ship with your application, I would encourage you to investigate adding a logging feature. There are lots of good open source libraries that provide this functionality, and it can be invaluable out in the field when your app is deployed to systems with unknown configurations.
As far as logging goes, Log4Net is solid and easy to use. You can add it to your project via NuGet (if you don't know what NuGet is, check it out: it's really nice). It allows you to log more or less wherever you want (console, file, mail, db ... )
Website contains good documentation and examples.

Is it possible to generate complex tones in C#?

I need to create a sound containing tones of many different frequencies. Is there any way to do this in C#?
The only tone generating methods I've seen so far involve console.beep, which works, but only for pure tones (single frequencies).
The Audiere library makes this extremely easy to do. Here's a nearly complete C# program to generate the DTMF tone for the "1" button:
AudioDevice device = new AudioDevice();
OutputStream tone1a = device.CreateTone(697); // part A of DTMF for "1" button
OutputStream tone1b = device.CreateTone(1209); // part B
tone1a.Volume = 0.25f;
tone1b.Volume = 0.25f;
tone1a.Play();
tone1b.Play();
Thread.Sleep(2000);
// when tone1a stops, you can easily tell that the tone was indeed DTMF
tone1a.Stop();
To use Audiere in C#, the easiest way to get up and running is to use Harald Fielker's C# binding (which he claims works on Mono and VS; I can confirm it works in the both full version of VS2005 and using the separate Express 2008 versions of C# and VC++). You'll need to download the Win32 Audiere DLL, lib, and header (which are all in the same zip) and you'll need to build the C# binding from source using both VC++ and C#.
One of the nice benefits of using Audiere is that the calls are non-blocking. You don't have to wait for tone1a to stop playing before you start tone1b, which is clearly a necessity for playing complex tones. I am not aware of any hard upper limits on how many simultaneous output streams you can use, so it's probably whatever your hardware/OS supports. By the way, Audiere can also play certain audio files (MP3, WAV, AIFF, MOD, S3M, XM, IT by itself; Ogg Vorbis, Flac, Speex with external libraries), not just pure generated tones.
One possible downside is that there is a slightly audible "click" as you start or stop an individual tone; it's not noticeable if you add one tone to an already playing tone. The easiest workaround I've found for that is to slowly ramp the tone's volume up or down when you're turning the tone on or off, respectively. You might have to play around with the ramp speed to get it to sound "just right".
Note that Audiere is LGPL-licensed, and the binding has no license attached to it. You'll have to consult your legal team or try to get a hold of Harald if you want to use his binding in a commercial product; or you could just make your own binding and avoid the hassle.
#Tom: Since there is no specific license attached to Harald's library, I'm not sure what implications would come of hosting it; however, I believe I can at least give you fine detail on exactly how my libaudieresharpglue project is set up.
Using Visual C++ Express 2008, open up bindings/csharp/libaudieresharpglue/vc8.0/libaudieresharpglue.sln. VC++ will automatically convert the solution to a VS9 solution.
In another folder, you should have the Audiere package from Sourceforge. Under your VC++ project properties, go to Configuration Properties > C/C++ > General, and make sure you have path/to/audiere-1.9.4-win32/include in your "Additional Include Directories." Then, in that same window, go to Linker > General and make sure you have /path/to/audiere-1.9.4-win32/lib in your "Additional Library Directories." Then, you should be able to build the project (preferably in Release mode) and this output libaudieresharpglue.dll in your vc8.0/Release folder.
Next, open up Visual C# Express 2008. Open up bindings\csharp\test\vc8.0\AudiereCSharpTest.sln and let it convert the solution. The project should build fine, but then you will get an error when you run it. That's fine; in your csharp/test/vc8.0/bin/Release folder, you need to add both libaudieresharpglue.dll from the VC++ solution and audiere.dll from the package from Sourceforge.
Now, you should be able to build and run AudiereCSharpTest. Note that by default, #define stream_test is not commented out at the top of AudiereTest.cs, and that will reference a file that is not on your hard drive. You can simply comment out that #define and uncomment noise_test or square_test.
That should cover it; if I missed any details, hopefully they are small enough to get by on your own :)
You can always try DirectSound...
I have been looking at NAudio with the view to create a program that emulates feedback whilst playing a backing track. There is a blog post about generating sine waves at specific frequencies, I suspect that this could be adapted to do what you are looking for.
Yes it is possible.
Here is a link to a tutorial on this. but of course this also uses Console.Beep
The MSDN documentation doesn't make it clear if Console.Beep is asynchronous or not. If it is, you can probably fire off as many calls as you need in quick succession and nobody will be the wiser. You'd want to use the version that takes a frequency and a duration, of course.
Essentially, you have to implement your own software synthesizer or find a 3rd party library. See: http://en.wikipedia.org/wiki/Demo_(computer_programming)#Music

C# PrintDialog.PrinterSettings.CanDuplex Reports Wrongly

I'm trying to setup some code to print to different trays on a photo copier depending on what the document is (different sizes, paper colours...). It is one particular type of copier so I am not too worried about the code working in other scenarios. I still want to show the print dialog, just with the settings having better defaults for each document.
I have managed to setup the majority of what I want using properties in
PrintDialog.PrinterSettings.
However on trying to set the duplexing using
PrintDialog.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Vertical;
It fails, remaining the same as it was before. If I check if duplex is supported using
PrintDialog.PrinterSettings.CanDuplex;
It returns false which is not the case I can change it on the dialog and it prints fine. Has anyone else had this problem? Is there a work around? Perhaps something involving COM (please be gentle not used interop code much)
It's a Gestetner 2212 copier and I believe the print server is a Windows Server 2008 machine.
Edit:
I found this link
http://bytes.com/topic/c-sharp/answers/238860-using-setprinter-c-set-duplex-option-print-prefs
Which seems to be a similar problem it seems to be some kind of problem related to using a networked printer and trying to set duplex. However the link doesn't post the solution it was emailed to them (I hate it when people do that). Anyone know how I can set the duplexing using COM interop code.
Seems network printers duplex property cannot be set in .NET code easily, even when it says it has changed the property it doesn't output correctly. There is a way to do it using com interop but it still requires modifying security levels for the printer so is more hassle than it is worth.
Try implementing a handler for the PrintPage event with following code:
if (e.PageSettings.PrinterSettings.IsValid && e.PageSettings.PrinterSettings.CanDuplex)
e.PageSettings.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Vertical;
Tried it with a HP Laserjet M3035. It didn't show in the PrintDialog window but printed the document in duplex anyway.

Categories