Spaces:
Sleeping
Sleeping
Vanderson da Silva Quintino commited on
Commit ·
56d8c4f
1
Parent(s): 356397f
feat: 12 images, dynamic Ken Burns
Browse files
src/ClipForge.Infrastructure/Services/FfmpegService.cs
CHANGED
|
@@ -42,12 +42,11 @@ public class FfmpegService : IFfmpegService
|
|
| 42 |
{
|
| 43 |
_logger.LogInformation("Using Ken Burns effect with {Count} images", images.Count);
|
| 44 |
|
| 45 |
-
// Get audio duration to calculate time per image
|
| 46 |
var audioDuration = await GetMediaDurationAsync(audioPath, ct);
|
| 47 |
-
if (audioDuration <= 0) audioDuration =
|
| 48 |
-
var timePerImage = audioDuration / images.Count;
|
| 49 |
|
| 50 |
-
// Build FFmpeg command with Ken Burns effect (zoom + pan) on each image
|
| 51 |
var inputArgs = new List<string>();
|
| 52 |
var filterParts = new List<string>();
|
| 53 |
|
|
@@ -57,23 +56,15 @@ public class FfmpegService : IFfmpegService
|
|
| 57 |
|
| 58 |
var frames = (int)(timePerImage * 25);
|
| 59 |
|
| 60 |
-
// Ken Burns
|
| 61 |
-
string zoomEffect
|
| 62 |
-
if (i % 3 == 0)
|
| 63 |
{
|
| 64 |
-
// Zoom in
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
zoomEffect = $"zoompan=z='if(lte(zoom,1.0),1.4,max(1.001,zoom-0.002))':x='iw/2-(iw/zoom/2)':y='ih/4-(ih/zoom/4)':d={frames}:s=1080x1920:fps=25";
|
| 71 |
-
}
|
| 72 |
-
else
|
| 73 |
-
{
|
| 74 |
-
// Slow pan right
|
| 75 |
-
zoomEffect = $"zoompan=z='1.2':x='iw/4+((iw/2-iw/4)*on/{frames})':y='ih/2-(ih/zoom/2)':d={frames}:s=1080x1920:fps=25";
|
| 76 |
-
}
|
| 77 |
|
| 78 |
filterParts.Add($"[{i}:v]scale=1920:1920:force_original_aspect_ratio=increase,crop=1080:1920,{zoomEffect},setsar=1[v{i}]");
|
| 79 |
}
|
|
|
|
| 42 |
{
|
| 43 |
_logger.LogInformation("Using Ken Burns effect with {Count} images", images.Count);
|
| 44 |
|
| 45 |
+
// Get audio duration to calculate time per image (3-4 seconds each for fast pacing)
|
| 46 |
var audioDuration = await GetMediaDurationAsync(audioPath, ct);
|
| 47 |
+
if (audioDuration <= 0) audioDuration = 50;
|
| 48 |
+
var timePerImage = Math.Min(4.0, audioDuration / images.Count); // Max 4s per image
|
| 49 |
|
|
|
|
| 50 |
var inputArgs = new List<string>();
|
| 51 |
var filterParts = new List<string>();
|
| 52 |
|
|
|
|
| 56 |
|
| 57 |
var frames = (int)(timePerImage * 25);
|
| 58 |
|
| 59 |
+
// Varied Ken Burns effects for dynamic feel
|
| 60 |
+
string zoomEffect = (i % 5) switch
|
|
|
|
| 61 |
{
|
| 62 |
+
0 => $"zoompan=z='min(zoom+0.003,1.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d={frames}:s=1080x1920:fps=25", // Zoom in center
|
| 63 |
+
1 => $"zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.003))':x='iw/2-(iw/zoom/2)':y='ih/3-(ih/zoom/3)':d={frames}:s=1080x1920:fps=25", // Zoom out top
|
| 64 |
+
2 => $"zoompan=z='1.3':x='iw/4+((iw/2)*on/{frames})':y='ih/2-(ih/zoom/2)':d={frames}:s=1080x1920:fps=25", // Pan right
|
| 65 |
+
3 => $"zoompan=z='min(zoom+0.004,1.6)':x='iw/3-(iw/zoom/3)':y='ih/4-(ih/zoom/4)':d={frames}:s=1080x1920:fps=25", // Zoom in top-left
|
| 66 |
+
_ => $"zoompan=z='1.3':x='iw/2-(iw/zoom/2)+((iw/4)*sin(on/{frames}*3.14))':y='ih/2-(ih/zoom/2)':d={frames}:s=1080x1920:fps=25", // Sway
|
| 67 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
filterParts.Add($"[{i}:v]scale=1920:1920:force_original_aspect_ratio=increase,crop=1080:1920,{zoomEffect},setsar=1[v{i}]");
|
| 70 |
}
|
src/ClipForge.Infrastructure/Services/VideoAssemblyService.cs
CHANGED
|
@@ -69,12 +69,12 @@ public class VideoAssemblyService : IVideoAssemblyService
|
|
| 69 |
var backgroundClips = new List<string>();
|
| 70 |
|
| 71 |
// Use the first 2 most specific scene descriptions as search queries
|
| 72 |
-
var searchQueries = scenes.Take(
|
| 73 |
|
| 74 |
foreach (var query in searchQueries)
|
| 75 |
{
|
| 76 |
-
if (backgroundClips.Count >=
|
| 77 |
-
var neededPerQuery = Math.Max(
|
| 78 |
var clips = await _stockMedia.DownloadMultipleVideosAsync(query, neededPerQuery, tempDir, ct);
|
| 79 |
backgroundClips.AddRange(clips);
|
| 80 |
}
|
|
|
|
| 69 |
var backgroundClips = new List<string>();
|
| 70 |
|
| 71 |
// Use the first 2 most specific scene descriptions as search queries
|
| 72 |
+
var searchQueries = scenes.Take(4).ToList();
|
| 73 |
|
| 74 |
foreach (var query in searchQueries)
|
| 75 |
{
|
| 76 |
+
if (backgroundClips.Count >= 12) break;
|
| 77 |
+
var neededPerQuery = Math.Max(3, (12 - backgroundClips.Count));
|
| 78 |
var clips = await _stockMedia.DownloadMultipleVideosAsync(query, neededPerQuery, tempDir, ct);
|
| 79 |
backgroundClips.AddRange(clips);
|
| 80 |
}
|