Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.
by AlexVas » Sat Aug 17, 2019 1:51 pm
Hello!
I connected AForge videoplayer to my WPF project. Than I use for test -
IVideoSource videoSource = new FileVideoSource(@"test200.avi"); videoSourcePlayer.VideoSource = videoSource; videoSourcePlayer.Start();
test.avi plays. ok.
Now how can I connect my bitmap stream (my project generate bitmap images) to play via player? As I understand I need to connect it to videosourse? But how?
-
AlexVas
-
- Posts: 5
- Joined: Sat Aug 17, 2019 1:46 pm
by andrew.kirillov » Sun Aug 18, 2019 9:25 am
Hello, AlexVas wrote:Now how can I connect my bitmap stream (my project generate bitmap images) to play via player?
Not sure what is your bitmap stream is. In general, you need to write your own class implementing IVideoSource interface, which provides images from your video source. Have a look at the source code of the framework to see how other video source classes do this.
-

andrew.kirillov
- Site Admin, AForge.NET Developer
-
- Posts: 3453
- Joined: Fri Jan 23, 2009 9:12 am
- Location: UK
by AlexVas » Sun Aug 18, 2019 9:41 am
andrew.kirillov wrote:Hello, AlexVas wrote:Now how can I connect my bitmap stream (my project generate bitmap images) to play via player?
Not sure what is your bitmap stream is. In general, you need to write your own class implementing IVideoSource interface, which provides images from your video source. Have a look at the source code of the framework to see how other video source classes do this.
Stream I mean - sequence of bitmap frames. New class you mean something like class MyClass:IVideosource { .. } ? About source code - could you give me names of files where I can see this? I tryed to find some but I'm afraid that I missed something..
-
AlexVas
-
- Posts: 5
- Joined: Sat Aug 17, 2019 1:46 pm
by andrew.kirillov » Sun Aug 18, 2019 3:31 pm
-

andrew.kirillov
- Site Admin, AForge.NET Developer
-
- Posts: 3453
- Joined: Fri Jan 23, 2009 9:12 am
- Location: UK
by AlexVas » Sat Aug 24, 2019 11:23 am
Hello Andrew
Thanks for links. I have built according it but have some problems yet -
а) I can see frames count but in player window I see nothing ("Connecting..") or, if I restart (run Player again) - one frame(last maybe..don't know). I think it is something in my IVideoSource realisation... but what? b) Is it possible (or how) to set frame rate for player? For example I make stream of bitmaps from my file where frames just a byte arrays. Without any marks.
1. Here I start Player -
AF_Stream stream_m = new AF_Stream(); stream_m.StartMe(context.PreviewVideoSource.QueueOut); videoSourcePlayer.VideoSource = stream_m; videoSourcePlayer.Start();
2. In xaml I have this -
<!--AFORGE--> <WindowsFormsHost Margin="5,5,5,201" Name="windowFormsHost" Panel.ZIndex="0" Visibility="Hidden"> <aforge:VideoSourcePlayer x:Name="videoSourcePlayer" Height="600" Margin="12,30,0,0" Width="800"> </aforge:VideoSourcePlayer> </WindowsFormsHost>
3. This is my class -
public class AF_Stream : IVideoSource { private ConcurrentQueue<VideoFrame> _framesQ = new ConcurrentQueue<VideoFrame>(); //queue for incoming frames (bitmaps)
private Thread thread = null; public long BytesReceived { get { throw new NotImplementedException(); } }
public int FramesReceived { get { throw new NotImplementedException(); } }
public bool IsRunning { get { if (thread != null) { // check thread status if (thread.Join(0) == false) return true;
// the thread is not running, free resources Free(); } return false; } }
private void Free() { thread = null; }
public string Source { get { throw new NotImplementedException(); } }
public event NewFrameEventHandler NewFrame; public event PlayingFinishedEventHandler PlayingFinished; public event VideoSourceErrorEventHandler VideoSourceError; VideoFrame videoFrame; Bitmap bitmapFrame; public static int af_Frame_Count;
public void SignalToStop() { throw new NotImplementedException(); } public void Start() {
} public void StartMe(ConcurrentQueue<VideoFrame> e) //I call this method to start { _framesQ = e; if (!IsRunning) { // check source if ((e == null) || (e.IsEmpty)) {
} else
{ // create and start new thread thread = new Thread(new ThreadStart(WorkerThread)); //thread.Name = source; // mainly for debugging thread.Start(); } } }
private void WorkerThread() {
while (_framesQ.TryDequeue(out videoFrame)) { if (NewFrame != null) { af_Frame_Count++; bitmapFrame = videoFrame.Frame; NewFrame(this, new AForge.Video.NewFrameEventArgs(bitmapFrame)); bitmapFrame.Dispose(); bitmapFrame = null; } }
}
public void Stop() { throw new NotImplementedException(); }
public void WaitForStop() { throw new NotImplementedException(); } private void AF_new_Frame_Event(object sender, Shared.Video.NewFrameEventArgs e) { Console.WriteLine("NEW FRAME"); } }
-
AlexVas
-
- Posts: 5
- Joined: Sat Aug 17, 2019 1:46 pm
by andrew.kirillov » Sat Aug 24, 2019 12:15 pm
Hello, AlexVas wrote:I think it is something in my IVideoSource realisation... but what?
Don't know. Debug your code. AlexVas wrote:b) Is it possible (or how) to set frame rate for player?
No. Player only displays video frames coming from some video source. It is your IVideoSource implementation who needs to manage frame rate.
-

andrew.kirillov
- Site Admin, AForge.NET Developer
-
- Posts: 3453
- Joined: Fri Jan 23, 2009 9:12 am
- Location: UK
by AlexVas » Sat Aug 24, 2019 2:58 pm
Ok.
Than -
I'm I understanfd right that IVideoSource public event NewFrameEventHandler NewFrame needs to send frame to Player? So when I release function that feed NewFrame with new frame from my source, that frame comes to player? (after of course I implement calls videoSourcePlayer.VideoSource = stream_m; videoSourcePlayer.Start();) ?
-
AlexVas
-
- Posts: 5
- Joined: Sat Aug 17, 2019 1:46 pm
by andrew.kirillov » Sun Aug 25, 2019 7:21 am
IVideoSource fires NewFrame event when it has new video frame. Player is subscribed to that event, so it gets notification and does its job. Do you know C#, right?
-

andrew.kirillov
- Site Admin, AForge.NET Developer
-
- Posts: 3453
- Joined: Fri Jan 23, 2009 9:12 am
- Location: UK
by AlexVas » Sun Aug 25, 2019 2:50 pm
=) I know c# but not so good( That's why I'm asking here.
Ok. Than next question please - regarding samples that I found in your links when I pass frame to NewFrame I have to use this construction -
public event NewFrameEventHandler NewFrame;
private void WorkerThread() { if (NewFrame != null) { af_Frame_Count++; bitmapFrame = videoFrame.Frame; NewFrame(this, new AForge.Video.NewFrameEventArgs(bitmapFrame)); bitmapFrame.Dispose(); bitmapFrame = null; } }
but I don't understand where NewFrame became not null? Because if I just start this code from begining - NewFrame always null. Could you help with it?
-
AlexVas
-
- Posts: 5
- Joined: Sat Aug 17, 2019 1:46 pm
Return to AForge.NET Framework
|

|