mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 22:18:45 +00:00
feat(video): add SMPTE timecode support and format selection dropdown
This commit is contained in:
@@ -19,6 +19,7 @@ export interface MediaMetadata {
|
|||||||
bitRate: number
|
bitRate: number
|
||||||
frameRate: number
|
frameRate: number
|
||||||
totalFrames: number
|
totalFrames: number
|
||||||
|
startTimecode?: string
|
||||||
hasAudio: boolean
|
hasAudio: boolean
|
||||||
videoCodec?: string
|
videoCodec?: string
|
||||||
audioCodec?: string
|
audioCodec?: string
|
||||||
@@ -123,6 +124,7 @@ export class TranscodeService {
|
|||||||
if (!totalFrames && fps > 0 && !isNaN(duration)) {
|
if (!totalFrames && fps > 0 && !isNaN(duration)) {
|
||||||
totalFrames = Math.round(duration * fps)
|
totalFrames = Math.round(duration * fps)
|
||||||
}
|
}
|
||||||
|
const startTimecode = videoStream.tags?.timecode || info.format?.tags?.timecode
|
||||||
|
|
||||||
return {
|
return {
|
||||||
originalWidth: videoStream.width,
|
originalWidth: videoStream.width,
|
||||||
@@ -131,6 +133,7 @@ export class TranscodeService {
|
|||||||
bitRate: parseFloat(info.format.bit_rate),
|
bitRate: parseFloat(info.format.bit_rate),
|
||||||
frameRate: fps || 30,
|
frameRate: fps || 30,
|
||||||
totalFrames: totalFrames || 0,
|
totalFrames: totalFrames || 0,
|
||||||
|
startTimecode,
|
||||||
hasAudio: !!audioStream,
|
hasAudio: !!audioStream,
|
||||||
videoCodec: this.resolveCodecName(videoStream),
|
videoCodec: this.resolveCodecName(videoStream),
|
||||||
audioCodec: audioStream ? this.resolveCodecName(audioStream) : undefined,
|
audioCodec: audioStream ? this.resolveCodecName(audioStream) : undefined,
|
||||||
@@ -161,6 +164,7 @@ export class TranscodeService {
|
|||||||
bitRate: 0,
|
bitRate: 0,
|
||||||
frameRate: 0,
|
frameRate: 0,
|
||||||
totalFrames: 0,
|
totalFrames: 0,
|
||||||
|
startTimecode: undefined,
|
||||||
hasAudio: false,
|
hasAudio: false,
|
||||||
mimeType: metadata.format || '',
|
mimeType: metadata.format || '',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ declare global {
|
|||||||
bitRate: number
|
bitRate: number
|
||||||
frameRate: number
|
frameRate: number
|
||||||
totalFrames?: number
|
totalFrames?: number
|
||||||
|
startTimecode?: string
|
||||||
videoCodec?: string
|
videoCodec?: string
|
||||||
audioCodec?: string
|
audioCodec?: string
|
||||||
audioChannels?: number
|
audioChannels?: number
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export const mediaMetadataSchema = z.object({
|
|||||||
originalHeight: z.number().optional(),
|
originalHeight: z.number().optional(),
|
||||||
frameRate: z.number().optional(),
|
frameRate: z.number().optional(),
|
||||||
totalFrames: z.number().optional(),
|
totalFrames: z.number().optional(),
|
||||||
|
startTimecode: z.string().optional(),
|
||||||
})
|
})
|
||||||
export type MediaMetadata = z.infer<typeof mediaMetadataSchema>
|
export type MediaMetadata = z.infer<typeof mediaMetadataSchema>
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ export async function getMediaInfoActivity(params: {
|
|||||||
bitRate: info.bitRate,
|
bitRate: info.bitRate,
|
||||||
frameRate: info.frameRate,
|
frameRate: info.frameRate,
|
||||||
totalFrames: info.totalFrames,
|
totalFrames: info.totalFrames,
|
||||||
|
startTimecode: info.startTimecode,
|
||||||
hasAudio: info.hasAudio,
|
hasAudio: info.hasAudio,
|
||||||
videoCodec: info.videoCodec,
|
videoCodec: info.videoCodec,
|
||||||
audioCodec: info.audioCodec,
|
audioCodec: info.audioCodec,
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ import Markdown from 'react-markdown'
|
|||||||
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar'
|
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar'
|
||||||
import { DrawAnnotation } from '../ui/icons'
|
import { DrawAnnotation } from '../ui/icons'
|
||||||
import { Skeleton } from '../ui/skeleton'
|
import { Skeleton } from '../ui/skeleton'
|
||||||
import { formatTimestamp } from '../viewers/utils'
|
import { formatTimecode } from '../viewers/utils'
|
||||||
import { m } from '@/ui/paraglide/messages.js'
|
import { m } from '@/ui/paraglide/messages.js'
|
||||||
|
import { useUiStore } from '@/ui/stores/ui'
|
||||||
|
|
||||||
interface MessageCardProps {
|
interface MessageCardProps {
|
||||||
teamId?: string
|
teamId?: string
|
||||||
@@ -32,6 +33,7 @@ interface MessageCardProps {
|
|||||||
isSelected?: boolean
|
isSelected?: boolean
|
||||||
onSelect?: () => void
|
onSelect?: () => void
|
||||||
frameRate?: number
|
frameRate?: number
|
||||||
|
startTimecode?: string
|
||||||
rootParentId?: string
|
rootParentId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ export const MessageCard: React.FC<MessageCardProps> = ({
|
|||||||
isSelected,
|
isSelected,
|
||||||
onSelect,
|
onSelect,
|
||||||
frameRate,
|
frameRate,
|
||||||
|
startTimecode,
|
||||||
}) => {
|
}) => {
|
||||||
const message = initialMessage
|
const message = initialMessage
|
||||||
const hasDrawInfo =
|
const hasDrawInfo =
|
||||||
@@ -66,6 +69,13 @@ export const MessageCard: React.FC<MessageCardProps> = ({
|
|||||||
|
|
||||||
const [isLogsOpen, setIsLogsOpen] = React.useState(false)
|
const [isLogsOpen, setIsLogsOpen] = React.useState(false)
|
||||||
|
|
||||||
|
const { videoTimeDisplayMode } = useUiStore()
|
||||||
|
const displayTime = React.useMemo(() => {
|
||||||
|
if (message.second === null || message.second === undefined || !frameRate) return ''
|
||||||
|
const frameIndex = Math.round(message.second * frameRate)
|
||||||
|
return formatTimecode(frameIndex, frameRate, videoTimeDisplayMode, startTimecode)
|
||||||
|
}, [message.second, frameRate, videoTimeDisplayMode, startTimecode])
|
||||||
|
|
||||||
const { data: me } = useQuery({
|
const { data: me } = useQuery({
|
||||||
queryKey: ['teams', teamId, 'me'],
|
queryKey: ['teams', teamId, 'me'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
@@ -171,7 +181,7 @@ export const MessageCard: React.FC<MessageCardProps> = ({
|
|||||||
<div className="flow-root mt-1">
|
<div className="flow-root mt-1">
|
||||||
{message.second !== null && message.second !== undefined && frameRate && (
|
{message.second !== null && message.second !== undefined && frameRate && (
|
||||||
<div className="float-left select-none bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 px-2.5 py-1 mt-[2px] mr-2 rounded-sm text-xs leading-none font-mono font-bold flex items-center gap-1">
|
<div className="float-left select-none bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 px-2.5 py-1 mt-[2px] mr-2 rounded-sm text-xs leading-none font-mono font-bold flex items-center gap-1">
|
||||||
{formatTimestamp(message.second, frameRate)}
|
{displayTime}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ import { Button } from '../ui/button'
|
|||||||
import { DrawAnnotation } from '../ui/icons'
|
import { DrawAnnotation } from '../ui/icons'
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
|
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
|
||||||
import { ProgressCircle } from '../ui/progress-circle'
|
import { ProgressCircle } from '../ui/progress-circle'
|
||||||
import { formatTimestamp } from '../viewers/utils'
|
import { formatTimecode } from '../viewers/utils'
|
||||||
|
import { useUiStore } from '@/ui/stores/ui'
|
||||||
|
|
||||||
type UploadingFile = {
|
type UploadingFile = {
|
||||||
id: string // A unique ID for the file, e.g., timestamp + name
|
id: string // A unique ID for the file, e.g., timestamp + name
|
||||||
@@ -54,6 +55,7 @@ interface ChatInputProps {
|
|||||||
disableMentions?: boolean
|
disableMentions?: boolean
|
||||||
currentTime?: number
|
currentTime?: number
|
||||||
frameRate?: number
|
frameRate?: number
|
||||||
|
startTimecode?: string
|
||||||
onTyping?: () => void
|
onTyping?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +86,7 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
|||||||
disableMentions = false,
|
disableMentions = false,
|
||||||
currentTime,
|
currentTime,
|
||||||
frameRate,
|
frameRate,
|
||||||
|
startTimecode,
|
||||||
onTyping,
|
onTyping,
|
||||||
},
|
},
|
||||||
ref,
|
ref,
|
||||||
@@ -92,6 +95,13 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
|||||||
const [viewingFile, setViewingFile] = useState<File | null>(null)
|
const [viewingFile, setViewingFile] = useState<File | null>(null)
|
||||||
const [isTimestampEnabled, setIsTimestampEnabled] = useState(true)
|
const [isTimestampEnabled, setIsTimestampEnabled] = useState(true)
|
||||||
|
|
||||||
|
const { videoTimeDisplayMode } = useUiStore()
|
||||||
|
const displayTime = React.useMemo(() => {
|
||||||
|
if (currentTime === undefined || !frameRate) return ''
|
||||||
|
const frameIndex = Math.round(currentTime * frameRate)
|
||||||
|
return formatTimecode(frameIndex, frameRate, videoTimeDisplayMode, startTimecode)
|
||||||
|
}, [currentTime, frameRate, videoTimeDisplayMode, startTimecode])
|
||||||
|
|
||||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||||
const { members: storeMembers, loading: membersLoading, fetchMembers } = useMemberStore()
|
const { members: storeMembers, loading: membersLoading, fetchMembers } = useMemberStore()
|
||||||
|
|
||||||
@@ -123,6 +133,16 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
|||||||
const [collapsedSections, setCollapsedSections] = useState({ bots: false, users: false })
|
const [collapsedSections, setCollapsedSections] = useState({ bots: false, users: false })
|
||||||
const [hasContent, setHasContent] = useState(false)
|
const [hasContent, setHasContent] = useState(false)
|
||||||
|
|
||||||
|
const paddingLeftClass = React.useMemo(() => {
|
||||||
|
if (!isTimestampEnabled || currentTime === undefined || !frameRate || hasContent) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
if (videoTimeDisplayMode === 'timecode') {
|
||||||
|
return 'pl-[120px]'
|
||||||
|
}
|
||||||
|
return 'pl-[85px]'
|
||||||
|
}, [isTimestampEnabled, currentTime, frameRate, hasContent, videoTimeDisplayMode])
|
||||||
|
|
||||||
const editorRef = useRef<HTMLDivElement>(null)
|
const editorRef = useRef<HTMLDivElement>(null)
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||||
const mentionRangeRef = useRef<Range | null>(null)
|
const mentionRangeRef = useRef<Range | null>(null)
|
||||||
@@ -645,7 +665,7 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
|||||||
}}
|
}}
|
||||||
className="float-left select-none bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 px-2.5 py-0.5 mt-3 mr-2 rounded-sm text-xs font-mono font-bold flex items-center gap-1 cursor-text"
|
className="float-left select-none bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 px-2.5 py-0.5 mt-3 mr-2 rounded-sm text-xs font-mono font-bold flex items-center gap-1 cursor-text"
|
||||||
>
|
>
|
||||||
{formatTimestamp(currentTime, frameRate)}
|
{displayTime}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
@@ -655,7 +675,7 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
|||||||
onInput={handleInput}
|
onInput={handleInput}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
data-placeholder={replyingTo ? 'Reply...' : 'Message...'}
|
data-placeholder={replyingTo ? 'Reply...' : 'Message...'}
|
||||||
className={`bg-transparent border-none focus:ring-0 resize-none min-h-[40px] leading-relaxed py-2 focus:outline-none block ${isTimestampEnabled && currentTime !== undefined && frameRate !== undefined && !hasContent ? 'pl-[120px]' : ''}`}
|
className={`bg-transparent border-none focus:ring-0 resize-none min-h-[40px] leading-relaxed py-2 focus:outline-none block ${paddingLeftClass}`}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -359,6 +359,11 @@ export function FileViewerRightSidebar({
|
|||||||
? file?.media?.metadata?.frameRate || 30
|
? file?.media?.metadata?.frameRate || 30
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
startTimecode={
|
||||||
|
file?.mediaType?.startsWith('video/')
|
||||||
|
? file?.media?.metadata?.startTimecode
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
isSelected={selectedCommentId === comment.id}
|
isSelected={selectedCommentId === comment.id}
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
onCommentSelect?.(comment)
|
onCommentSelect?.(comment)
|
||||||
@@ -380,6 +385,11 @@ export function FileViewerRightSidebar({
|
|||||||
? file?.media?.metadata?.frameRate || 30
|
? file?.media?.metadata?.frameRate || 30
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
startTimecode={
|
||||||
|
file?.mediaType?.startsWith('video/')
|
||||||
|
? file?.media?.metadata?.startTimecode
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
isSelected={selectedCommentId === reply.id}
|
isSelected={selectedCommentId === reply.id}
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
onCommentSelect?.(reply)
|
onCommentSelect?.(reply)
|
||||||
@@ -413,6 +423,11 @@ export function FileViewerRightSidebar({
|
|||||||
? file?.media?.metadata?.frameRate || 30
|
? file?.media?.metadata?.frameRate || 30
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
startTimecode={
|
||||||
|
file?.mediaType?.startsWith('video/')
|
||||||
|
? file?.media?.metadata?.startTimecode
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
onTyping={onTyping}
|
onTyping={onTyping}
|
||||||
/>
|
/>
|
||||||
</GuestIdentityPopup>
|
</GuestIdentityPopup>
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { formatTimecode } from './utils'
|
||||||
|
|
||||||
|
describe('formatTimecode tests', () => {
|
||||||
|
describe('non-drop-frame calculations', () => {
|
||||||
|
it('formats non-drop-frame correctly at 25 fps', () => {
|
||||||
|
// 2999 frames at 25 fps => 00:01:59:24
|
||||||
|
expect(formatTimecode(2999, 25, 'timecode')).toBe('00:01:59:24')
|
||||||
|
// 3000 frames at 25 fps => 00:02:00:00
|
||||||
|
expect(formatTimecode(3000, 25, 'timecode')).toBe('00:02:00:00')
|
||||||
|
// 15000 frames at 25 fps => 00:10:00:00
|
||||||
|
expect(formatTimecode(15000, 25, 'timecode')).toBe('00:10:00:00')
|
||||||
|
// 900000 frames at 25 fps => 10:00:00:00
|
||||||
|
expect(formatTimecode(900000, 25, 'timecode')).toBe('10:00:00:00')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('drop-frame calculations', () => {
|
||||||
|
it('formats drop-frame correctly at 29.97 fps', () => {
|
||||||
|
// 3597 frames at 29.97 fps => 00:01:59;29
|
||||||
|
expect(formatTimecode(3597, 29.97, 'timecode')).toBe('00:01:59;29')
|
||||||
|
// 17982 frames at 29.97 fps => 00:10:00;00
|
||||||
|
expect(formatTimecode(17982, 29.97, 'timecode')).toBe('00:10:00;00')
|
||||||
|
// 1078920 frames at 29.97 fps => 10:00:00;00
|
||||||
|
expect(formatTimecode(1078920, 29.97, 'timecode')).toBe('10:00:00;00')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('formats drop-frame correctly at 59.94 fps', () => {
|
||||||
|
// 3597 * 2 + 1 = 7195 frames at 59.94 fps => 00:01:59;59
|
||||||
|
expect(formatTimecode(7195, 59.94, 'timecode')).toBe('00:01:59;59')
|
||||||
|
// 17982 * 2 = 35964 frames at 59.94 fps => 00:10:00;00
|
||||||
|
expect(formatTimecode(35964, 59.94, 'timecode')).toBe('00:10:00;00')
|
||||||
|
// 1078920 * 2 = 2157840 frames at 59.94 fps => 10:00:00;00
|
||||||
|
expect(formatTimecode(2157840, 59.94, 'timecode')).toBe('10:00:00;00')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('starting timecode offsets', () => {
|
||||||
|
it('offsets timecode correctly based on startTimecode string', () => {
|
||||||
|
// 0 frames at 29.97 fps with start '01:00:00:00' => 01:00:00:00
|
||||||
|
expect(formatTimecode(0, 29.97, 'timecode', '01:00:00:00')).toBe('01:00:00:00')
|
||||||
|
// 0 frames at 29.97 fps with start '01:00:00;00' => 01:00:00;00
|
||||||
|
expect(formatTimecode(0, 29.97, 'timecode', '01:00:00;00')).toBe('01:00:00;00')
|
||||||
|
// 30 frames at 30 fps with start '01:00:00:00' => 01:00:01:00
|
||||||
|
expect(formatTimecode(30, 30, 'timecode', '01:00:00:00')).toBe('01:00:01:00')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('other display modes', () => {
|
||||||
|
it('formats as frames index', () => {
|
||||||
|
expect(formatTimecode(150, 30, 'frames')).toBe('150 fr')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('formats as standard MM:SS time', () => {
|
||||||
|
expect(formatTimecode(150, 30, 'standard')).toBe('00:05')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -2,22 +2,86 @@ export const formatTime = (seconds: number): string => {
|
|||||||
if (isNaN(seconds)) return '00:00'
|
if (isNaN(seconds)) return '00:00'
|
||||||
const date = new Date(seconds * 1000)
|
const date = new Date(seconds * 1000)
|
||||||
const hh = date.getUTCHours()
|
const hh = date.getUTCHours()
|
||||||
const mm = date.getUTCMinutes()
|
const mm = date.getUTCMinutes().toString().padStart(2, '0')
|
||||||
const ss = date.getUTCSeconds().toString().padStart(2, '0')
|
const ss = date.getUTCSeconds().toString().padStart(2, '0')
|
||||||
if (hh) {
|
if (hh) {
|
||||||
return `${hh}:${mm.toString().padStart(2, '0')}:${ss}`
|
return `${hh}:${mm}:${ss}`
|
||||||
}
|
}
|
||||||
return `${mm}:${ss}`
|
return `${mm}:${ss}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const formatTimecode = (
|
||||||
|
frameIndex: number,
|
||||||
|
frameRate: number,
|
||||||
|
mode: 'standard' | 'frames' | 'timecode',
|
||||||
|
startTimecode?: string | null,
|
||||||
|
): string => {
|
||||||
|
if (mode === 'frames') {
|
||||||
|
return `${frameIndex} fr`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode === 'standard') {
|
||||||
|
return formatTime(frameIndex / frameRate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if drop-frame should be used (standard for NTSC 29.97 and 59.94)
|
||||||
|
const frameRateRound = Math.round(frameRate)
|
||||||
|
const isFractional = frameRate !== frameRateRound
|
||||||
|
let dropFrame = false
|
||||||
|
if (isFractional && (frameRateRound === 30 || frameRateRound === 60)) {
|
||||||
|
dropFrame = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse start timecode if provided
|
||||||
|
let startFrameCount = 0
|
||||||
|
if (startTimecode) {
|
||||||
|
const parts = startTimecode.match(/^([012]\d):(\d\d):(\d\d)(:|;|\.)(\d+)$/)
|
||||||
|
if (parts) {
|
||||||
|
const hours = parseInt(parts[1], 10)
|
||||||
|
const minutes = parseInt(parts[2], 10)
|
||||||
|
const seconds = parseInt(parts[3], 10)
|
||||||
|
const frames = parseInt(parts[5], 10)
|
||||||
|
|
||||||
|
// Timecode string format overrides the default dropFrame setting
|
||||||
|
dropFrame = parts[4] !== ':'
|
||||||
|
|
||||||
|
// Calculate frame count from timecode
|
||||||
|
startFrameCount = (hours * 3600 + minutes * 60 + seconds) * frameRateRound + frames
|
||||||
|
if (dropFrame) {
|
||||||
|
const totalMinutes = hours * 60 + minutes
|
||||||
|
const df = frameRate < 30 ? 2 : 4
|
||||||
|
startFrameCount -= df * (totalMinutes - Math.floor(totalMinutes / 10))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate absolute frame count
|
||||||
|
let fc = frameIndex + startFrameCount
|
||||||
|
|
||||||
|
// Convert frame count to timecode using the exact smpte-timecode formula
|
||||||
|
if (dropFrame) {
|
||||||
|
const df = frameRate < 30 ? 2 : 4
|
||||||
|
const d = Math.floor(fc / ((17982 * df) / 2))
|
||||||
|
let m = fc % ((17982 * df) / 2)
|
||||||
|
if (m < df) {
|
||||||
|
m = m + df
|
||||||
|
}
|
||||||
|
fc += 9 * df * d + df * Math.floor((m - df) / ((1798 * df) / 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
const frames = fc % frameRateRound
|
||||||
|
const seconds = Math.floor(fc / frameRateRound) % 60
|
||||||
|
const minutes = Math.floor(fc / (frameRateRound * 60)) % 60
|
||||||
|
const hours = Math.floor(fc / (frameRateRound * 3600)) % 24
|
||||||
|
|
||||||
|
const separator = dropFrame ? ';' : ':'
|
||||||
|
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}${separator}${frames.toString().padStart(2, '0')}`
|
||||||
|
}
|
||||||
|
|
||||||
export const formatTimestamp = (seconds: number, fps: number): string => {
|
export const formatTimestamp = (seconds: number, fps: number): string => {
|
||||||
if (isNaN(seconds)) return '00:00:00:00'
|
if (isNaN(seconds)) return '00:00:00:00'
|
||||||
const hh = Math.floor(seconds / 3600)
|
const frameIndex = Math.round(seconds * fps)
|
||||||
const mm = Math.floor((seconds % 3600) / 60)
|
return formatTimecode(frameIndex, fps, 'timecode')
|
||||||
const ss = Math.floor(seconds % 60)
|
|
||||||
const ff = Math.floor((seconds % 1) * fps)
|
|
||||||
|
|
||||||
return `${hh.toString().padStart(2, '0')}:${mm.toString().padStart(2, '0')}:${ss.toString().padStart(2, '0')}:${ff.toString().padStart(2, '0')}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const formatFrame = (seconds: number, fps: number): number => {
|
export const formatFrame = (seconds: number, fps: number): number => {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import type { AssetInfo, VideoTranscode } from '@shumai/dtos'
|
import type { AssetInfo, VideoTranscode } from '@shumai/dtos'
|
||||||
import { cn } from '@/ui/lib/utils'
|
import { cn } from '@/ui/lib/utils'
|
||||||
import {
|
import {
|
||||||
|
Check,
|
||||||
|
ChevronDown,
|
||||||
Download,
|
Download,
|
||||||
Maximize,
|
Maximize,
|
||||||
Minimize,
|
Minimize,
|
||||||
@@ -25,8 +27,9 @@ import {
|
|||||||
} from '../ui/dropdown-menu'
|
} from '../ui/dropdown-menu'
|
||||||
import { Slider } from '../ui/slider'
|
import { Slider } from '../ui/slider'
|
||||||
import ProgressBar from './progress-bar'
|
import ProgressBar from './progress-bar'
|
||||||
import { formatTime } from './utils'
|
import { formatTimecode } from './utils'
|
||||||
import { useFramePlayer } from './use-frame-player'
|
import { useFramePlayer } from './use-frame-player'
|
||||||
|
import { useUiStore } from '@/ui/stores/ui'
|
||||||
|
|
||||||
import type { Annotation } from '@/ui/types'
|
import type { Annotation } from '@/ui/types'
|
||||||
import DrawingCanvas from '../drawing-canvas'
|
import DrawingCanvas from '../drawing-canvas'
|
||||||
@@ -71,7 +74,6 @@ interface ControlBarProps {
|
|||||||
toggleLoop: () => void
|
toggleLoop: () => void
|
||||||
toggleMute: () => void
|
toggleMute: () => void
|
||||||
handleVolumeChange: (newVolume: number) => void
|
handleVolumeChange: (newVolume: number) => void
|
||||||
setState: React.Dispatch<React.SetStateAction<PlayerState>>
|
|
||||||
changePlaybackRate: (rate: number) => void
|
changePlaybackRate: (rate: number) => void
|
||||||
changeResolution: (res: DisplayTranscode) => void
|
changeResolution: (res: DisplayTranscode) => void
|
||||||
handleDownload: (url: string, resolution: string) => void
|
handleDownload: (url: string, resolution: string) => void
|
||||||
@@ -95,7 +97,6 @@ const ControlBar: React.FC<ControlBarProps> = ({
|
|||||||
toggleLoop,
|
toggleLoop,
|
||||||
toggleMute,
|
toggleMute,
|
||||||
handleVolumeChange,
|
handleVolumeChange,
|
||||||
setState,
|
|
||||||
changePlaybackRate,
|
changePlaybackRate,
|
||||||
changeResolution,
|
changeResolution,
|
||||||
handleDownload,
|
handleDownload,
|
||||||
@@ -112,6 +113,14 @@ const ControlBar: React.FC<ControlBarProps> = ({
|
|||||||
|
|
||||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||||
|
|
||||||
|
const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
|
||||||
|
|
||||||
|
const startTimecode = data.media?.metadata?.startTimecode
|
||||||
|
const displayString =
|
||||||
|
videoTimeDisplayMode === 'frames'
|
||||||
|
? `${currentFrame} / ${totalFrames} fr`
|
||||||
|
: `${formatTimecode(currentFrame, frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(totalFrames, frameRate, videoTimeDisplayMode, startTimecode)}`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -189,17 +198,47 @@ const ControlBar: React.FC<ControlBarProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div className="flex items-center gap-1 text-sm font-medium tabular-nums select-none min-w-[100px]">
|
||||||
className="min-w-[100px] cursor-pointer text-sm font-medium tabular-nums hover:text-primary"
|
<span className="text-muted-foreground font-mono">{displayString}</span>
|
||||||
onClick={() => setState((p) => ({ ...p, showFrames: !p.showFrames }))}
|
<DropdownMenu modal={false}>
|
||||||
title="Click to toggle Time/Frames"
|
<DropdownMenuTrigger asChild>
|
||||||
>
|
<button className="h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors cursor-pointer focus:outline-none">
|
||||||
{state.showFrames
|
<ChevronDown className="h-3.5 w-3.5" />
|
||||||
? `${currentFrame} / ${totalFrames}`
|
</button>
|
||||||
: `${formatTime(currentFrame / frameRate)} / ${formatTime(totalFrames / frameRate)}`}
|
</DropdownMenuTrigger>
|
||||||
<span className="ml-1 text-xs text-muted-foreground">
|
<DropdownMenuContent align="start" className="w-40 z-30">
|
||||||
{state.showFrames ? 'fr' : ''}
|
<DropdownMenuLabel className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">
|
||||||
</span>
|
Format
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => setVideoTimeDisplayMode('standard')}
|
||||||
|
className="flex items-center justify-between cursor-pointer text-xs"
|
||||||
|
>
|
||||||
|
<span>Standard Time</span>
|
||||||
|
{videoTimeDisplayMode === 'standard' && (
|
||||||
|
<Check className="h-3.5 w-3.5 text-primary" />
|
||||||
|
)}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => setVideoTimeDisplayMode('frames')}
|
||||||
|
className="flex items-center justify-between cursor-pointer text-xs"
|
||||||
|
>
|
||||||
|
<span>Frames</span>
|
||||||
|
{videoTimeDisplayMode === 'frames' && (
|
||||||
|
<Check className="h-3.5 w-3.5 text-primary" />
|
||||||
|
)}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => setVideoTimeDisplayMode('timecode')}
|
||||||
|
className="flex items-center justify-between cursor-pointer text-xs"
|
||||||
|
>
|
||||||
|
<span>Timecode</span>
|
||||||
|
{videoTimeDisplayMode === 'timecode' && (
|
||||||
|
<Check className="h-3.5 w-3.5 text-primary" />
|
||||||
|
)}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ interface UiState {
|
|||||||
|
|
||||||
viewModes: { [projectId: string]: 'card' | 'list' }
|
viewModes: { [projectId: string]: 'card' | 'list' }
|
||||||
setViewMode: (projectId: string, mode: 'card' | 'list') => void
|
setViewMode: (projectId: string, mode: 'card' | 'list') => void
|
||||||
|
|
||||||
|
videoTimeDisplayMode: 'standard' | 'frames' | 'timecode'
|
||||||
|
setVideoTimeDisplayMode: (mode: 'standard' | 'frames' | 'timecode') => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUiStore = create<UiState>()(
|
export const useUiStore = create<UiState>()(
|
||||||
@@ -56,6 +59,9 @@ export const useUiStore = create<UiState>()(
|
|||||||
set((state) => ({
|
set((state) => ({
|
||||||
viewModes: { ...state.viewModes, [projectId]: mode },
|
viewModes: { ...state.viewModes, [projectId]: mode },
|
||||||
})),
|
})),
|
||||||
|
|
||||||
|
videoTimeDisplayMode: 'standard',
|
||||||
|
setVideoTimeDisplayMode: (mode) => set({ videoTimeDisplayMode: mode }),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: 'ui-storage',
|
name: 'ui-storage',
|
||||||
|
|||||||
Reference in New Issue
Block a user