Play video file from a memory stream - c#

Just curious to see if this is possible. I have a windows application that reads all the bytes from a .avi file situated on my pc and then stores it in a byte[]. So now I have the avi file in memory, and I want to load it into some sort of a video player control, directly from memory. I've tried using the wmplayer control, apparently this is not possible. I've read suggestion about using the DirectShow and VLC plugins, but I have no idea where to even start using those two and I haven't seen any sample code of this being down. Anybody have any ideas to elaborate on the mentioned plugins, or have a different approach to it?

For DirectShow, an in-memory source filter may be required. I am not aware of such a filter being available, but one can be based on Async Filter Sample from DirectShow samples. This is in C++ though.
For .NET, DirectShow.NET library can be used. A sample GSSF filter there may be a good start for an in-memory source filter implementation. This library also provides COM Interop for DirectShow that could be used to build a test player application that instantiates this filter.

Related

How to play a video from Stream or MemoryStream using WPF-Mediakit?

For my wpf application i need to play video files saved in a MemoryStream. Is it possibile to achieve this by using WPF-mediakit?
Since MediaElement does not support playing a video directly from memory I have been using the vlc.dotnet library to achieve this. However I am looking for an alternative. I have found some posts that say WPF-Mediakit can play videos from a MemoryStream, but i was unable to find the described functionality in the source code or documentation.
If anyone could point me in the right direction towards playing video saved in memory in WPF-Mediakit, that would be great.
No, WPF-MediaKit cannot play video from memory stream. Just save it to a temporary file (e.g. use System.IO.Path.GetTempFileName()) and play the video from file.
WPF-MediaKit uses DirectShowLib, which is just a wrapper around MS Windows DirectShow interface. And that is unmanaged code. So:
You cannot use C# MemoryStream, i.e. managed memory, for an unmanaged code. You have to use unmanaged memory.
DirectShow is based on filters. AFAIK it has no input filter, which can play from memory. But you can code one, e.g. see https://stackoverflow.com/a/24478030/254109
Note: You may also some FFmpeg based solutions, see https://github.com/Sascha-L/WPF-MediaKit/wiki/Similar-Projects e.g. FFME.

DirectShow .Net camera capture encode output?

recently i have started workin on project of my own which is capturing a camera output using DirectShow .Net. There are few problems that i don't know how ot solve
1) How can i encode the captured stream into H.264 format.I understand i should some how add filter in the filter graph. But i wasn't able to find where and how . Also i was not able to find if there is standart H.264 filter or should i download it form some where? If i need to download it can it just be a dll to wich i add reference or should it be installer?
2) Is there a way to save the captured output into a memory object, some kind of stream or it can only be written to file?
Best Regards,
Iordan
You're can use commercial software from VisioForge or Viscomsoft.
AForge potencial problem - no audio during capture, only video. Also output formats is a very limited. But - it's free and open source, if you're have any DirectShow experiense you can add audio support.
You will need to use something like FFMpeg or Handbrake. Check out http://vidcoder.codeplex.com/.
AForge also has some video editing abilities and you can also pass filters to it. There are also several FFMpeg C# wrappers you could use such as https://github.com/crazyender/FFMPEG.net
You should use AForge.net. All of the hard work is done for you already. Use VideoFileWriter http://www.aforgenet.com/framework/docs/html/4ee1742c-44d3-b250-d6aa-90cd2d606611.htm. I appears that the AForge framework uses FFMpeg under the hood as well (See AForge.Video.FFMPEG namespace). You just create a writer and pass it the bitmap/frame writer.WriteVideoFrame(bitmap);
You should fully investigate the video abstractions in AForge. You could save yourself considerable amounts of time.
Example: http://www.aforgenet.com/framework/samples/video.html
1) Yes, You should download encoder filter library. Most of decoders are supplied with free. But encoder is not. If you don't want to pay, you have to find open source Encoder.
And To use at the graphedit program, you should do dll register with that dll file. Or the installer program do this instead. And you also need to check container type like mp4, mkv... In other words you need mux filter to save that in a file. I think someone will link available urls. Sorry I don't have urls now.
2)What is that the means of capture? Is that Movie? or Image?
In case of Image, There are many sample projects and SampleGrabbers. You can save it to both of a file and memory.
In case of Movie, I'm sure your pc memory is not enougth to them with out encoding. Make memory stream and pass it to capture manager.
You can also make a filter in order to customize filter to your needs. All of information are included in Windows SDK samples.

Filling and playing audio buffer in C# (.NET 4.0)

Where I can found something suitable (library) for .NET 4.0 (C#) capable for following features:
+ Reading mp3/wav samples with direct access to samplebuffer of loaded samples? (for example I want to load mp3 sample and programatically add reverb, chorus, and more custom effects implemented by me)
+ Playing directly audio buffers (arrays of floats)
+ Saving audio buffers to disk as mp3 or wav
Some time ago i found ASIO for .NET and this only works with .NET 3.5, is there something for .NET 4.0? Thank's a lot for your help.
ASIO for .NET won't help you in the cracking of mp3 or wav files. The most modern API in Windows for doing this is Microsoft Media Foundation. These are all COM APIs though, so you're either going to be doing (perhaps painful) COM interop from .NET or (easier) writing a C++/CLI wrapper. If you go the C++/CLI wrapper, you will need to be aware of performance issues (especially with how critical latency is to audio programming).
I'm skeptical that you will get the audio latency you need when programming in .NET. A good audio driver (like ASIO) will get you down to <3ms of latency. So if you are targetting "live audio", you will need to be generating audio buffers quicker than that (unless you are fine with longer latencies). To put it this way, the "time intervals" that the Windows APIs deal with are in 100 nanosecond intervals :).
You likely don't want to have to crack the files yourself. It becomes tedious as it's not only just mp3 and wav. You also have to be aware of how the wav is formatted as well (to account for different bit rates, number of channels, etc.). Using Media Foundation, it will automatically load the write decoder for you, you just give it the file path. Check out this tutorial that shows opening an existing WAV file and writing a new WAV file. I just recently went down this path for a drum sequencer I'm creating, and it's not very painful at all (if you're familiar with COM programming).
The central component in MF that makes this possible is the MFSourceReader.
If you're wanting to play the audio after you modify it, you can look at the sample "RenderExclusiveEventDriven" in the Windows SDK (under "audio" I believe). That's what I did for the drum sequencer as well. Latency won't be an issue and you're just dealing with byte arrays, so manipulating the raw data becomes very easy. Though at this point, you can probably stick with the ASIO .NET route and just use that to play the raw data you get from MFSourceReader.
I don't think there are .NET wrappers around Media Foundation yet (though if somebody has done that work already, feel free to post here as it would be awesome to know).

How do I split an mp3 file into smaller files?

I want to make a program that takes an MP3 file and breaks it into many smaller mp3 files based on 1-2 seconds of no sound (silence).
What is the easiest way to do this in c#?
Bass library. Bass has everything you need. It can access, record and edit media streams like mp3s, allowing you to sample the volume at different time points. It has a .net api, so you can use it in c#. Unfortunately it does cost money if you are using it for a commercial application, but they do provide a free non-commercial license.
Sox is a command-line tool which has an option to split an mp3 on n seconds of silence. You could always use the system command to call sox from c#.
Other related links.
Ripping a CD to mp3 in C# - third party component or api out there?
Audio Libraries for MP3 editing
How do I merge/join mp3 files with c#
This code shows a way to make a CD
ripper in C#. There are APIs from some
vendors that allow reading audio CD
tracks but it is also possible to do
it using APIs that allow low level
access to CD drives such as ASPI from
Adaptec or IOCTL control codes. The
latter method is used in this case,
because there is no need to install
any third party software, it is
completely covered by Win32 API
functions.
http://www.codeproject.com/KB/cs/csharpripper.aspx
Splitting the MP3 stream will be difficult to do with any degree of precision. The compressed MP3 data exists as sequential chunks of audio data comprised of many samples. The easiest way to perform this would be to decode the stream either progressively or in its entirety, perform your manipulation, then re-encode it (which as I understand is how most jukebox software does it)
Having a solid knowledge of the file's binary format would be a good place to start. That done, you'll know what silence looks like in the file. You may have to define exactly what silence is. Presuming that, like most audio, it started from an analog source, there's almost certainly some noise buried in the "silence". What will your tolerance for ambient/background noise be?
Once you know what you're looking for, just scan through the file, looking for "it".
Simple ...
A program to do this already exists:
http://mp3splt.sourceforge.net/mp3splt_page/home.php

How can I emulate a video capture device and provide dynamic video content?

I would like to emulate video input from a webcam for testing purposes.
So I need to be able to emulate a software video capture device in Windows and be able to dynamically generate its output.
How can I achieve this?
I would prefer a solution in C# or C++.
You can use a Virtual Webcam (old link, but there are others) it will take a video/images file and will display it in a webcam device. Your system will think that its a normal device.
Then you will need to create something that will generate the video/images, if you need static image then its pretty easy to generate a bmp.
Old (no selected answer) question.... actually probably one of the oldest I've ever seen... but I came across this looking for an answer myself, I remembered the day when "Virtual Webcam" still existed (now just a chinese ad site).
Fear not! There are new sources to solve your decade long quest:
First of all, checkout OBS, open source does a LOT with video streams:
https://obsproject.com/
Second, checkout this virtual webcam plugin for it. Does exactly what you're talking about, and does use #qbeuek's suggestion of DirectDraw:
https://obsproject.com/forum/resources/obs-virtualcam.949/
It is written in C++, so grabbing the bits you need and rewriting to C# is left as an exercise to the reader, but the capability is there.
As far as I know, there is a set of COM interfaces that govern the recording and playback of audio and video in Windows. It used to be called DirectShow, but maybe in the meantime the name has been changed. Those interfaces are used to construct a graph of audio and video filters, to encode / decode the data stream.
The way to go:
- read about the Microsoft DirectShow API,
- implement a COM object that implements the video source interface,

Categories

Resources