Selur's Little Message Board
[HELP] ReplaceSingle (to replace multi) - Printable Version

+- Selur's Little Message Board (https://forum.selur.net)
+-- Forum: Hybrid - Support (https://forum.selur.net/forum-1.html)
+--- Forum: Problems & Questions (https://forum.selur.net/forum-3.html)
+--- Thread: [HELP] ReplaceSingle (to replace multi) (/thread-4084.html)

Pages: 1 2


RE: ReplaceSingle (to replace multi) - zspeciman - 20.05.2025

Thank you for providing a solution.  
I was ready to test this, but Hybrid doesn't accept the video anymore.
I am on Hybrid_dev_2025.05.18-84550
As soon as I add the video Hybrid exists

Will Replaceframe with Duplicate ever become part of Hybrid as you have done with ReplaceMultiple?


RE: ReplaceSingle (to replace multi) - Selur - 20.05.2025

Quote:As soon as I add the video Hybrid exists
no clue, why Hybrid would close, don't see anything in the debug output.

Quote:Will Replaceframe with Duplicate ever become part of Hybrid as you have done with ReplaceMultiple?
Maybe, not sure.

Cu Selur


RE: ReplaceSingle (to replace multi) - Selur - 20.05.2025

btw. for amusement:
def duplicateFrames(clip: vs.VideoNode, positions: list[int]) -> vs.VideoNode:
    # Sort and deduplicate positions in descending order to prevent index shifts
    positions = sorted(set(positions), reverse=True)

    for pos in positions:
        if pos < 0 or pos >= clip.num_frames - 1:
            raise ValueError(f"Position {pos} is invalid (must be between 0 and {clip.num_frames - 2}).")
        part1 = core.std.Trim(clip, 0, pos + 1)       # Frames 0 to pos (inclusive)
        dup = core.std.Trim(clip, pos + 1, pos + 1)   # Frame at pos + 1 to duplicate
        part3 = core.std.Trim(clip, pos + 2, None)    # Frames from pos + 2 to end
        clip = core.std.Splice([part1, dup, part3], mismatch=True)

    return clip
this would allow multiple frames,..
clip = duplicateFrames(clip,[7361, 7447])
would replace 7362 with a duplicate of 7361 and 7448 with a duplicate of 7747.

Cu Selur


RE: ReplaceSingle (to replace multi) - zspeciman - 21.05.2025

(19.05.2025, 14:54)Selur Wrote: Do:
# replaces frame x +1 with a duplicate of x
def duplicate(clip: vs.VideoNode, x: int) -> vs.VideoNode:
    part1 = core.std.Trim(clip, 0, x)          # Frames 0 to x (inclusive)
    replacement = core.std.Trim(clip, x, x)    # Only frame x (duplicate)
    part3 = core.std.Trim(clip, x + 2, None)   # Frames x+2 to end
    return core.std.Splice([part1, replacement, part3], mismatch=True)
return duplicate(clip, 7361)
is faster and works.
If you wanted to duplicate 7361 and 7447 you would use:
# replaces frame x +1 with a duplicate of x
def duplicate(clip: vs.VideoNode, x: int) -> vs.VideoNode:
    part1 = core.std.Trim(clip, 0, x)          # Frames 0 to x (inclusive)
    replacement = core.std.Trim(clip, x, x)    # Only frame x (duplicate)
    part3 = core.std.Trim(clip, x + 2, None)   # Frames x+2 to end
    return core.std.Splice([part1, replacement, part3], mismatch=True)
clip = duplicate(clip, 7361)
clip = duplicate(clip, 7447)
return clip

Cu Selur

It works great!!!  Thank you for helping.  A useful tool, on a wish list to be part of Hybrid someday


RE: ReplaceSingle (to replace multi) - Selur - 28.05.2025

Added an DuplicateFrames option to the latest dev.

Cu Selur


RE: ReplaceSingle (to replace multi) - zspeciman - 29.05.2025

Thank you for adding this feature.
There is still a problem.  If I put frame 7361 in the field.  I get 7361 and a duplicate 7362 (which is perfect), however old bad frame 7362 became new 7363 and old good frame 7363 becomes new frame 7364.  The video has one more frame than the original.


RE: ReplaceSingle (to replace multi) - Selur - 29.05.2025

Argh, must be a typo somewhere, I'll look at it.


RE: ReplaceSingle (to replace multi) - Selur - 29.05.2025

Should be fixed now (udated dev). (small index mistake)

Cu Selur