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() >---------------
}
}
|
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