Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Extract bitmaps from MP4 stream

Recently, i searched alot on the internet for a good C# lib to Extract bitmaps from MP4 videos, and i found somethings that were similar to this code, but not to MP4:

        VideoStream stream = aviManager.GetVideoStream(@"C:\Users\User\Desktop\video.mp4");
        //the video.mp4 is usually .avi or .mpeg
        for (int n = 0; n < stream.CountFrames; n++)
        {
            Bitmap bmp = new Bitmap(stream.GetBitmap(Position));
            bmp.Save(@"C:\Users\Nehoray\Desktop\Something.png");
            bmp.Dispose;
        }

Can anyone give me a library with an easy code like this, just for MP4? :)

like image 750
Omer litchy Avatar asked Oct 07 '12 20:10

Omer litchy


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


2 Answers

I have used Expression Encoder SDK for a similar task. They declare that MP4 is supported. Take a look at the AudioVideoFile.GetThumbnail method.

like image 95
Sergey Rybalkin Avatar answered Sep 21 '22 14:09

Sergey Rybalkin


For avi I used to write something like this:

string filename = "file.avi";
string storagepath = @"temp\";
static int counter = 0;
MediaDetClass memde;

private void button1_Click(object sender, EventArgs e)
{
    if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        // Create the subfolder
        System.IO.Directory.CreateDirectory("temp");

    // Some properities
        counter = 0;
        memde = new MediaDetClass();
        Image img;
        memde.Filename = openFileDialog1.FileName;
        memde.CurrentStream = 0;
        int len = (int)memde.StreamLength;
        float percent = 0.002f;//how far do u want for a single step

        for (float i = 0.0f; i < len; i = i + (float)(percent * len))
        {

            counter++;
            string fbitname = storagepath + counter.ToString();
            memde.WriteBitmapBits(i, 850, 480, fbitname + ".bmp");
            //img = Image.FromFile(fbitname + ".bmp");
            //img.Save(fbitname + ".bmp", ImageFormat.Bmp);
            //img.Dispose();
            //System.IO.File.Delete(i + fbitname + ".bmp");
        }
}

Library used was: Interop.DexterLib.dll, I'm not sure now if you can find it in C# resources. I can share link if you want.


GitHub Repo just download RAW file ( There is in C# folder).

like image 40
deadfish Avatar answered Sep 19 '22 14:09

deadfish