🎥 Make videos programmatically with React
import {expect, test} from 'vitest';
import {getTimeInSeconds} from '../get-time-in-seconds';
test('should inhibit the same behavior as <Html5Video> - no loop', () => {
const timestamp = getTimeInSeconds({
fps: 25,
loop: false,
mediaDurationInSeconds: 10,
playbackRate: 1,
src: 'https://remotion.media/video.mp4',
trimAfter: 200,
trimBefore: 100,
unloopedTimeInSeconds: 4.04,
ifNoMediaDuration: 'fail',
});
expect(timestamp).toBe(null);
});
test('should inhibit the same loop behavior as <Html5Video> - loop + trim after', () => {
const timestamp = getTimeInSeconds({
fps: 25,
loop: true,
mediaDurationInSeconds: 10,
playbackRate: 1,
src: 'https://remotion.media/video.mp4',
trimAfter: 200,
trimBefore: 100,
unloopedTimeInSeconds: 4.04,
ifNoMediaDuration: 'fail',
});
expect(timestamp).toBe(4.04);
});
test('should inhibit the same loop behavior as <Html5Video> - loop + no trim after', () => {
const timestamp = getTimeInSeconds({
fps: 25,
loop: true,
mediaDurationInSeconds: 10,
playbackRate: 1,
src: 'https://remotion.media/video.mp4',
trimAfter: undefined,
trimBefore: 100,
unloopedTimeInSeconds: 4.04,
ifNoMediaDuration: 'fail',
});
expect(timestamp).toBe(8.04);
});
test('should map trimAfter loop boundaries in the frame domain', () => {
const timestamp = getTimeInSeconds({
fps: 30,
loop: true,
mediaDurationInSeconds: 60.066667,
playbackRate: 1,
src: 'https://remotion.media/video-1m.mp4',
trimAfter: 1800,
trimBefore: 90,
unloopedTimeInSeconds: 1711 / 30,
ifNoMediaDuration: 'fail',
});
expect(timestamp).toBe(91 / 30);
});
test('should inhibit the same loop behavior as <Html5Video> - edge case', () => {
const timestamp = getTimeInSeconds({
fps: 25,
loop: false,
mediaDurationInSeconds: 10,
playbackRate: 1,
src: 'https://remotion.media/video.mp4',
trimAfter: 100,
trimBefore: 0,
unloopedTimeInSeconds: 4,
ifNoMediaDuration: 'fail',
});
expect(timestamp).toBe(null);
});