简体   繁体   English

使用 C# 播放视频中的特定帧

[英]Play specific frames in video using C#

I am trying to play part of the video(in this example from frame no 1 to frame 299) in c#.我正在尝试在 c# 中播放部分视频(在此示例中,从第 1 帧到第 299 帧)。 I tried with below code, it works perfectly for single frame but does not display anything after addition of loop.我尝试使用下面的代码,它适用于单帧但在添加循环后不显示任何内容。 The code does not throw any errors.该代码不会引发任何错误。

        private void button2_Click(object sender, EventArgs e)
        {
            // Open video file
            VideoFileReader reader = new VideoFileReader();
            reader.Open(@"c:\Users\Replay.avi");

            // Read frame no. 1 to 300 and display in picturebox
            for (int j = 1; j < 300; j++)
             {

                Bitmap replay_frame = reader.ReadVideoFrame();
                pictureBox1.Image = replay_frame;
            }
            reader.Close();

        }

Whats wrong with the above code?上面的代码有什么问题?

I know this is very old but I needed the same thing and found this.我知道这已经很老了,但我需要同样的东西并找到了这个。 All you are missing is pictureBox1.Refresh();你所缺少的只是 pictureBox1.Refresh(); inside your loop.在你的循环里面。 The new image doesn't show up until the picture box is refreshed刷新图片框后,新图像才会显示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM