radek-k / FFMediaToolkit

FFMediaToolkit is a cross-platform video decoder/encoder library for .NET that uses FFmpeg native libraries. It supports video frames extraction, reading stream metadata and creating videos from bitmaps in any format supported by FFmpeg.
MIT License
352 stars 56 forks source link

Cannot find a container format for the ".mp4" file extension. #91

Closed xinchencai closed 2 years ago

xinchencai commented 3 years ago

I got a System.NotSupportedException thrown when trying to run the following function:

    using FFMediaToolkit;
    using FFMediaToolkit.Encoding;
    using System.Drawing.Imaging;
    using FFMediaToolkit.Graphics;

    private static void image2video(string[] files, int width, int height, string output)
    {
        FFmpegLoader.FFmpegPath = path;

        var settings = new VideoEncoderSettings(width: width, height: height, framerate: 25, codec: VideoCodec.H264);
        settings.EncoderPreset = EncoderPreset.Fast;
        settings.CRF = 17;
        using (var file = MediaBuilder.CreateContainer(output + "video.mp4").WithVideo(settings).Create())
        {
            foreach (var inputFile in files)
            {
                var binInputFile = File.ReadAllBytes(inputFile);
                var memInput = new MemoryStream(binInputFile);
                var bitmap = Bitmap.FromStream(memInput) as Bitmap;
                var rect = new System.Drawing.Rectangle(System.Drawing.Point.Empty, bitmap.Size);
                var bitLock = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                ImageData bitmapData = ImageData.FromPointer(bitLock.Scan0, ImagePixelFormat.Bgr24, bitmap.Size);
                file.Video.AddFrame(bitmapData); // Encode the frame
                bitmap.UnlockBits(bitLock);
            }
            file.Dispose();
        }
    }

Here's the error that I got

    Exception thrown: 'System.NotSupportedException' in FFMediaToolkit.dll
    Exception thrown: 'System.NotSupportedException' in mscorlib.dll
    An unhandled exception of type 'System.NotSupportedException' occurred in mscorlib.dll
    Cannot find a container format for the ".mp4" file extension.

Can anybody tell where this error is coming from?