dimanche 28 juin 2015

How can i convert and compress in real time batch of images to mp4 video file?

In my directory on the hard disk i have many images: screenshot000001.bmp , screenshot000002.bmp....screenshot001200.bmp

I want to do two things:

  1. For testing using the CMD and to compress and convert the images to mp4 video file.

  2. In my program in real time while my program take the screenshots and save them to the hard disk to compress them and build the mp4 video file in real time.

For the first part i tried to type in cmd :

ffmpeg -f image2 -i screenshot%d.bmp -vcodec libx264 -b 800k video.avi

But what i got is two errors:

[image2 @ 0000000004766380] Could find no file with path 'screenshot%d.bmp' and index in the range 0-4 screenshot%d.bmp: No such file or directory

I copied the ffmpeg.exe to the directory where the images are in. E:\screenshots

For the second part this how i'm taking the screenshots in real time:

A button click event that start a timer:

private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

Then in the tick event:

    ScreenShot shot = new ScreenShot();
    public static int counter = 0;
    private void timer1_Tick(object sender, EventArgs e)
    {
        counter++;
        shot.GetScreenShot(@"e:\screenshots\", "screenshot");
        if (counter == 1200)
        {
            timer1.Stop();
        }
    }

This line shot.GetScreenShot(@"e:\screenshots\", "screenshot"); save the screenshots to the hard disk. Here after each screenshot save i want to compress and build the mp4 video file in real time.

Aucun commentaire:

Enregistrer un commentaire