feat(transcode): optimize video chunks for embedding by forcing 1 FPS and dropping audio

This commit is contained in:
yiling
2026-06-18 19:53:19 +08:00
parent 212ac3bc0e
commit 718d9d5b51
3 changed files with 21 additions and 6 deletions
+2 -1
View File
@@ -14,7 +14,8 @@ Semantic search translates text queries and file contents into conceptual profil
1. **Index Generation**: When you upload an asset, Shumai's background agent scans the file's visual elements, text contents, or descriptions, translating them into a concept profile.
- **Video Processing**: Shumai uses **gemini-embedding-2** for video indexing.
- **Chunking**: For long videos, Shumai breaks them into chunks to ensure high-quality indexing. By default, chunks are **60 seconds** long with a **5-second overlap** to ensure no context is lost at the boundaries.
- **Sampling**: The model processes a maximum of 32 frames per chunk: short chunks (≤32s) are sampled at 1 fps, while longer chunks are uniformly sampled to 32 frames. Note that audio tracks are not processed.
- **Sampling**: The model processes a maximum of 32 frames per chunk: short chunks (≤32s) are sampled at 1 fps, while longer chunks are uniformly sampled to 32 frames.
- **Optimization**: To optimize processing, Shumai automatically transcodes each chunk to **1 FPS** and **removes the audio track** before sending it to the embedding agent.
- **Configuration**: Administrators can customize these settings using the `EMBEDDING_CHUNK_DURATION` and `EMBEDDING_CHUNK_OVERLAP` environment variables.
2. **Concept Matching**: When you search with the "Semantic" toggle enabled, Shumai matches the conceptual meaning of your query against your assets.
3. **Result**: Searching "sunset at the beach" will successfully find a video file of ocean waves at dusk, even if the filename is `IMG_4029.mp4`.
@@ -406,8 +406,15 @@ describe('Transcode Activities', () => {
'10',
'-t',
'15',
'-c',
'copy',
'-vf',
'fps=1',
'-c:v',
'libx264',
'-preset',
'ultrafast',
'-crf',
'28',
'-an',
]),
expect.any(Function),
)
+10 -3
View File
@@ -558,7 +558,7 @@ export async function transcodeVideoChunkActivity(
): Promise<{ chunkKey: string }> {
const chunkTmp = path.join(os.tmpdir(), `video-chunk-${Date.now()}.mp4`)
try {
// Slice video segment using ffmpeg
// Slice video segment using ffmpeg, force 1fps and remove audio for gemini-embedding-2 optimization
await execFileAsync('ffmpeg', [
'-y',
'-loglevel',
@@ -569,8 +569,15 @@ export async function transcodeVideoChunkActivity(
params.startTime.toString(),
'-t',
(params.endTime - params.startTime).toString(),
'-c',
'copy',
'-vf',
'fps=1',
'-c:v',
'libx264',
'-preset',
'ultrafast',
'-crf',
'28',
'-an',
chunkTmp,
])