6

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? :)

Omer litchy
  • 91
  • 1
  • 1
  • 6
  • is it possible first convert from mp4 to avi? – deadfish Oct 07 '12 at 20:24
  • @deadfish - if you just need to play mp4 video as an avi file and dont need to _actually_ convert the container format, you should be able to just rename the file. – StingyJack Sep 28 '17 at 13:00

3 Answers3

3

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

Sergey Rybalkin
  • 3,004
  • 22
  • 26
1

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).

deadfish
  • 11,996
  • 12
  • 87
  • 136
  • Thanks, actually it helped me for the avi files (i had a problem with the current code).. I only have 1 problem - im rendering on MP4, because I'm uploading videos to youtube, and AVI is too heavy.. I'll be glad if you'll share a link :) – Omer litchy Oct 08 '12 at 01:56
0

For anyone else running across this post, checkout this answer: Get thumbnail image of video file in C#

One of the posts mention a NuGet package called NReco.VideoConverter. This lets you create thumbnails quite easily from an MP4 file:

var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
ffMpeg.GetVideoThumbnail(pathToVideoFile, pathToNewThumbnail, locationInSeconds);
Community
  • 1
  • 1
lehn0058
  • 19,977
  • 15
  • 69
  • 109