视频文件尚未打开 [英] A video file was not opened yet

查看:217
本文介绍了视频文件尚未打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在通过ffmpeg VideoFileWriter类录制视频时,我收到的错误如视频文件尚未打开



这里是我的代码:

While recording video by ffmpeg VideoFileWriter class, i am getting error like 'A video file was not opened yet'

here is my code :

private void butStart_Click(object sender, EventArgs e)
{
    try
    {
        FinalVideo = new VideoCaptureDevice(monikerString);
        FinalVideo.VideoResolution = FinalVideo.VideoCapabilities[videoCapabilityNo];
        FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
        FinalVideo.Start();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Start Video", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

private void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    try
    {
        pbVideo.Image = (Bitmap)eventArgs.Frame.Clone();
        writer.WriteVideoFrame((Bitmap)pbVideo.Image);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "New Frame", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

private void butRecord_Click(object sender, EventArgs e)
{
    try
    {
        path = Path.GetDirectoryName(Application.ExecutablePath) + DateTime.Now.ToString("dd-MM-yyyy")+"\\";
        if (Directory.Exists(path) == false)
        {
            Directory.CreateDirectory(path);
        }

        writer.Open(path + "VID" + DateTime.Now.ToString("HHmmss") + videoFormat, width, height, frameRate, VideoCodec.MPEG4, bitRate);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

private void butStop_Click(object sender, EventArgs e)
{
    try
    {
        if (FinalVideo == null)
            return;
        if (FinalVideo.IsRunning)
            writer.Close();
        else
        {
            this.FinalVideo.Stop();
            FinalVideo = null;
            pbVideo.Image = null;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Stop Video", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

推荐答案

这篇关于视频文件尚未打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆