不同片段以不同速度
如果你有一个视频,并且想以不同的速度展示视频的不同部分,请使用以下代码片段。
🌐 If you have a video and want to show different sections of the video at different speeds, use the following snippet.
SegmentSpeeds.tsximport {OffthreadVideo ,Sequence ,staticFile ,useCurrentFrame } from 'remotion'; constsegments = [ {duration : 100,speed : 0.5, }, {duration : 100,speed : 1, }, {duration : 200,speed : 2, }, {duration : 400,speed : 4, }, ]; typeAccumulatedSegment = {start : number;passedVideoTime : number;end : number;speed : number; }; export constaccumulateSegments = () => { constaccumulatedSegments :AccumulatedSegment [] = []; letaccumulatedDuration = 0; letaccumulatedPassedVideoTime = 0; for (constsegment ofsegments ) { constduration =segment .duration /segment .speed ;accumulatedSegments .push ({end :accumulatedDuration +duration ,speed :segment .speed ,start :accumulatedDuration ,passedVideoTime :accumulatedPassedVideoTime , });accumulatedPassedVideoTime +=segment .duration ;accumulatedDuration +=duration ; } returnaccumulatedSegments ; }; export constSpeedSegments = () => { constframe =useCurrentFrame (); constaccumulated =accumulateSegments (); constcurrentSegment =accumulated .find ((segment ) =>frame >segment .start &&frame <=segment .end ); if (!currentSegment ) { return; } return ( <Sequence from ={currentSegment .start }> <OffthreadVideo pauseWhenBuffering trimBefore ={currentSegment .passedVideoTime } // Remotion will automatically add a time fragment to the end of the video URL // based on `trimBefore`. Opt out of this by adding one yourself. // https://www.remotion.dev/docs/media-fragmentssrc ={`${staticFile ('bigbuckbunny.mp4')}#t=0,`}playbackRate ={currentSegment .speed } /> </Sequence > ); };
另请参阅
🌐 See also