-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3989 from remotion-dev/captions-type
- Loading branch information
Showing
70 changed files
with
1,416 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type {OnArtifact} from '@remotion/renderer'; | ||
import type {ArtifactProgress} from '@remotion/studio-shared'; | ||
import {existsSync, mkdirSync, writeFileSync} from 'fs'; | ||
import path from 'path'; | ||
|
||
export const handleOnArtifact = ({ | ||
artifactState, | ||
onProgress, | ||
compositionId, | ||
}: { | ||
artifactState: ArtifactProgress; | ||
onProgress: (artifact: ArtifactProgress) => void; | ||
compositionId: string; | ||
}) => { | ||
const initialProgress = {...artifactState}; | ||
|
||
const onArtifact: OnArtifact = (artifact) => { | ||
// It would be nice in the future to customize the artifact output destination | ||
|
||
const relativeOutputDestination = path.join( | ||
'out', | ||
compositionId, | ||
artifact.filename.replace('/', path.sep), | ||
); | ||
const defaultOutName = path.join(process.cwd(), relativeOutputDestination); | ||
|
||
if (!existsSync(path.dirname(defaultOutName))) { | ||
mkdirSync(path.dirname(defaultOutName), { | ||
recursive: true, | ||
}); | ||
} | ||
|
||
const alreadyExisted = existsSync(defaultOutName); | ||
|
||
writeFileSync(defaultOutName, artifact.content); | ||
|
||
initialProgress.received.push({ | ||
absoluteOutputDestination: defaultOutName, | ||
filename: artifact.filename, | ||
sizeInBytes: artifact.content.length, | ||
alreadyExisted, | ||
relativeOutputDestination, | ||
}); | ||
}; | ||
|
||
onProgress(initialProgress); | ||
|
||
return { | ||
onArtifact, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type React from 'react'; | ||
import {useContext, useEffect, useState} from 'react'; | ||
import {RenderAssetManager} from './RenderAssetManager'; | ||
import {getRemotionEnvironment} from './get-remotion-environment'; | ||
import {useCurrentFrame} from './use-current-frame'; | ||
|
||
export const Artifact: React.FC<{ | ||
readonly filename: string; | ||
readonly content: string | Uint8Array; | ||
}> = ({filename, content}) => { | ||
const {registerRenderAsset, unregisterRenderAsset} = | ||
useContext(RenderAssetManager); | ||
|
||
const [env] = useState(() => getRemotionEnvironment()); | ||
|
||
const frame = useCurrentFrame(); | ||
|
||
const [id] = useState(() => { | ||
return String(Math.random()); | ||
}); | ||
|
||
useEffect(() => { | ||
if (!env.isRendering) { | ||
return; | ||
} | ||
|
||
if (content instanceof Uint8Array) { | ||
registerRenderAsset({ | ||
type: 'artifact', | ||
id, | ||
content: btoa(new TextDecoder('utf8').decode(content)), | ||
filename, | ||
frame, | ||
binary: true, | ||
}); | ||
} else { | ||
registerRenderAsset({ | ||
type: 'artifact', | ||
id, | ||
content, | ||
filename, | ||
frame, | ||
binary: false, | ||
}); | ||
} | ||
|
||
return () => { | ||
return unregisterRenderAsset(id); | ||
}; | ||
}, [ | ||
content, | ||
env.isRendering, | ||
filename, | ||
frame, | ||
id, | ||
registerRenderAsset, | ||
unregisterRenderAsset, | ||
]); | ||
|
||
return null; | ||
}; |
Oops, something went wrong.