Click here to Skip to main content
13,199,026 members (43,494 online)
Rate this:
 
Please Sign up or sign in to vote.
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);
            }
        }
Posted 21-May-14 2:58am
Updated 21-May-14 3:02am
v2
Comments
RyanDev 21-May-14 9:27am
   
Which line of code and what is the exact error?
Pavan Kumar 21-May-14 9:58am
   
while writing the video frame, writer.WriteVideoFrame((Bitmap)pbVideo.Image);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171020.1 | Last Updated 21 May 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100