Forked from davepermen/Return Embedded Thumbnail from Video.cs
Created
April 24, 2023 14:24
-
-
Save Buildstarted/74f9b8b595bc414866f6e81bb7ba19df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net.Mime; | |
using Xabe.FFmpeg; | |
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
FFmpeg.SetExecutablesPath(@"C:\Temp\Tools\ffmpeg\bin"); | |
app.MapGet("/thumbnail/{filename}", async (string filename, HttpContext context) => { | |
var i = await FFmpeg.GetMediaInfo($@"C:\Temp\files\{filename}"); | |
var ii = i.Streams.Where(i => i.Codec.EndsWith("jpg") || i.Codec.EndsWith("jpeg")).First(); | |
List<byte> data = new(); | |
var conversion = FFmpeg.Conversions.New() | |
.AddStream(ii) | |
.PipeOutput(PipeDescriptor.stdout) | |
.SetOutputFormat(Format.mjpeg); | |
conversion.OnVideoDataReceived += async (_, args) => await context.Response.BodyWriter.WriteAsync(args.Data); | |
await conversion.Start(); | |
return Results.Ok(); | |
}).Produces(StatusCodes.Status200OK, contentType: MediaTypeNames.Image.Jpeg); | |
app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment