Skip to content

Commit f1462d0

Browse files
committed
track video duration right after recordins stops
1 parent e431f09 commit f1462d0

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

app/services/highlighter/cut-highlight-clips.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FFMPEG_EXE, FFPROBE_EXE } from './constants';
55
import { IHighlight } from './models/ai-highlighter.models';
66
import path from 'path';
77

8-
async function getVideoDuration(filePath: string): Promise<number> {
8+
export async function getVideoDuration(filePath: string): Promise<number> {
99
const { stdout } = await execa(FFPROBE_EXE, [
1010
'-v',
1111
'error',

app/services/highlighter/index.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import {
6767
} from './models/ai-highlighter.models';
6868
import { HighlighterViews } from './highlighter-views';
6969
import { startRendering } from './rendering/start-rendering';
70-
import { cutHighlightClips } from './cut-highlight-clips';
70+
import { cutHighlightClips, getVideoDuration } from './cut-highlight-clips';
7171
import { reduce } from 'lodash';
7272
import { extractDateTimeFromPath, fileExists } from './file-utils';
7373
import { addVerticalFilterToExportOptions } from './vertical-export';
@@ -449,12 +449,28 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
449449
});
450450

451451
this.streamingService.latestRecordingPath.subscribe(path => {
452+
// Check if recording is immediately available
453+
getVideoDuration(path)
454+
.then(duration => {
455+
if (isNaN(duration)) {
456+
duration = -1;
457+
}
458+
this.usageStatisticsService.recordAnalyticsEvent('AIHighlighter', {
459+
type: 'FinishRecording',
460+
duration,
461+
});
462+
console.log('Successfully got duration', duration);
463+
})
464+
.catch(error => {
465+
console.error('Failed getting duration right after the recoding.', error);
466+
});
467+
452468
if (!aiRecordingInProgress) {
453469
return;
454470
}
455471

456472
aiRecordingInProgress = false;
457-
this.detectAndClipAiHighlights(path, streamInfo);
473+
this.detectAndClipAiHighlights(path, streamInfo, true);
458474

459475
this.navigationService.actions.navigate(
460476
'Highlighter',
@@ -1186,6 +1202,7 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
11861202
async detectAndClipAiHighlights(
11871203
filePath: string,
11881204
streamInfo: IStreamInfoForAiHighlighter,
1205+
delayStart = false,
11891206
): Promise<void> {
11901207
if (this.aiHighlighterFeatureEnabled === false) {
11911208
console.log('HighlighterService: Not enabled');
@@ -1246,6 +1263,10 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
12461263

12471264
console.log('🔄 HighlighterData');
12481265
try {
1266+
if (delayStart) {
1267+
await this.wait(5000);
1268+
}
1269+
12491270
const highlighterResponse = await getHighlightClips(
12501271
filePath,
12511272
this.userService.getLocalUserId(),
@@ -1492,4 +1513,13 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
14921513

14931514
return id;
14941515
}
1516+
1517+
/**
1518+
* Utility function that returns a promise that resolves after a specified delay
1519+
* @param ms Delay in milliseconds
1520+
* @returns Promise that resolves after the delay
1521+
*/
1522+
wait(ms: number): Promise<void> {
1523+
return new Promise<void>(resolve => setTimeout(resolve, ms));
1524+
}
14951525
}

0 commit comments

Comments
 (0)