Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davepermen/db178f1dba32c2a6628a067baf28e2ed to your computer and use it in GitHub Desktop.
Save davepermen/db178f1dba32c2a6628a067baf28e2ed to your computer and use it in GitHub Desktop.
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