Resource icon

OBS Python Additional Replay Buffer 0.1

ODENYGG

New Member
This is a late contribution, but the original script lacks a function to capture several audio streams properly (if you have multiple audio streams configured). To change that, replace the line
Python:
"-vcodec", "copy", "-acodec", "copy", targetname]
with
Python:
"-map", "0?", "-vcodec", "copy", "-c:a", "copy", targetname]

Additionally, you can replace the FFMPEG file from moviepy with a newer version (the one it uses is quite old)
If you installed it using pip, the default location should be
C:\Users\"Your Name"\AppData\Local\Programs\Python\...\Lib\site-packages\imageio_ffmpeg\binaries
or wherever you installed Python to.
I. Love. You. I was desperate to find a solution for this, as it was making the script completely unusable for me. Thank you so much!
 

JohnCarson89

New Member
[additional-replays.py] ModuleNotFoundError: No module named 'moviepy'
Getting this error after attempting to run. Installed moviepy no problem, says it's already in there.
 

JohnCarson89

New Member
Got the above working, but I'm running into this issue.

[additional-replays.py] Traceback (most recent call last):
[additional-replays.py] File "C:/Program Files/obs-studio/data/obs-plugins/frontend-tools/scripts\additional-replays.py", line 154, in save_replay3
[additional-replays.py] subprocess.call([PKG_INSTALL_CMD_FULL])
[additional-replays.py] File "C:/Program Files/obs-studio/data/obs-plugins/frontend-tools/scripts\additional-replays.py", line 196, in save_replay
[additional-replays.py] path = None
[additional-replays.py] TypeError: must be str, not int
 

Suslik V

Active Member
@JohnCarson89 because there are too many versions of the same script, it is hard to tell what is wrong with yours.
Probably you forgot to set new destination (valid path) for new replays in the properties of the script itself (main menu Tools > Scripts > your_script).
 

newuxtreme

New Member
This is a late contribution, but the original script lacks a function to capture several audio streams properly (if you have multiple audio streams configured). To change that, replace the line
Python:
"-vcodec", "copy", "-acodec", "copy", targetname]
with
Python:
"-map", "0?", "-vcodec", "copy", "-c:a", "copy", targetname]

Additionally, you can replace the FFMPEG file from moviepy with a newer version (the one it uses is quite old)
If you installed it using pip, the default location should be
C:\Users\"Your Name"\AppData\Local\Programs\Python\...\Lib\site-packages\imageio_ffmpeg\binaries
or wherever you installed Python to.

I. Love. You. I was desperate to find a solution for this, as it was making the script completely unusable for me. Thank you so much!

@JohnCarson89 because there are too many versions of the same script, it is hard to tell what is wrong with yours.
Probably you forgot to set new destination (valid path) for new replays in the properties of the script itself (main menu Tools > Scripts > your_script).


Would so greatly appreciate some help here please!

So far :

1. Installed Python 3.9
2. Set up the script right afaik, set up hotkeys as Alt 1 (60s), 2(180s), 3 (300s)
3. Set up save folder
4. I have not understood how to update the ffmpeg file as suggested by @KittieCatKay

When I run OBS and press say Alt 1, it seems to just capture and save the overall replay buffer length I have so far which is beyond 5 mins even, so it's not exactly snipping right the way it should I think.

The function seems to do the SAME thing whether I press Alt 1 2 or 3.

If I press say Alt 1 first nothing really happened, no error or anything but it also only saved a 1 kb file of nothing.
Then if I press Alt 2 this error pops up :

1724351325469.png
 

Suslik V

Active Member
@newuxtreme the script has mistake when destination folder for "truncated" replays wasn't set at all (or was set the same as for the regular replays).

It uses FFmpeg v4.2.2, thus only supports codecs known to this version of FFmpeg.

Here is a bit newer, fixed version:

AdditionalReplays_0_2_2_beta_2024_08_23.zip, ~5KiB to download.
CRC of the zip archive MD5:5A54DFE2FF4564498EC844FCE2DA2CB5

inside:
"AdditionalReplays.py" (~20 KiB)

Usage (for test purposes):
  1. Look online for "Windows x86-64 embeddable zip file" of the Python and download it (the "python-3.6.8-embed-amd64.zip" file). Then unpack its contents to any suitable folder (I don't recommend Unicode symbols in the path). You'll see many files in your folder, like: "python.exe", "python3.dll" etc.
  2. Go to OBS Tools > Scripts > Python Settings tab , and set Python Install Path (64bit) to the folder from p1.
  3. Restart OBS.
  4. Go to OBS Tools > Scripts and add "AdditionalReplays.py" file.
  5. Click "Install moviepy with pip" button under the script's description. (3 cmd window will be opened one by one that downloads pip and all required modules for Python).
  6. Wait until message "Restart OBS, please" appear under the button from p5.
  7. Restart OBS.
  8. Set OBS Settings > Hotkeys "Replay 1", "Replay 2" and "Replay 3" hotkeys.
  9. Start Replay Buffer of OBS as usual. Click the "Replay 1" hotkey to save replay that will be cut on the fly to specified length.
Note. p5-p6 are optional and works only for mentioned version of Python. Of course, you may install all required modules manually, the "moviepy" and its dependencies (~160MiB including Python itself).

The tests were running in obsolete Windows OS, OBS v27+ 64-bit (custom build), with the embedded (that itself is not recommended for this use case) version of the Python v3.6.8. I didn't check the whole algorithm, so

As is.
 

Attachments

  • AdditionalReplays_0_2_2_beta_2024_08_23.zip
    4.7 KB · Views: 19

Suslik V

Active Member
Some old issues were triggered when new features implemented. So, new fixes (to old features) comes only with new features. New defaults and option names, so check your settings.

Here is a bit newer, also fixed version:
AdditionalReplays_0_3_1_beta_2024_09_19.zip, ~9KiB to download.
CRC of the zip archive MD5:2120ED7A37CB0DA8B2B9A37058760193

inside:
"AdditionalReplays.py" (~36 KiB)

Usage is the same as written one post above.

Changes:
* "modification" instead of "creation" time in checks for the "new file is ready!" routine. Useful only for replays that has static (constant) names, and no new file ever being created.
Tech details: os.path.getmtime() vs os.path.getctime() in use.​
* the script will not crash if replay media remains busy for a long.
Tech details: now the file-ready check returns null object when all attempts fails, instead of returning real filename that itself remains in use by other threads.​
- the option name "from which end to cut media from" was renamed to become more clear.
Tech details: I mistaken in it too, so now it is named "Drop begin, preserve end".​
- new Defaults.
Tech details: everyone needs last seconds in replay, not unknown first. Useful for live events.​
+ optional Instant Replay functionality. Last truncated replay goes to selected source of OBS.
Tech details: only VLC Video Source is supported because it allows playlists that itself used for the next feature...​
+ ...optional reversed playback of last replay. Short media file plays before actual replay in VLC. Creates kind of "rewind" effect.
Tech details: last replay sped-up to fit into ~2.5 sec, and then reversed. Requires ~0.5 GiB of RAM. Takes some time for encoding.​
+ when job is done script generates hotkey press event for internals of OBS.
Tech details: hotkey "Ctrl + Alt + Num7" triggered when replay is ready.​

Was tested only on Windows, Python v3.6.8.
 

Attachments

  • AdditionalReplays_0_3_1_beta_2024_09_19.zip
    8.6 KB · Views: 40
Last edited:

tzerony

New Member
I am getting following errors:
[Unknown Script] Traceback (most recent call last):
[Unknown Script] File "C:\Program Files/obs-studio/data/obs-plugins/frontend-tools/scripts\AdditionalReplays.py", line 410, in save_replay1
[Unknown Script] save_replay(replay1_seconds, replay1_dir, replay1_remove, replay1_from_end, replay1_rev)
[Unknown Script] File "C:\Program Files/obs-studio/data/obs-plugins/frontend-tools/scripts\AdditionalReplays.py", line 491, in save_replay
[Unknown Script] duration, in_fps = ffmpeg_get_clip_dur(last_replay)
[Unknown Script] File "C:\Program Files/obs-studio/data/obs-plugins/frontend-tools/scripts\AdditionalReplays.py", line 253, in ffmpeg_get_clip_dur
[Unknown Script] from moviepy.editor import VideoFileClip
[Unknown Script] ModuleNotFoundError: No module named 'moviepy.editor'

moviepy is properly installed...
 

Suslik V

Active Member
@tzerony you are using moviepy==2.0.0 or newer, where location/import/structure of modules was changed. So, the script needs to be adapted to take into account these changes. Original script expects moviepy==1.0.3 (from May 2020). You may install it instead until script will be adapted to be compatible with new moviepy module.
 

Suslik V

Active Member
AdditionalReplays_0_3_7_beta_2024_11_25.zip, ~9KiB to download.
CRC of the zip archive MD5:A69CAFA51A2FA60C32FF12C3500666E2

inside:
"AdditionalReplays.py" (~40 KiB)

Usage is the same as written a few posts above ( here: https://obsproject.com/forum/threads/additional-replay-buffer.106619/post-657013 ).

Changes:
* changes in moviepy imports to support versions newer than 1.0.3.
Tech details: now sub-modules import done in universal way to ease future transfer to moviepy==2.0.0. Right now I tested it only with moviepy==1.0.3, but you may give it a try.​
- visual grouping of replay's properties. Easier to modify options.
Tech details: UI elements now grouped by replay number or separated with disabled/empty block. Uses more screen space because of decorations and alignment. The script listing increased again.​
+ minor changes in the script listing and fixing typos.
Tech details: I can easily forget where global/local variables were initialized first, so more explicit definitions of globals where they are really global. It doesn't changes logic but can ease future modifications for me.​

Was tested only under the Windows OS, Python v3.6.8, moviepy==1.0.3, imageio==2.15.0, imageio-ffmpeg==0.4.9.
 

Attachments

  • AdditionalReplays_0_3_7_beta_2024_11_25.zip
    8.9 KB · Views: 10
Last edited:

Wippito

New Member
Hi all. I found this script and its very usefull for me, but i have a problem. Everything works fine, except videos are lagging first and last couple of seconds, if i check "Drop begin, preserve end" box. If this checkbox is unchecked, video doesnt lag, but it starts and ends too early (my main buffer is 15mins, with unchecked box i got video of what happened 14-15 min ago). any fixes?
windows 11, Python v3.6.8
 

Suslik V

Active Member
@Wippito please, clarify what is happening and where you see it. The cut is not precise and only done at keyframes. The only difference between the options is that the media file of the recently saved replay either read from start or seek to the first nearby keyframe. Seeking time can be improved if you shorten distance (interval) between keyframes during encoding and eliminate B-frames usage. Faster disk also helps.
 
Last edited:

Wippito

New Member
@Wippito please, clarify what is happening and where you see it. The cut is not precise and only done at keyframes. The only difference between the options is that the media file of the recently saved replay either read from start or seek to the first nearby keyframe. Seeking time can be improved if you shorten distance (interval) between keyframes during encoding and eliminate B-frames usage. Faster disk also helps.
thanks for reply, suslik. can we continue in russian? i dont think i can explain it in english
 

Wippito

New Member
@Wippito please, clarify what is happening and where you see it. The cut is not precise and only done at keyframes. The only difference between the options is that the media file of the recently saved replay either read from start or seek to the first nearby keyframe. Seeking time can be improved if you shorten distance (interval) between keyframes during encoding and eliminate B-frames usage. Faster disk also helps.
Anyways, i will try to explain it in english and then duplicate it in russian. so the problem appears in all 3 additional videos - first and last second of the videos are laggy, it takes 5 seconds to play first second of the video. its not about precision, its about lags. if i enable "Drop begin, preserve end", lags dissapear, but (like u said) replay file read from start i believe. Unfortunatelly, i cant attach video here, also i cant upload it on youtube, because yt converts file and no lags are visible.
---
В общем, проблема в том, что на дополнительных видео, которые создает этот скрипт, первая и последняя секунды дико лагают и воспроизводятся очень долго. Я менял Б-кадры, битрейт, путь сохранения, записывал на м2 ссд. Менял предустановки, регулировки, профиль, многопроходный режим, включал/выключал психовизуалоизалькую корректировку. Лагов становится меньше (но они не исчезают) с битрейтом 500. Прикрепить видео не получается, максимум - могу залить куда-то на диск и скинуть ссылку
 

Suslik V

Active Member
@Wippito Hardware encoder? I don't know, x264 works just fine (not hybrid but fragmented). Of course, you may try to update your FFmpeg executable from the "imageio_ffmpeg/binaries" folder of the Python installation before giving up. Simple renaming will work fine if this is Windows OS. At least, .exe from the "ffmpeg-7.0.2-essentials" build easily replaces "ffmpeg-win64-v4.2.2.exe". For other platforms you better look at "imageio_ffmpeg/_definitions.py" file for details. All mentined paths and filenames are valid for imageio-ffmpeg==0.4.9.
 

Wippito

New Member
@Wippito Hardware encoder? I don't know, x264 works just fine (not hybrid but fragmented). Of course, you may try to update your FFmpeg executable from the "imageio_ffmpeg/binaries" folder of the Python installation before giving up. Simple renaming will work fine if this is Windows OS. At least, .exe from the "ffmpeg-7.0.2-essentials" build easily replaces "ffmpeg-win64-v4.2.2.exe". For other platforms you better look at "imageio_ffmpeg/_definitions.py" file for details. All mentined paths and filenames are valid for imageio-ffmpeg==0.4.9.
i use NVIDIA NVENC HEVC, mpeg-4. x264 lags aswell. i cant find FFmped directory, can you please send me full path? there s no folder named anything like ffmpeg in the python folder
 

Suslik V

Active Member
AdditionalReplays_0_3_8_beta_2024_12_06.zip, ~9KiB to download.
CRC of the zip archive MD5:542B83759A45F67A7C37B3A4B815FF2C

inside:
"AdditionalReplays.py" (~40 KiB)

Usage is the same as written a few posts above ( here: https://obsproject.com/forum/threads/additional-replay-buffer.106619/post-657013 ).

Changes:
* VLC sources named "Disabled" no longer treated as valid when 'Disabled' option is selected.
Tech details: DropBox list type was changed from OBS_COMBO_TYPE_EDITABLE to OBS_COMBO_TYPE_LIST, because in my setup editable lists saves keys instead of values in the tables.​
- VLC source selection option for Instant Replays renamed from "Disabled" to "Disable".
Tech details: verb instead of adjective.​

Was tested only under the Windows OS, Python v3.6.8, moviepy==1.0.3, imageio==2.15.0, imageio-ffmpeg==0.4.9.
 

Attachments

  • AdditionalReplays_0_3_8_beta_2024_12_06.zip
    8.9 KB · Views: 10
Top