问题
I'm writing a program that will get video stream from IP Camera and display its video.
I request MJPEG stream, parse data and display frame by frame on WPF control for making video.
I have compared my program with the other programs, and I saw that my program displayed video less smooth than others although the FRAME RATE DISPLAY is same.
I displayed video on a WPF control by updating control's image sequentially.
Someone can tell me why my program is not smooth? and how to improve it.
UPDATE:
@LearnedfromMistake: There are 2 threads. Thread #1 will request, parse data from Camera stream and Append frames into Queue. Thread #2 will get frame from Queue and display it.
Here is my Pseudo code.
Thread #1
{
while(true)
{
JpegFrame = ReadAFrameFromStream();
QUEUE.Append(JpegFrame);
}
}
Thread #2
{
while(true)
{
JpegFrame = QUEUE.GetFrame();
WPFControl.UpdateImage(JpegFrame); //Making video here
}
}
回答1:
- while video frames are supposedly taken at regular time intervals, they might be encoded with different delays, transmission and buffering delays/lanetcies apply and eventually your receive rate is not regular, you need to compensate for this to restore smooth feed
- WPF control repaint overhead is greater compared to presentation through specialized multimedia APIs
The best would be facilitate multimedia streaming APIs where images are decoded into YUV frames and presented accurately according to attached time stamps.
来源:https://stackoverflow.com/questions/14538073/how-to-display-video-smoothly