I'm building simple informative website for the browser. In this website I'm using video in the background the page look interesting. The problem is I wanted to video work in a certain sequence:
I can't find optimal way to do it.
I'm developing website on Next JS, but any abstract suggestion will work.
const playForward = () => {
const video = videoRef.current!;
if (loopIntervalRef.current) {
clearInterval(loopIntervalRef.current);
}
//@ts-ignore
loopIntervalRef.current = setInterval(() => {
if (video.currentTime >= video.duration) {
playBack();
} else {
video.currentTime += 0.04;
}
}, 120);
};
const playBack = () => {
const video = videoRef.current!;
if (loopIntervalRef.current) {
clearInterval(loopIntervalRef.current);
}
//@ts-ignore
loopIntervalRef.current = setInterval(() => {
if (video.currentTime <= reversePoint) {
playForward();
} else {
video.currentTime -= 0.04;
}
}, 120);
};
It works almost perfectly, but video lagging sometimes while playing reverse.
I think you should have two copies of the video, one normal and one reversed and to toggle between the two when they reach the end.
Luckily, the well known ffmpeg utility can create a copy in reverse using the following syntax...
ffmpeg -i /storage/emulated/0/ffvid/frameCount.mp4 -vf reverse -af areverse reversed.mp4
As informed on this page.