Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Thumbnail Image erstellen aus einem Video in Asp Core

28.07.2021 (👁11163)

Thumbnail Image erstellen aus einem Video

In diesem Artikel wird gezeigt, wie man ganz einfach Thumbnails aus einem Video erstellen kann.

Hierzu wird das kostenlose Paket FFMpeg im C# Projekt installiert und dann als Process die ffmpeg.exe Programm ausgeführt.

Die Anwendung findet in Asp Core .Net5, MVC statt und kann unter Windows Servern oder Linux als Cross Platform laufen.

Aus den Video Dateien erstellen

Die Video Dateien müssen sich auf dem Webserver befinden. Hier .mp4 Dateien im User Verzeichnis

Code Asp Core

 .Net5 MVC in _classes public shared

using System.Diagnostics;   //ProcessStartInfo

 

public static class Video_Methods

{

    public static void Video_create_Thumbnail(string Video_Path, string output_Image_Path, int new_Width, string sPath_FFMpeg)

    {

        //---------------< Video_create_Thumbnail() >---------------

        string sPath_FFMpegDir = @"D:\xx\bin\FFMpeg\";

 

        string sInputFile = @"D:\xx\Videos\Video_2618_0.mp4";

        string sOutputFile = @"D:\xx\Images\thumb_2618_0.jpg";

        var startInfo = new ProcessStartInfo

        {           

            FileName = sPath_FFMpegDir + $"ffmpeg.exe",

            Arguments = $"-i " + sInputFile + " -an -vf scale=200x112 " + sOutputFile + " -ss 00:00:00 -vframes 1",

            CreateNoWindow=true,

            UseShellExecute=false,

            WorkingDirectory=sPath_FFMpegDir

        };

 

        using (var process=new Process { StartInfo=startInfo})

        {

            process.Start();

            process.WaitForExit();

        }

        //---------------</ Video_create_Thumbnail() >---------------

    }

 

}

 

The command line parameters:

  • For video files,
    • -ss 5 means “seek to the position five seconds into the media file”.
    • -an prevents audio streams from being handled in any way
  • -i specifies the input file
  • -vframes 1 gets one frame from the input file
  • -s specifies the output size
  • -y to confirm overwriting an existing file
  • The last parameter is the output file; the extension of the thumbnail file tells FFmpeg that we want the file in PNG format.

 

 

Alternativ System.Diagnostics.Process p = new System.Diagnostics.Process ( );

p.StartInfo.FileName = "ffmpeg.exe";

p.StartInfo.Arguments = "-i input.avi -b 64k output.flv";

p.Start ( );


Installation von FFMpeg

Bei beiden Vorgängen muss man FFMpeg downloaden und als dll und exe im Asp Core .Net5 oder MVC speichern:

Neueste FFMpeg Dateien

Download und in Server installieren

https://github.com/BtbN/FFmpeg-Builds/releases

 

 

FFMpeg in Asp Core speichern

Ich habe die FFMpeg Dateien in den Ausgabe /bin Pfad gelegt neben Debug und Public