导出字幕
🌐 Exporting subtitles
本指南介绍了从你的 Remotion 视频导出字幕的不同方法。
🌐 This guide covers different ways to export subtitles from your Remotion video.
烧录字幕
🌐 Burned-in subtitles
如果你希望字幕成为视频本身的一部分(烧录在视频中),请按照显示字幕中的说明渲染字幕,然后像平常一样渲染视频即可。
🌐 If you want the subtitles to be part of the video itself (burned in), follow the instructions in Displaying captions to render the captions, then simply render the video as usual.
npx remotion render导出为单独的 .srt 文件
🌐 Exporting as a separate .srt file
要将字幕导出为单独的 .srt 文件,请将 <Artifact> 组件与 serializeSrt() 一起使用。
🌐 To export subtitles as a separate .srt file, use the <Artifact> component together with serializeSrt().
Exporting captions as .srtexport constMyComp :React .FC = () => { constframe =useCurrentFrame (); // Convert captions to SRT format // Each caption becomes its own line constsrtContent =serializeSrt ({lines :captions .map ((caption ) => [caption ]), }); return ( <> {/* Only emit the artifact on the first frame */} {frame === 0 ? <Artifact filename ="subtitles.srt"content ={srtContent } /> : null} {/* Rest of your video content */} </> ); };
在渲染时,工件将被保存到 out/[composition-id]/subtitles.srt。
🌐 The artifact will be saved to out/[composition-id]/subtitles.srt when rendering.
将单词分组为行
🌐 Grouping words into lines
如果你的字幕是逐字的,你可能想将多个单词组合到一个字幕行中。你可以使用 createTikTokStyleCaptions() 创建页面,然后将它们转换回 serializeSrt() 期待的格式:
🌐 If your captions are word-by-word, you may want to group multiple words into a single subtitle line. You can use createTikTokStyleCaptions() to create pages, then convert them back to the format expected by serializeSrt():
Grouping captions into linesconst {pages } =createTikTokStyleCaptions ({captions ,combineTokensWithinMilliseconds : 3000, }); constsrtContent =serializeSrt ({lines :pages .map ((page ) => { // Convert page tokens back to Caption format returnpage .tokens .map ((token ) => ({text :token .text ,startMs :token .fromMs ,endMs :token .toMs ,timestampMs : (token .fromMs +token .toMs ) / 2,confidence : null, })); }), });
另请参阅
🌐 See also
- 显示字幕 - 在你的视频中呈现字幕
<Artifact>- 在渲染期间输出文件serializeSrt()- 将字幕转换为 SRT 格式- 释放神器 - 关于神器的完整指南