diff --git a/AiServer.ServiceInterface/Generation/ComfyProvider.cs b/AiServer.ServiceInterface/Generation/ComfyProvider.cs index 6162cdb..c24d9f4 100644 --- a/AiServer.ServiceInterface/Generation/ComfyProvider.cs +++ b/AiServer.ServiceInterface/Generation/ComfyProvider.cs @@ -226,13 +226,13 @@ public async Task TransformMediaAsync(MediaProvider provider, M { var scaleWidth = args.ScaleWidth ?? -1; var scaleHeight = args.ScaleHeight ?? -1; - filterComplex.Add($"scale={scaleWidth}:{scaleHeight}"); + filterComplex.Add($"[0:v]scale={scaleWidth}:{scaleHeight}"); } // Handle cropping if (args is { CropX: not null, CropY: not null, CropWidth: not null, CropHeight: not null }) { - filterComplex.Add($"crop={args.CropWidth}:{args.CropHeight}:{args.CropX}:{args.CropY}"); + filterComplex.Add($"[0:v]crop={args.CropWidth}:{args.CropHeight}:{args.CropX}:{args.CropY}"); } if (args is { WatermarkInput: not null, WatermarkPosition: not null }) diff --git a/AiServer.ServiceInterface/MediaTransform/CreateMediaTransformCommand.cs b/AiServer.ServiceInterface/MediaTransform/CreateMediaTransformCommand.cs index b1d01bf..ee1669f 100644 --- a/AiServer.ServiceInterface/MediaTransform/CreateMediaTransformCommand.cs +++ b/AiServer.ServiceInterface/MediaTransform/CreateMediaTransformCommand.cs @@ -62,7 +62,7 @@ protected override async Task RunAsync(CreateMediaTransform req log.LogInformation("Finished {TaskType} generation request {RefId} with {Provider} in {DurationMs}ms", request.Request.TaskType, request.RefId, apiProviderInstance.Name, durationMs); if (response.Outputs != null && response.Outputs.Count > 0) - await DownloadOutputsAsync(transformProvider, apiProviderInstance, response.Outputs, keyId); + await DownloadOutputsAsync(transformProvider, apiProviderInstance, response.Outputs, keyId, token); ResponseStatus? error = null; var outputs = new List(); @@ -308,10 +308,10 @@ private IImageFormat GetImageFormat(ImageOutputFormat format) async Task DownloadOutputsAsync(IMediaTransformProvider aiProvider, MediaProvider apiProvider, - IEnumerable outputs, string keyId) + IEnumerable outputs, string keyId, CancellationToken token = default) { var now = DateTime.UtcNow; - var downloadTasks = outputs.Select(x => DownloadOutputAsync(aiProvider, apiProvider, x, now, keyId)); + var downloadTasks = outputs.Select(x => DownloadOutputAsync(aiProvider, apiProvider, x, now, keyId, token)); await Task.WhenAll(downloadTasks); } @@ -331,12 +331,12 @@ async Task SaveTransformResultAsync(TransformResult response, Stream data, strin async Task DownloadOutputAsync(IMediaTransformProvider aiProvider, MediaProvider apiProvider, - TransformFileOutput output, DateTime now, string keyId) + TransformFileOutput output, DateTime now, string keyId, CancellationToken token = default) { using var client = httpFactory.CreateClient(); try { - var response = await aiProvider.DownloadOutputAsync(apiProvider, output); + var response = await aiProvider.DownloadOutputAsync(apiProvider, output, token); response.EnsureSuccessStatusCode(); // Grab file extension from response @@ -360,13 +360,13 @@ async Task DownloadOutputAsync(IMediaTransformProvider aiProvider, _ => "mp4" }; - var imageBytes = await response.Content.ReadAsByteArrayAsync(); + var imageBytes = await response.Content.ReadAsByteArrayAsync(token); var sha256 = imageBytes.ComputeSha256(); output.FileName = $"{sha256}.{ext}"; var relativePath = $"{now:yyyy}/{now:MM}/{now:dd}/{keyId}/{output.FileName}"; var path = appConfig.ArtifactsPath.CombineWith(relativePath); Path.GetDirectoryName(path).AssertDir(); - await File.WriteAllBytesAsync(path, imageBytes); + await File.WriteAllBytesAsync(path, imageBytes, token); output.Url = $"/artifacts/{relativePath}"; } catch (Exception e)