mardi 15 avril 2014

.net - c#: fermeture VideoFileWriter lorsque le flux d'entrée est arrêté - Stack Overflow


I'm working on a c# application that open a communication socket on a predefined ipaddress and port, and receives frame from a another streaming application. When a frame is received it is added to VideoFileWriter object. When 1800 frames are received the writer is closed, so the file is writed on the disc. The code is:


private void StartColor_Click(object sender, RoutedEventArgs e)
{
int portaIP = int.Parse(Porta.Text);


if (!colorClient.IsConnected)
colorClient.Connect(ServerIp.Text, portaIP);
else
colorClient.Disconnect();

writer = new VideoFileWriter();
writer.Open("testVideoFileWriter.wmv", 320, 240, 15, VideoCodec.WMV2);
count = 1;
}

void client_ColorFrameReady(object sender, ColorFrameReadyEventArgs e)
{
this.Color.Source = e.ColorFrame.BitmapImage;
if (writer != null & count < 1800) // acquire a limitated number of frame
{
count++;
if(count%2==0)
writer.WriteVideoFrame(ResizeBitmap(BitmapImage2Bitmap(e.ColorFrame.BitmapImage), 320, 240));
}
else
{
writer.Close();
}
}

This code works good, but now I don't want to close the writer after 1800 frames are acquired: I want close the writer only if the input streaming is stopped. How can I perform this task?



I'm working on a c# application that open a communication socket on a predefined ipaddress and port, and receives frame from a another streaming application. When a frame is received it is added to VideoFileWriter object. When 1800 frames are received the writer is closed, so the file is writed on the disc. The code is:


private void StartColor_Click(object sender, RoutedEventArgs e)
{
int portaIP = int.Parse(Porta.Text);


if (!colorClient.IsConnected)
colorClient.Connect(ServerIp.Text, portaIP);
else
colorClient.Disconnect();

writer = new VideoFileWriter();
writer.Open("testVideoFileWriter.wmv", 320, 240, 15, VideoCodec.WMV2);
count = 1;
}

void client_ColorFrameReady(object sender, ColorFrameReadyEventArgs e)
{
this.Color.Source = e.ColorFrame.BitmapImage;
if (writer != null & count < 1800) // acquire a limitated number of frame
{
count++;
if(count%2==0)
writer.WriteVideoFrame(ResizeBitmap(BitmapImage2Bitmap(e.ColorFrame.BitmapImage), 320, 240));
}
else
{
writer.Close();
}
}

This code works good, but now I don't want to close the writer after 1800 frames are acquired: I want close the writer only if the input streaming is stopped. How can I perform this task?


Related Posts:

0 commentaires:

Enregistrer un commentaire