Created
April 24, 2023 11:35
-
-
Save davepermen/db178f1dba32c2a6628a067baf28e2ed to your computer and use it in GitHub Desktop.
This file contains 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