How to create an accelerated rewind effect ?

Bendr

New Member
Hello everyone!
I wanted to know if there is a filter or script that would allow me to apply an accelerated rewind effect to any video source? (If I need to combine several filters/plugins to achieve this effect, that's fine too).
It's a very specific request, but I haven't found any tips or plugins that would allow me to do it easily.

Thanks for your answers!
 

Suslik V

Active Member
"rewind" is resource demanding effect, because you need back in time. To back in time you need to save your source somewhere. Replay Buffer of OBS can save short fragments of what "happened" in the past. These fragments can be reversed in relatively short period of time. But modern encoders all were made in the way that it is hard to play them backwards (previous frame depends on more older frames that should be decoded first). Uncompressed frames (raw sources of OBS) are huge. So, it is demanding task.

Fast forwarded playback possible in Media Source (200%). Source Toolbar contains seeking bar for the media.

You need to be more specific about what kind of effect you need. OBS usually operates on live sources (gameplay or camera), so what you want to rewind? Maybe you are talking about "Instant Replay"?
 

Bendr

New Member
"rewind" is resource demanding effect, because you need back in time. To back in time you need to save your source somewhere. Replay Buffer of OBS can save short fragments of what "happened" in the past. These fragments can be reversed in relatively short period of time. But modern encoders all were made in the way that it is hard to play them backwards (previous frame depends on more older frames that should be decoded first). Uncompressed frames (raw sources of OBS) are huge. So, it is demanding task.

Fast forwarded playback possible in Media Source (200%). Source Toolbar contains seeking bar for the media.

You need to be more specific about what kind of effect you need. OBS usually operates on live sources (gameplay or camera), so what you want to rewind? Maybe you are talking about "Instant Replay"?
Thanks for your reply, I'll try to be more precise.
I need to keep about the last 20 minutes of my livestream (it's a lot, I know) and play the whole thing backwards very quickly (in 30 seconds maximum), without the sound and synchronize this video with an animation I've already made beforehand. The two videos will run at the same time to achieve the desired effect.

I had previously thought of using Exeldro's “Dynamic Delay” because it allows me to do exactly what I want, a fast backward after keeping a piece of my livestream in the buffer. But it's far too resource-intensive (5 seconds for about 5GB of Ram).

For the moment, I'm using the “Instant replay” function to keep the video in the buffer. It keeps the 20 minutes in the ram (2.5GB for 20 minutes) without any problem. But I'm missing the ability to play the video backwards very quickly.

As the video in the buffer is saved on the PC and played back as if it were a standard video, I was wondering if there wasn't an effect that just lets you play the video backwards, and another (or the same) that could speed up playback. I don't need it to do that at the same time as the replay, as it becomes a video in my recording folder.

Maybe I'm missing some crucial information, given your answer, it seems something “simple” on paper, but very complex to set up in practice.
 

koala

Active Member
You could write the replay buffer to disk, then use a tool such as ffmpeg to accelerate and reverse the written video file to some predefined output file name, then play back this file within OBS. I know of no plugin that will do this, so it's some kind of manual task to do.
To accelerate a video with ffmpeg: https://superuser.com/questions/1261678/how-do-i-speed-up-a-video-by-60x-in-ffmpeg
To reverse a video with ffmpeg: https://video.stackexchange.com/questions/17738/how-to-use-ffmpeg-command-for-reverse-video
 

Suslik V

Active Member
Even 30 sec is a long video for reverse with FFmpeg. It all will be decoded to RAM (uncompressed frames) and only then written back to the disk reversed. Splitting into fragments is questionable solution (additional read/write operations to slow storage) but simple and it works.

How fast your PC can write mpeg2video? For example, 10 min FullHD, 60 fps, re-encoded with FFmpeg -c:v mpeg2video -qscale:v 6 to mkv. How much time it takes? Just wondering.
 

Bendr

New Member
You could write the replay buffer to disk, then use a tool such as ffmpeg to accelerate and reverse the written video file to some predefined output file name, then play back this file within OBS. I know of no plugin that will do this, so it's some kind of manual task to do.
To accelerate a video with ffmpeg: https://superuser.com/questions/1261678/how-do-i-speed-up-a-video-by-60x-in-ffmpeg
To reverse a video with ffmpeg: https://video.stackexchange.com/questions/17738/how-to-use-ffmpeg-command-for-reverse-video
I've tried to look at ffmpeg. I have some options in the properties of my video file in OBS but nothing seems to work. If I use ffmpeg aside OBS, since the video file is already active with "instant-replay" I don't think this will rewrite the file to add the rewind and speed effect.
 

Bendr

New Member
Even 30 sec is a long video for reverse with FFmpeg. It all will be decoded to RAM (uncompressed frames) and only then written back to the disk reversed. Splitting into fragments is questionable solution (additional read/write operations to slow storage) but simple and it works.

How fast your PC can write mpeg2video? For example, 10 min FullHD, 60 fps, re-encoded with FFmpeg -c:v mpeg2video -qscale:v 6 to mkv. How much time it takes? Just wondering.
I downloaded this video: “https://www.youtube.com/watch?v=GT5-ME-qoe4” in 1080p 60 fps

With the command “ffmpeg -i ‘video.mp4’ ‘video.mkv’ -c:v mpeg2video -qscale:v 6”. This took 2 minutes and 47 seconds.

I guess for a rewind and speed effect of a 20-minute video, it will take much longer.

In view of the replies here, and that I've had on other forums, I imagine there's no way (or easy way) of making the process faster and less RAM-intensive than it is now.
 

khaver

Member
Here's what I would do. Record a scene as similar as possible to the appearance of what your live scene will look like. With it, create a highly distorted "rewind" effect in your video editing application of choice. Use this video in a scene called "rewind". When you want the effect simply switch to that scene. With all the distortion, your viewers may not even realize it's a fake rewind.
 

Suslik V

Active Member
I guess for a rewind and speed effect of a 20-minute video, it will take much longer.
No. I think, it will take only about 10 sec because source for reversion is only 30 sec long. Is it acceptable result? Also, it will take about 5.3GB of RAM space to store 30 sec of uncompressed video for reverse. RAM consumption can be reduced by lowering output FPS, resolution or duration.

Reading media backward in portions, from keyframe to keyframe, and picking only some frames (aka "random access") is task for NLE - I don't think that someone will write such "plugin" soon.

Anyway, command line may look like this (.bat or .cmd file). It uses both FFprobe.exe and FFmpeg.exe to calculate speed-up ratio. It reverses and speeds up any media file to fit it into fixed duration (in the example it is 15 sec @60fps, ~3.2GiB RAM), no sound, mpeg2 software encoder for compatibility:
Code:
:: turn off the command printing
@echo off

:: parameters for Input and Output, output duration longer than input duration
:: take in mind, output 30 sec 1080@60 for reversion is (4:2:0, 8-bit) 1920*1080*24/8/2*fps*duration
:: = ~5.3GiB RAM (+0.2GiB RAM for encoding and decoding the source)
set OUTFPS=60
set OUT_DUR_SEC=15
set FFPROBE_EXE=C:\ffmpeg\ffmpeg-4.3.1-win64-shared\bin\ffprobe.exe
set FFMPEG_EXE=C:\ffmpeg\ffmpeg-4.3.1-win64-shared\bin\ffmpeg.exe
set NORMAL_FILE=C:\Temp\input_file.mkv
set REV_FILE=C:\Temp\reversed.mkv

:: parse the "ffprobe.exe" output to get duration in seconds
for /F %%G in ('^""%FFPROBE_EXE%" -i "%NORMAL_FILE%" -v quiet -show_entries format^=duration -of csv^="p=0"^"') do set IN_DUR_SEC=%%G

:: parse the "ffprobe.exe" output to get fps
for /F %%G in ('^""%FFPROBE_EXE%" -i "%NORMAL_FILE%" -v quiet -select_streams v:0 -show_entries stream^=r_frame_rate -of csv^="p=0"^"') do set IN_FPS=%%G

:: show the result
echo %IN_DUR_SEC%
echo %IN_FPS%

:: !!! --- output file will be overwritten without confirmation --- !!!
:: speed it up and reverse with ffmpeg.exe
"%FFMPEG_EXE%" -y -i "%NORMAL_FILE%" -r %OUTFPS% -vf select='st(0,%IN_DUR_SEC%/%OUT_DUR_SEC%/(%OUTFPS%/%IN_FPS%));lt(n/ld(0)-trunc(n/ld(0)),floor(1/ld(0)*1000000)/1000000)',setpts='N/%OUTFPS%/TB',reverse -c:v mpeg2video -qscale:v 6 -an "%REV_FILE%"

:: comment or remove next line to not wait for keypress
pause
 
Top