jbilcke-hf HF staff commited on
Commit
565de77
·
1 Parent(s): 8aa24de

experimenting

Browse files
src/bug-in-bun/aitube_ffmpeg/overlay/imageToVideoBase64.ts CHANGED
@@ -47,17 +47,6 @@ export async function imageToVideoBase64({
47
 
48
  outputDir = outputDir || (await getRandomDirectory())
49
 
50
- console.log(`imagetoVideoBase64 called with: ${JSON.stringify({
51
- inputImageInBase64: inputImageInBase64?.slice(0, 50),
52
- outputFilePath,
53
- width,
54
- height,
55
- outputVideoDurationInMs,
56
- outputDir,
57
- clearOutputDirAtTheEnd,
58
- outputVideoFormat,
59
- }, null, 2)}`)
60
-
61
  outputDir = outputDir || await getRandomDirectory();
62
 
63
  // Decode the Base64 image and write it to a temporary file.
@@ -104,23 +93,22 @@ export async function imageToVideoBase64({
104
  const startZoom = 1;
105
  const endZoom = 1 + zoomInRatePerSecond * durationInSeconds;
106
 
107
- /**
108
- this version has an issue, the ken burns effect is too fast, and is repeated multiple times,
109
- which is uncomfortable to watch
110
-
111
- const videoFilters = [
112
- `crop=${cropWidth}:${cropHeight}:${(originalWidth - cropWidth) / 2}:${(originalHeight - cropHeight) / 2}`,
113
- `zoompan=z='if(lte(zoom,${endZoom}),zoom+${(endZoom - startZoom) / framesTotal},zoom)':x='${xCenter}':y='${yCenter}':d=${framesTotal/fps}`,
114
- ].join(',');
115
- */
116
 
117
- // hopefully this version works betetr
118
  const videoFilters = [
119
  `crop=${cropWidth}:${cropHeight}:${(originalWidth - cropWidth) / 2}:${(originalHeight - cropHeight) / 2}`,
120
- `zoompan=z='min(zoom+${(endZoom - startZoom) / framesTotal}, ${endZoom})':x='${xCenter}':y='${yCenter}':d=${fps}`,
121
  ].join(',');
122
 
123
- console.log("imageToVideoBase64:", {
 
 
 
 
 
 
 
 
124
  originalWidth,
125
  originalHeight,
126
  originalAspect,
@@ -133,8 +121,9 @@ export async function imageToVideoBase64({
133
  yCenter,
134
  startZoom,
135
  endZoom,
 
136
  videoFilters,
137
- })
138
 
139
  // Process the image to video conversion using ffmpeg.
140
  await new Promise<void>((resolve, reject) => {
 
47
 
48
  outputDir = outputDir || (await getRandomDirectory())
49
 
 
 
 
 
 
 
 
 
 
 
 
50
  outputDir = outputDir || await getRandomDirectory();
51
 
52
  // Decode the Base64 image and write it to a temporary file.
 
93
  const startZoom = 1;
94
  const endZoom = 1 + zoomInRatePerSecond * durationInSeconds;
95
 
96
+ const zoomDurationFrames = Math.ceil(durationInSeconds * fps); // Total frames for the video
 
 
 
 
 
 
 
 
97
 
 
98
  const videoFilters = [
99
  `crop=${cropWidth}:${cropHeight}:${(originalWidth - cropWidth) / 2}:${(originalHeight - cropHeight) / 2}`,
100
+ `zoompan=z='min(zoom+${(endZoom - startZoom) / framesTotal}, ${endZoom})':x='${xCenter}':y='${yCenter}':d=${zoomDurationFrames}`
101
  ].join(',');
102
 
103
+ console.log(`imagetoVideoBase64 called with: ${JSON.stringify({
104
+ inputImageInBase64: inputImageInBase64?.slice(0, 50),
105
+ outputFilePath,
106
+ width,
107
+ height,
108
+ outputVideoDurationInMs,
109
+ outputDir,
110
+ clearOutputDirAtTheEnd,
111
+ outputVideoFormat,
112
  originalWidth,
113
  originalHeight,
114
  originalAspect,
 
121
  yCenter,
122
  startZoom,
123
  endZoom,
124
+ zoomDurationFrames,
125
  videoFilters,
126
+ }, null, 2)}`)
127
 
128
  // Process the image to video conversion using ffmpeg.
129
  await new Promise<void>((resolve, reject) => {