Skip to content

Commit

Permalink
fix top timeline bar
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke-hf committed Sep 2, 2024
1 parent 490fe73 commit c1d8629
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 160 deletions.
2 changes: 1 addition & 1 deletion packages/app/src/lib/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export const HARD_LIMIT_NB_MAX_ASSETS_TO_GENERATE_IN_PARALLEL = 32

export const APP_NAME = 'Clapper.app'
export const APP_REVISION = '20240902+0142'
export const APP_REVISION = '20240902+1208'

export const APP_DOMAIN = 'Clapper.app'
export const APP_LINK = 'https://clapper.app'
Expand Down
180 changes: 90 additions & 90 deletions packages/app/src/services/io/useIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,107 +536,107 @@ export const useIO = create<IOStore>((set, get) => ({
})

try {
const timeline: TimelineStore = useTimeline.getState()
const timeline: TimelineStore = useTimeline.getState()

const {
width,
height,
durationInMs,
segments: timelineSegments,
getClap,
} = timeline
const {
width,
height,
durationInMs,
segments: timelineSegments,
getClap,
} = timeline

const clap = await getClap()
const clap = await getClap()

if (!clap) {
throw new Error(`cannot save a clap.. if there is no clap`)
}
if (!clap) {
throw new Error(`cannot save a clap.. if there is no clap`)
}

const ignoreThisVideoSegmentId = (await getFinalVideo(clap))?.id || ''
const ignoreThisVideoSegmentId = (await getFinalVideo(clap))?.id || ''

const segments: ExportableSegment[] = timelineSegments
.map((segment, i) => formatSegmentForExport(segment, i))
.filter(
({ id, isExportableToFile }) =>
isExportableToFile && id !== ignoreThisVideoSegmentId
)
const segments: ExportableSegment[] = timelineSegments
.map((segment, i) => formatSegmentForExport(segment, i))
.filter(
({ id, isExportableToFile }) =>
isExportableToFile && id !== ignoreThisVideoSegmentId
)

const videos: FFMPegVideoInput[] = []
const images: FFMPegVideoInput[] = []
const audios: FFMPegAudioInput[] = []

segments.forEach(
({
segment,
prefix,
filePath,
assetUrl,
assetSourceType,
isExportableToFile,
}) => {
if (isExportableToFile) {
assetUrl = filePath
assetSourceType = ClapAssetSource.PATH

if (filePath.startsWith('video/')) {
videos.push({
data: base64DataUriToUint8Array(segment.assetUrl),
startTimeInMs: segment.startTimeInMs,
endTimeInMs: segment.endTimeInMs,
durationInSecs: segment.assetDurationInMs / 1000,
category: segment.category,
})
} else if (
filePath.startsWith('image/') ||
segment.category === ClapSegmentCategory.IMAGE
) {
images.push({
data: base64DataUriToUint8Array(segment.assetUrl),
startTimeInMs: segment.startTimeInMs,
endTimeInMs: segment.endTimeInMs,
durationInSecs:
(segment.endTimeInMs - segment.startTimeInMs) / 1000,
category: segment.category,
})
} else if (
filePath.startsWith('music/') ||
filePath.startsWith('sound/') ||
filePath.startsWith('dialogue/')
) {
audios.push({
data: base64DataUriToUint8Array(segment.assetUrl),
startTimeInMs: segment.startTimeInMs,
endTimeInMs: segment.endTimeInMs,
durationInSecs: segment.assetDurationInMs / 1000,
category: segment.category,
})
const videos: FFMPegVideoInput[] = []
const images: FFMPegVideoInput[] = []
const audios: FFMPegAudioInput[] = []

segments.forEach(
({
segment,
prefix,
filePath,
assetUrl,
assetSourceType,
isExportableToFile,
}) => {
if (isExportableToFile) {
assetUrl = filePath
assetSourceType = ClapAssetSource.PATH

if (filePath.startsWith('video/')) {
videos.push({
data: base64DataUriToUint8Array(segment.assetUrl),
startTimeInMs: segment.startTimeInMs,
endTimeInMs: segment.endTimeInMs,
durationInSecs: segment.assetDurationInMs / 1000,
category: segment.category,
})
} else if (
filePath.startsWith('image/') ||
segment.category === ClapSegmentCategory.IMAGE
) {
images.push({
data: base64DataUriToUint8Array(segment.assetUrl),
startTimeInMs: segment.startTimeInMs,
endTimeInMs: segment.endTimeInMs,
durationInSecs:
(segment.endTimeInMs - segment.startTimeInMs) / 1000,
category: segment.category,
})
} else if (
filePath.startsWith('music/') ||
filePath.startsWith('sound/') ||
filePath.startsWith('dialogue/')
) {
audios.push({
data: base64DataUriToUint8Array(segment.assetUrl),
startTimeInMs: segment.startTimeInMs,
endTimeInMs: segment.endTimeInMs,
durationInSecs: segment.assetDurationInMs / 1000,
category: segment.category,
})
}
}
}
}
)
)

// Combine videos and images
const videoInputs = [...videos, ...images].sort(
(a, b) => a.startTimeInMs - b.startTimeInMs
)
// Combine videos and images
const videoInputs = [...videos, ...images].sort(
(a, b) => a.startTimeInMs - b.startTimeInMs
)

const fullVideo = await createFullVideo(
videoInputs,
audios,
width,
height,
durationInMs,
(progress, message) => {
task.setProgress({
message: `Rendering video (${Math.round(progress)}%)`,
value: progress * 0.9,
})
}
)
const fullVideo = await createFullVideo(
videoInputs,
audios,
width,
height,
durationInMs,
(progress, message) => {
task.setProgress({
message: `Rendering video (${Math.round(progress)}%)`,
value: progress * 0.9,
})
}
)

const videoBlob = new Blob([fullVideo], { type: 'video/mp4' })
saveAnyFile(videoBlob, 'my_project.mp4')
task.success()
const videoBlob = new Blob([fullVideo], { type: 'video/mp4' })
saveAnyFile(videoBlob, 'my_project.mp4')
task.success()
} catch (err) {
console.error(err)
task.fail(`${err || 'unknown error'}`)
Expand Down
Loading

0 comments on commit c1d8629

Please sign in to comment.