@@ -207,7 +207,6 @@ export interface VideoMetadata {
207207 videoStreamStartSeconds ?: number ;
208208 /** Seconds after the file's media time 0 (its earliest audio/video stream start) at which video begins. */
209209 videoStreamLeadSeconds ?: number ;
210- /** How far the browser's media time runs ahead of the file's: it counts an MP4 or WebM from timestamp 0. */
211210 mediaTimeOffsetSeconds ?: number ;
212211 width : number ;
213212 height : number ;
@@ -245,7 +244,6 @@ export interface AudioMetadata {
245244 /** Seconds after the file's media time 0 at which its last audio or video stream starts. */
246245 latestStreamLeadSeconds ?: number ;
247246 audioStreamLeadSeconds ?: number ;
248- /** As on VideoMetadata: how far the browser's media time runs ahead of the file's. */
249247 mediaTimeOffsetSeconds ?: number ;
250248 audioStreamCount ?: number ;
251249 /** The track read for these facts and for the mix, by its place among the audio streams (decodableAudioStream). */
@@ -516,14 +514,12 @@ export async function buildProbeFactsText(filePath: string, signal?: AbortSignal
516514 return JSON . stringify ( facts ) ;
517515}
518516
519- /** Where the video begins on the media timeline the browser plays. */
520517export function videoStartOnMediaTimeline (
521518 metadata : Pick < VideoMetadata , "videoStreamLeadSeconds" | "mediaTimeOffsetSeconds" > ,
522519) : number {
523520 return ( metadata . videoStreamLeadSeconds ?? 0 ) + ( metadata . mediaTimeOffsetSeconds ?? 0 ) ;
524521}
525522
526- /** FFmpeg's input `-ss` for a media time: FFmpeg counts from the file's earliest stream start. */
527523export function ffmpegSeekSeconds (
528524 metadata : Pick < VideoMetadata , "mediaTimeOffsetSeconds" > ,
529525 mediaTime : number ,
@@ -1292,11 +1288,12 @@ function streamLeadSeconds(output: FFProbeOutput | null, stream: FFProbeStream):
12921288 return Number . isFinite ( start ) && starts . length > 0 ? Math . max ( 0 , start - Math . min ( ...starts ) ) : 0 ;
12931289}
12941290
1295- // Transport streams start their clock anywhere (MPEG-TS at 1.4 s); their earliest stream is media time 0.
1291+ const BROWSER_PLAYS_FROM_TIMESTAMP_ZERO = / \b ( m p 4 | w e b m ) \b / ;
1292+
12961293function mediaTimeOffsetSeconds ( output : FFProbeOutput | null ) : number {
12971294 const starts = audioVideoStreamStarts ( output ) ;
1298- const countsFromZero = / \b ( m p 4 | w e b m ) \b / . test ( output ?. format . format_name ?? "" ) ;
1299- return countsFromZero && starts . length > 0 ? Math . max ( 0 , Math . min ( ...starts ) ) : 0 ;
1295+ const fromZero = BROWSER_PLAYS_FROM_TIMESTAMP_ZERO . test ( output ?. format . format_name ?? "" ) ;
1296+ return fromZero && starts . length > 0 ? Math . max ( 0 , Math . min ( ...starts ) ) : 0 ;
13001297}
13011298
13021299function latestStreamLeadSeconds ( output : FFProbeOutput ) : number {
0 commit comments