Working way to make video from images in C# - c#

Does anybody have a known reliable way to create a video from a series of image files? Before you mod me down for not searching for the answer before posting the question, and before you fire off a simple message like "use FFMPEG," read the rest of this message.
I'm trying to create a video, it doesn't matter too much what format as long as it's widely supported, from a series of images (.jpg, .bmp, etc.). My platform is Windows Server 2008, 64-bit. If I can make the video from within my C# program, that's great, but I'm not averse to writing a series of image files to a directory and then firing off an external program to make a video from those images.
The only constraints are: it must work on my Windows Server 2008 system, and be scriptable. That is, no GUI programs that require operator intervention.
I found a number of similar questions on StackOverflow, and have tried several of the solutions, all with varying degrees of frustration and none with anything like success.
FFMPEG looks like a great program. Maybe it is, on Linux. The two Windows builds I downloaded are broken. Given this command line:
ffmpeg -r 1 -f image2 -i jpeg\*.jpg video.avi
One of the builds reads the images and then crashes due to data execution prevention. The other reads the first file and then spits out an error message that says "cannot find suitable codec for file jpeg/image2.jpg". Helpful, that. In any case, FFMPEG looks like a non-starter under Windows.
One answer to a previous posting recommended Splicer . It looks like pretty good code. I compiled the samples and tried to run, but got some cryptic error message about a file not found. It looks like a COM class isn't registered. I suppose I need to install something (DirectShow, maybe, although I thought that was already installed?). Depending on what's required, I might have a difficult time justifying its installation on a server. ("What? Why do you need that on a server?")
Another answer suggested the AviFile library from Code Project. That looks simple enough: a wrapper around the Windows AviFile subsystem. Except that the AVI files the package creates appear to have all of the frames, but only the first frame shows when I play the AVI in Windows Media Player. Well, that and if you try to create a compressed video, the program throws an exception.
So, I'm left wondering if there is a good, reliable way to do what I want: on a Windows system, create an AVI or other common video file format from a series of images, either through a .NET API or using an external program. Any help?

After working with it a while and taking a look at x264 and VideoLan, I went back to Splicer. It turns out that the cryptic error message was due to an error in my code.
It looks like Splicer will do what I want: programmatically create videos from a series of images.
Thanks to all who responded.

You can use VideoLan and I'd recommend it.
I've had direct experience in a C# application with VideoLan doing these two things:
Embedding a VLC viewer in my C# application (there are 3-4 C# "wrappers" for the VLC veiwer).
Using vlc.exe in a separate Process by sending it command-line arguments.
The fact that VideoLan has a command-line interface is a great thing. And VLC supports a command-line option that disables any visual element; so the VLC GUI doesn't pop up and neither does a command-line window. Thus, in a C# application you can farm out the video-related work to the VLC client. C# has the Process class which can manage your vlc.exe instances for you. It ends up being a pretty neat solution.

The handling of video on Windows (encoding and playback) is a real quagmire. And .NET isn't going to help you at all - you're always going to be either PInvoking/COM-interoping native APIs or using a .NET wrapper that someone else has built to do the same.
Anyway, I can't say I've used it, but a good bet seems to be the x264 library that is part of the videolan project. That gives you a self-contained C library that you can PInvoke and you don't have to worry about installing and DirectShow garbage on your server. It'll generate H.264 format video which is playable in Flash as I understand it.

I've used mplayer's mencoder to create AVI (with codecs msmpeg4/mp3, readable by default with Windows Media Player) from TGA files on linux like this:
mencoder mf://*.tga -mf fps=25:type=tga \
-audiofile /tmp/test.mp3 -oac copy \
-of lavf -ovc lavc \
-lavcopts vcodec=msmpeg4v2:mbd=2:mv0:trell:cbp:last_pred=3:vbitrate=3000 \
-o /tmp/test.avi
I know mplayer does have a Windows version.

Instead of just going through all the hassle, you could coppy all the images that you want to be included in your video to the clipboard and have it imported into Windows Live Movie Maker (dynamically, of course!) and have it compile for you!
All of this CAN be done through code, but this way, you don't have to create it yourself. As you said that the platform was Windows, and ALL Windows comps have Windows Live Movie Maker installed, so it shouldn't be a problem for anyone using your application unless
a) They uninstalled Windows Live Movie Maker
b) They are using a computer running on a Windows Version more than 8 or 9 years old...

Related

Is there a good way of extracting data from GUI on Windows OS using python libraries?

I'm currently working on a project which requires me to extract data from GUI on Windows OS - say I need to extract content such as the URL in my browser or the name of the attachment on Gmail.
I have already tried LDTP/Cobra, however it's pretty slow - each request can take up to 5 seconds and I need this library to be reasonably fast. Besides that, the LDTP/Cobra is pretty outdated and the latest MSI file doesn't work with python 3.* unless you modify the library itself.
I've been also researching the pywin API, however, it seems that you can't really extract anything with FindWindowEx and WM_GETTEXT method anymore, but I might be wrong.
My question is - is there any other library that would allow me to extract basically anything from a given Window? Maybe I'm missing an important part of the mentioned libraries? Ideally, I'm looking for a python library, but if there is no other way I could try and write some C# code.

C# Vlc.DotNet Libraries - Null reference exception

Recently stumbled upon this post whilst trying to decide on the best way of getting a VLC player into C#.
Does VLC media player have a C# interface?
I downloaded the dll files and imported them into my project, but then realised I had no real idea of how to use them. Has anyone got a Windows Forms example of this code that works? The code have tried is shown below -
Vlc.DotNet.Core.Medias.MediaBase media = new
Vlc.DotNet.Core.Medias.PathMedia(#"C:\Users\...\SampleVideos\Wildlife.wmv");
Vlc.DotNet.Forms.VlcControl vlcControl1 = new Vlc.DotNet.Forms.VlcControl();
vlcControl1.Play(media);
I am also using the code in this link in the main program.cs of my project.
http://vlcdotnet.codeplex.com/wikipage?title=Forms
The current problem I experience is that upon starting the project it throws a NullReferenceException when it gets to ->
vlcControl1.Play(media)
The problem seems to be with the vlcControl but I am unsure why. The documentation seems to rather thin and I couldn't find any working examples on the codeplex site. If anyone has a working forms example or knows what I might have missed please let me know!
Here is the call stack present when the error occurs ->
RTSPViewer_Test.exe!RTSPViewer_Test.Form1.Form1_Load(object sender,
System.EventArgs e) Line 31 + 0xd bytes C#
RTSPViewer_Test.exe!RTSPViewer_Test.Program.Main() Line 30 + 0x1d bytes C#
When debugging it appears that the Media and Medias attribute of the VLC control are both null. When trying to set the Media of the control to the media object created above a
NullReferenceException
Checking the VLC control object Media does indeed equal null, but I am not sure why it hasn't been initialised properly.
I was unable to get the program to work using the latest version of the Vlc.dotnet libraries but instead used the alpha 2 version which was posted by Raj. I used VLC version 1.1.5 with this library to get the basic example to function properly. My end objective was to stream from an rtsp device, however this library does not appear to support this functionality yet.
For anyone looking to use a good C# wrapper for using VLC then this is a great example -
http://www.codeproject.com/Articles/109639/nVLC
Used the library files from VLC 1.1.1 with this project and works fine. Supports pretty much all the features that you would usually use in VLC but gives you much more control over what you use them for.
Many of the issues that arise when using these DLL wrappers arose from incorrect versions of the source DLL files. The VLC libraries are only 32 bit at this time, so you need to make sure to compile using x86 mode otherwise the libvlc.dll will not load properly and the application will crash. Using the above example you must also make sure that the libvlc.dll, libvlccore.dll and the plugins folder are included in the build folder.

Problem with .DLL and Audio Library

I have a problem with different sound libraries...
I use Visual Studio.NET and C#
I have programmed a small simulator with ebedded sound and want to have a audio library which also has pause and volume control. So I tried SDL.NET and IrrKlang. Both are working, but I want to have the simulator as a "standalone" simulator so I have to embed the audio libraries to the simulator. I tried the testversion of smartassembly, but the SDL.NET library isn't fully integrated and with Irrklang, smartassembly said that there is nonmanaged code in the irrklang library and it aborts.
So I have multiple questions:
-Is there a simple audiolibrary which I can embed easily?
-Is there a, for example, .cs-file of an audio library so I don't have to embed a .dll?
-Can I change a .dll so I have mangaged code?
Thx
EDIT:
Errormessages with SmartAssembly:
SDL.NET:
Tao.NET.dll and SDLdotNET.dll can be embedded, but SDL.NET (The Core) is not a valid .COM-Library so it can't be embedded
IrrKlang:
-IrrLang.dll can be embedded, but after converting the program says that there is "non-managed" code in library so it can't be embedded.
What can I do??
Try nAudio: http://naudio.codeplex.com/, you will have full source code.
But that's a library like others.
Or maybe try to edit your question and add error messages you get
Ok, got it finally to work :)
I used the irrklang.dll but I had chosen the "Depencies Merging"-Option in {smartassembly} instead of the "Depencies EMBEDDING"-Option
Now it works perfectly :)
Thx Pierre that you wanted to help me :)
Wonderwhy

Programming an Event listener for files in a directory on Linux

On Ubuntu linux, when you watch a flash video, it gets saved temporarily in the /tmp as flv files while the video buffers. I use vlc to directly play these files.
Currently, I have scripted a shortcut that directly scans and opens the latest file in /tmp with vlc, when clicked.
But, I want to program a Java application that will continually monitor this /tmp directory for any new flv files, and open it in vlc automatically. I know I can use Runtime.exec() to open the VLC application with the flv files. But, I DO NOT want to run a while(true) loop (with sleep) to scan for files.
How can I make use of Event Handling (Java or any other language) on Linux to complete this task?
Edit:
I am also wondering if Java is the right way to approach this. As someone suggested below, Python and QT seem more appropriate.
For Python, use pyinotify: http://trac.dbzteam.org/pyinotify. It's a simple, standalone library; there's no need for an ugly Qt dependency for this.
Have you seen JNotify ? It's a Java library that uses OS-specific code to listen for filesystem events.
I wouldn't rule out polling the file system, however, unless you're dealing with a huge number of files/directories.
In Linux there something called FAM (File Alteration Monitor) which does a better job than the sleep/poll thing.
There's a python package for it as well: Python FAM
It is probably going to be a lot less to depend on than for example QT.
I would recommend Qt and Python.
I've used PyQt for a similar project before. Qt has a file system watcher that monitors directories and files for updates, which trigger events that you can catch and do stuff (like open vlc).
QFileSystemWatcher
If this is something you just want to always run in the background, Qt also has a feature that allows you to run your program in the System Tray. This is what I did, and just added a menu or two to make modifications.
QSystemTrayIcon
For Python, you can try this this, I find it simpler than pyinotify.

Getting duration of audio file C#

I'm trying to get the duration for an audio file in c#.
I got the following code to work on my local machine but when I deploy it to a windows server 2008 box it always returns a duration of 0 for .avi and .wav files.
WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();
IWMPMedia mediaInfo = wmp.newMedia(filePath);
return mediaInfo.durationString
I have windows media player 11 installed on the server.
Any help would be most appreciated
I don't have experience with "WindowsMediaPlayerClass", but I have used TagLibSharp extensively, which is what I try to use for such things - it supports a pretty broad set of formats and that makes it's API much more usable that the built-in support in .NET
http://developer.novell.com/wiki/index.php/TagLib_Sharp
Quite possibly simply using TagLibSharp will solve your problems.
(Note that taglibsharp is maintained by the banshee project, but is hosted # novell for apparently historical reasons. I don't know about the details, but that can make contacting the devs a little confusing)
To retrieve duration info, media file must be opened first.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd564790(v=vs.85).aspx#Y656
To retrieve the duration for files that are not in the user's library, you must wait for Windows Media Player to open the file; that is, the current OpenState must equal MediaOpen. You can verify this by handling the AxWindowsMediaPlayer._WMPOCXEvents_OpenStateChange event or by periodically checking the value of AxWindowsMediaPlayer.openState.
The link also has sample codes for C#.
If you don't like to play the video, you may use the IWMPMedia class:
http://johndyer.name/post/Retreiving-the-duration-of-a-WMV-in-C.aspx
My guess is that the media player isn't installed (it's not by default on server SKUs).
Did you try installing the desktop experience package?

Categories

Resources