Log in

View Full Version : Vapoursynth: Remove Scene Change Frames


jay123210599
19th January 2025, 17:04
How do I detect scene changes and either avoid or remove them in vspreview? This is for both interlaced and progressive videos.

_Al_
19th January 2025, 21:47
Your questions have nothing to do with vspreview, just in case why are you wandering why folks do not answer more frequently. Basically all questions you have are about vapoursynth scripts.

Title question: "How do I create scene changes for a vapoursynth clip"
Answer: Perhaps the one that is included in "misc" (miscellaneous) package plugin, "MiscFilter.dll", download here (https://github.com/vapoursynth/vs-miscfilters-obsolete/releases/tag/R2), docs here (https://github.com/vapoursynth/vs-miscfilters-obsolete/blob/master/docs/misc.rst)
usage:clip = core.misc.SCDetect(clip)
that creates two clip properties: _SceneChangePrev and _SceneChangeNext that code or other plugins work with, they check those props, if they are 0 or 1

Title question: "How to delete scene changes in my vapoursynth script for a clip"
Answer: Delete those just mentioned clip properties.
clip = clip.std.RemoveFrameProps(["_SceneChangePrev", "_SceneChangeNext"])

jay123210599
19th January 2025, 22:17
Your questions have nothing to do with vspreview, just in case why are you wandering why folks do not answer more frequently. Basically all questions you have are about vapoursynth scripts.

Title question: "How do I create scene changes for a vapoursynth clip"
Answer: Perhaps the one that is included in "misc" (miscellaneous) package plugin, "MiscFilter.dll", download here (https://github.com/vapoursynth/vs-miscfilters-obsolete/releases/tag/R2), docs here (https://github.com/vapoursynth/vs-miscfilters-obsolete/blob/master/docs/misc.rst)
usage:clip = core.misc.SCDetect(clip)
that creates two clip properties: _SceneChangePrev and _SceneChangeNext that code or other plugins work with, they check those props, if they are 0 or 1

Title question: "How to delete scene changes in my vapoursynth script for a clip"
Answer: Delete those just mentioned clip properties.
clip = clip.std.RemoveFrameProps(["_SceneChangePrev", "_SceneChangeNext"])

Does this answer this question, too?
https://forum.doom9.org/showthread.php?t=186071

Do I need both clip = core.misc.SCDetect(clip) and clip = clip.std.RemoveFrameProps(["_SceneChangePrev", "_SceneChangeNext"]) to remove scene changes (or frames where the scene changes) from videos?

Z2697
20th January 2025, 08:05
are you trying to remove the scenechange flags or the actual frames
why
if 2 scenes are different there's always gonna be scenechange if you remove one frame next frame is scenechange unless you removed the whole scene

jay123210599
20th January 2025, 11:20
are you trying to remove the scenechange flags or the actual frames
why
if 2 scenes are different there's always gonna be scenechange if you remove one frame next frame is scenechange unless you removed the whole scene

the actual frame where the scene changes. Like, for example, the 239th frame is the last frame for a scene in a video, then the 240th frame is the first frame for a new one, so I want to remove the 240th frame.

hello_hello
20th January 2025, 14:59
the actual frame where the scene changes. Like, for example, the 239th frame is the last frame for a scene in a video, then the 240th frame is the first frame for a new one, so I want to remove the 240th frame.

Doesn't that mean the 241st frame then becomes the first frame for a new scene instead?

I could understand it if for some reason the frames on scene changes had issues, but if that's not the case it's hard to see the logic behind what you want to do.

jay123210599
20th January 2025, 15:20
are you trying to remove the scenechange flags or the actual frames
why
if 2 scenes are different there's always gonna be scenechange if you remove one frame next frame is scenechange unless you removed the whole scene

Doesn't that mean the 241st frame then becomes the first frame for a new scene instead?

I could understand it if for some reason the frames on scene changes had issues, but if that's not the case it's hard to see the logic behind what you want to do.

That's exactly what I'm trying to do. I have 5 videos that I'm trying to compare in vspreview, but there's a problem with the first video. It was initially one frame ahead of the rest, but then it become two frames ahead, then three, then four, then seven, then ten, and the number of frames it's ahead of the rest keeps increasing, all because of the scene changing frames. That's why I want to remove the first frames where the scenes change in my video.

Z2697
20th January 2025, 17:02
core.std.DeleteFrames
Come up a script to generate a list of I frame numbers then use it.

jay123210599
20th January 2025, 18:27
core.std.DeleteFrames
Come up a script to generate a list of I frame numbers then use it.

Not all I frames from my video are scene changing frames, though.

hello_hello
20th January 2025, 19:02
That's exactly what I'm trying to do. I have 5 videos that I'm trying to compare in vspreview, but there's a problem with the first video. It was initially one frame ahead of the rest, but then it become two frames ahead, then three, then four, then seven, then ten, and the number of frames it's ahead of the rest keeps increasing, all because of the scene changing frames. That's why I want to remove the first frames where the scenes change in my video.

Just to be pedantic.... if it's getting further and further ahead of the others it'd mean it has fewer frames rather than more, so you'd either have to delete frames from the other four videos or add frames to the first one.

Fortunately repeating a single frame right before a scene change tends not to be very noticeable.

jay123210599
20th January 2025, 20:45
core.std.DeleteFrames
Come up a script to generate a list of I frame numbers then use it.

How do I make a script that will generate a list of frame numbers where the scene changes?

poisondeathray
20th January 2025, 21:03
How do I make a script that will generate a list of frame numbers where the scene changes?

You can try this
https://forum.doom9.org/showthread.php?t=166769


log: The name of the log file to output.
If this is set, the frame numbers applicable to a scene change are outputted as a text.
Describing full path is recommended.
(default is unset)

jay123210599
20th January 2025, 22:53
You can try this
https://forum.doom9.org/showthread.php?t=166769

How do I use it, exactly?

_Al_
21st January 2025, 00:51
Did you actually read the thread?
Post #27 does exactly what you asked for.
It prints SC_SCD.TXT with frame numbers.
Or you can just add some lines and get python list as well:
sd_list = []
and under line where it write number to a SC_SCD.TXT, you just add :sd_list.append(i)

jay123210599
21st January 2025, 03:07
Did you actually read the thread?
Post #27 does exactly what you asked for.
It prints SC_SCD.TXT with frame numbers.
Or you can just add some lines and get python list as well:
sd_list = []
and under line where it write number to a SC_SCD.TXT, you just add :sd_list.append(i)

Do I put it in .vpy file, or a .py file? What do I do when I enter it in?

_Al_
21st January 2025, 03:29
if having a *.py then
1.run that python file: in command line:
python "my_script.py"

2.again using *.py and any python editor, the most simple would be IDLE, you might have it already installed with python, but not sure about that, you might had to enable it while installing python

then you just open IDLE , load your script and simply run it by pressing F5 or in menu run/ run module
or just right click your script in widows file browser, and select "Edit with IDLE"

3. Using *.vpy or *.py, technically you could even use vspreview to run your script. You load that script.
Then seemingly nothing would happen because script would be running to calculate and writing your frames. Only when done with that, you'd see frame number 0 and you could preview that clip.

jay123210599
21st January 2025, 05:47
if having a *.py then
1.run that python file: in command line:
python "my_script.py"

2.again using *.py and any python editor, the most simple would be IDLE, you might have it already installed with python, but not sure about that, you might had to enable it while installing python

then you just open IDLE , load your script and simply run it by pressing F5 or in menu run/ run module
or just right click your script in widows file browser, and select "Edit with IDLE"

3. Using *.vpy or *.py, technically you could even use vspreview to run your script. You load that script.
Then seemingly nothing would happen because script would be running to calculate and writing your frames. Only when done with that, you'd see frame number 0 and you could preview that clip.

I tried running the script in vspreview, but I got these warnings and an error:
2025-01-20 20:43:32.881: root: WARNING: Failed to load C:\Users\User\AppData\Roaming\VapourSynth\plugins64\scenechange.dll. GetLastError() returned 193.
2025-01-20 20:43:32.881: root: WARNING: Failed to load C:\Users\User\AppData\Roaming\VapourSynth\plugins64\temporalsoften2.dll. GetLastError() returned 193.
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

How do I fix this? Where can I download the 64bit versions of scenechange.dll and temporalsoften2.dll? The old link to them had expired.
https://uloz.to/x6gvxpbB/scenechange-win64-7z

Z2697
21st January 2025, 07:22
that plugin is similar to the one in "misc".

there's a handful of methods that can be used to detect scenechange. as of now I prefer the one in mvtools and some of the NN models trained by styler00dollar

jay123210599
21st January 2025, 17:42
that plugin is similar to the one in "misc".

there's a handful of methods that can be used to detect scenechange. as of now I prefer the one in mvtools and some of the NN models trained by styler00dollar

Know any other methods to detect scene change with Vapoursynth?

_Al_
21st January 2025, 17:46
2025-01-20 20:43:32.881: root: WARNING: Failed to load C:\Users\User\AppData\Roaming\VapourSynth\plugins64\scenechange.dll. GetLastError() returned 193.
2025-01-20 20:43:32.881: root: WARNING: Failed to load C:\Users\User\AppData\Roaming\VapourSynth\plugins64\temporalsoften2.dll. GetLastError() returned 193.
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
scenechange.dll is for that Chikuzen scene change filter: https://forum.doom9.org/showthread.php?t=166769
but MiscFilter.dll is for Myrsloiks (vapoursynth author) filter. What I remember it suppose to be based on that Chikuzen filter or similar (heck, it is always the same, comparing stats perhaps, average with thresholds). He said his might be a bit faster, so using it.
scenechange.dll and use: core.scd.Detect
or MiscFilter.dll and use: core.misc.SCDetect
If first does not work use Myrsloiks filter.

Also reading Myrsloik mentioning not using TemporalSoften2, not sure why or what should be used instead, might look for an alternative.

jay123210599
21st January 2025, 18:33
2025-01-20 20:43:32.881: root: WARNING: Failed to load C:\Users\User\AppData\Roaming\VapourSynth\plugins64\scenechange.dll. GetLastError() returned 193.
2025-01-20 20:43:32.881: root: WARNING: Failed to load C:\Users\User\AppData\Roaming\VapourSynth\plugins64\temporalsoften2.dll. GetLastError() returned 193.
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
scenechange.dll is for that Chikuzen scene change filter: https://forum.doom9.org/showthread.php?t=166769
but MiscFilter.dll is for Myrsloiks (vapoursynth author) filter. What I remember it suppose to be based on that Chikuzen filter or similar (heck, it is always the same, comparing stats perhaps, average with thresholds). He said his might be a bit faster, so using it.
scenechange.dll and use: core.scd.Detect
or MiscFilter.dll and use: core.misc.SCDetect
If first does not work use Myrsloiks filter.

Also reading Myrsloik mentioning not using TemporalSoften2, not sure why or what should be used instead, might look for an alternative.

But what do I do to solve the error? Where can I find the 64 bit versions of those .dll files? The old link to them had expired.

_Al_
21st January 2025, 19:37
Using first link that was posted in this thread.

jay123210599
21st January 2025, 22:50
Using first link that was posted in this thread.

You mean this? https://www.mediafire.com/?dnld4p98i333idp
I put them in my VapourSynth\plugins64 folder and that's where I got my "WARNING: Failed to load" messages.

I want to download this but it said "404 - Page not found".
https://uloz.to/x6gvxpbB/scenechange-win64-7z

_Al_
22nd January 2025, 02:05
First response in this thread by me, post #2:

Title question: "How do I create scene changes for a vapoursynth clip"
Answer: Perhaps the one that is included in "misc" (miscellaneous) package plugin, "MiscFilter.dll", download here (https://github.com/vapoursynth/vs-miscfilters-obsolete/releases/tag/R2), docs here (https://github.com/vapoursynth/vs-miscfilters-obsolete/blob/master/docs/misc.rst)
usage:
clip = core.misc.SCDetect(clip)
Seriously , I am not sure if you do this on purpose or not ... :-)

jay123210599
22nd January 2025, 05:11
First response in this thread by me, post #2:

Seriously , I am not sure if you do this on purpose or not ... :-)

Can it detect the frame numbers where the scene changes?

_Al_
22nd January 2025, 16:00
You can interchange it with core.scd.Detect, it works the same, scripts are the same. You can even see that in posted example in that Chikuzen version thread. Post #27.
https://forum.doom9.org/showpost.php?p=1814586&postcount=27
Both versions are even posted in that script. But of course one is commented out from the script.

jay123210599
22nd January 2025, 17:36
You can interchange it with core.scd.Detect, it works the same, scripts are the same. You can even see that in posted example in that Chikuzen version thread. Post #27.
https://forum.doom9.org/showpost.php?p=1814586&postcount=27
Both versions are even posted in that script. But of course one is commented out from the script.

This is my script.

import vapoursynth as vs
core = vs.get_core()

ret = core.ffms2.Source(source="C:\Users\User\Downloads\[BDMV][JAPANESE BLU-RAY]\JAPANESE_BLU-RAY_BDBOX_01\BDMV\STREAM\00000.m2ts")

ret = core.misc.SCDetect(clip=ret, threshold=0.15)

fstats = open ('SC.txt', 'w', encoding='utf-8', errors='strict')
fstats.write('frame_no\n')
for i in range (ret.num_frames):
if ret.get_frame(i).props._SceneChangePrev == 1 :
fstats.write('{}\n'.format(i))
fstats.close()

ret=core.text.FrameProps(clip=ret, alignment=3)#, props
ret.set_output()

Any problems with that causing this error:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

My video is interlaced, by the way.

_Al_
22nd January 2025, 18:55
maybe:
source=r"C:\Users\User ......
If backslashes in the path then there has to be that "r" in front.
If you used forward slashes, you do not have to.

What are you using to run script, btw., if using proper app, like in cmd using python ..., or running a script using a python editor, you get more informative error messages.
This is a common theme, folks using vapoursynth previewers not getting proper feedbacks.

I do not know about script correctness in terms of function, or what you are trying to do, just guessing syntaxerror.

jay123210599
22nd January 2025, 23:28
maybe:
source=r"C:\Users\User ......
If backslashes in the path then there has to be that "r" in front.
If you used forward slashes, you do not have to.

What are you using to run script, btw., if using proper app, like in cmd using python ..., or running a script using a python editor, you get more informative error messages.
This is a common theme, folks using vapoursynth previewers not getting proper feedbacks.

I do not know about script correctness in terms of function, or what you are trying to do, just guessing syntaxerror.

I added r in front and made few edits but it now works!

jay123210599
23rd January 2025, 15:42
maybe:
source=r"C:\Users\User ......
If backslashes in the path then there has to be that "r" in front.
If you used forward slashes, you do not have to.

What are you using to run script, btw., if using proper app, like in cmd using python ..., or running a script using a python editor, you get more informative error messages.
This is a common theme, folks using vapoursynth previewers not getting proper feedbacks.

I do not know about script correctness in terms of function, or what you are trying to do, just guessing syntaxerror.

But now, can you help me with this? https://forum.doom9.org/showthread.php?t=186071