Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th October 2020, 16:00   #4041  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,625
Quote:
Originally Posted by Jukus View Post
Is there no way to use ffmpeg filters inside a script?

What filter(s) do you need that are not available natively ?

If you need to apply an exclusive ffmpeg filter, and there isn't something similar already available - ffmpeg output can be piped to a vs script (vsrawsource input), and that can be piped back into ffmpeg with vspipe or native ffmpeg vpy demuxer
poisondeathray is offline   Reply With Quote
Old 12th October 2020, 16:37   #4042  |  Link
Jukus
Registered User
 
Join Date: Jul 2019
Location: Russia
Posts: 88
Quote:
Originally Posted by poisondeathray View Post
What filter(s) do you need that are not available natively ?
I searched for something autolevels and didn't find it.

I am trying to fix videos where good, normal scenes and very dark scenes are constantly alternating. I tried using "-vf pp=al", it just got a little better. Even if try to manually set the brightness and contrast values for a specific frame, then get disgusting grains, noise and others. I would be glad to have advice for this situation.

Last edited by Jukus; 12th October 2020 at 16:42.
Jukus is offline   Reply With Quote
Old 12th October 2020, 17:38   #4043  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,625
Quote:
Originally Posted by Jukus View Post
I searched for something autolevels and didn't find it.

I am trying to fix videos where good, normal scenes and very dark scenes are constantly alternating. I tried using "-vf pp=al", it just got a little better. Even if try to manually set the brightness and contrast values for a specific frame, then get disgusting grains, noise and others. I would be glad to have advice for this situation.
I looked and couldn't find any either...

There are several "auto" leveling plugins in avisynth; if you're on windows you can use those in the vpy script. Avisynth+ is supposed to be crossplatform now, but I'm not sure if you can load avs plugins into vpy scripts on other platforms than Win

The ffmpeg/vpy piping back and forth workaround is not ideal; lots of overhead piping back and forth.
poisondeathray is offline   Reply With Quote
Old 12th October 2020, 19:49   #4044  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 370
Just as a curiosity sort of, you could pipe ffmpeg cmd line in vapoursynth directly in your script.
It is not ideal, it is one way only, no searching etc.
vs script is always python script so all python woo-doo is available in vs script as well. Not sure how many folks realize that.
Code:
import vapoursynth as vs
from vapoursynth import core
import subprocess
import ctypes

ffmpeg = r'C:\tools\ffmpeg.exe'
source_path=r'C:\videos\video.mp4'
clip = core.lsmas.LibavSMASHSource(source_path) #this clip is not not needed, just to get width and height
clip = core.std.BlankClip(clip)

w = clip.width
h = clip.height
Ysize  = w * h
UVsize = w * h//4
frame_len = w * h * 3 // 2 #YUV420

command = [ ffmpeg, '-i', source_path,'-vcodec', 'rawvideo', '-pix_fmt', 'yuv420p',  '-f', 'rawvideo', '-']
pipe = subprocess.Popen(command, stdout = subprocess.PIPE, bufsize=frame_len)

def load_frame(n,f):
    try:
        vs_frame = f.copy()
        for i, size in enumerate([Ysize, UVsize, UVsize]):
            ctypes.memmove(vs_frame.get_write_ptr(i), pipe.stdout.read(size),  size)
        pipe.stdout.flush()
    except Exception as e:
        raise ValueError(repr(e))    
    return vs_frame

try:
    clip = core.std.ModifyFrame(clip, clip, load_frame)
except ValueError as e:
    pipe.terminate()
    print(e)

clip.set_output()
_Al_ is offline   Reply With Quote
Old 12th October 2020, 19:57   #4045  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
VideoNode has a member function called output(), see: https://github.com/IFeelBloated/Oyst...a/Alpha.py#L49
feisty2 is offline   Reply With Quote
Old 12th October 2020, 20:36   #4046  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 370
yes, thats much better, using some filters on clip and then give it to ffmpeg:
Code:
import vapoursynth as vs
from vapoursynth import core
import subprocess

ffmpeg = r'C:\tools\ffmpeg.exe'
source_path=r'C:\videos\video.mp4'
clip = core.lsmas.LibavSMASHSource(source_path)

clip = clip.std.Expr(['x 20 -','',''])  #just to demonstrate using some filters before ffmpeg

ffmpeg_cmd = [ffmpeg, '-f', 'yuv4mpegpipe', '-i', '-','-c:v', 'libx264', 'F:\OUT\output.mp4']
process = subprocess.Popen(ffmpeg_cmd, stdin=subprocess.PIPE)
clip.output(process.stdin, y4m = True)
process.communicate()
_Al_ is offline   Reply With Quote
Old 12th October 2020, 20:59   #4047  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 370
or how about this,
vs -> ffmpeg -> prores - > vs again -> vspipe -> whatever
is it too crazy?
Code:
import vapoursynth as vs
from vapoursynth import core
import subprocess

ffmpeg = r'C:\tools\ffmpeg.exe'
INTERMEDIATE = 'F:\OUT\prores.mov'
source_path=r'C:\videos\video.mp4'
clip = core.lsmas.LibavSMASHSource(source_path)
clip = clip.std.Expr(['x 20 -','',''])  #just to demonstarte using some filter before ffmpeg

ffmpeg_cmd = [ffmpeg, '-f', 'yuv4mpegpipe', '-i', '-', '-c:v', 'prores', '-an', '-y', INTERMEDIATE]
process = subprocess.Popen(ffmpeg_cmd, stdin=subprocess.PIPE)
clip.output(process.stdin, y4m = True)
process.communicate()

clip = core.lsmas.LibavSMASHSource(INTERMEDIATE)
clip = clip.std.Expr(['x 20 +','','']) #yet some more filters
clip.set_output()
technically , that ffmpeg could be piped into vs again like my example #1, not needing prores ...

Last edited by _Al_; 12th October 2020 at 23:19.
_Al_ is offline   Reply With Quote
Old 12th October 2020, 21:09   #4048  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
prores is lossy, ffv1 is probably better for your purpose
feisty2 is offline   Reply With Quote
Old 13th October 2020, 01:34   #4049  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 370
Quote:
VideoNode has a member function called output(), see: https://github.com/IFeelBloated/Oyst...a/Alpha.py#L49
What would be the purpose for that Materialize()? Function takes a clip, stores raw data on disk, then reads those data into same clip and that is returned. What is the Inject wrapper?

Oh, I guess it is used for more instances, only one time created.

Last edited by _Al_; 13th October 2020 at 01:54.
_Al_ is offline   Reply With Quote
Old 13th October 2020, 02:16   #4050  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
@Inject can dynamically inject any property into native types in python (stuff like list, or VideoNode), this is not normally allowed by python
Materialize() is used to speed up very slow scripts, it materializes intermediate results so they won’t be re-evaluated once things exceed max memory limit
feisty2 is offline   Reply With Quote
Old 14th October 2020, 14:27   #4051  |  Link
Jukus
Registered User
 
Join Date: Jul 2019
Location: Russia
Posts: 88
How can make a smooth transition between different filters? For example:
Code:
clip1 = core.std.Trim(clip, 6223, 8361)
clip1 = adjust.Tweak(clip1, hue=0.0, sat=1.3, bright=8.0, cont=1.1, coring=True)

clip2 = core.std.Trim(clip, 8362, 9887)
clip2 = adjust.Tweak(clip2, hue=0.0, sat=1.4, bright=15.0, cont=1.3, coring=True)
That is, it would not be an instant change, but a smooth transition within 100 frames.
Jukus is offline   Reply With Quote
Old 14th October 2020, 16:13   #4052  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,625
Quote:
Originally Posted by Jukus View Post
How can make a smooth transition between different filters? For example:
Code:
clip1 = core.std.Trim(clip, 6223, 8361)
clip1 = adjust.Tweak(clip1, hue=0.0, sat=1.3, bright=8.0, cont=1.1, coring=True)

clip2 = core.std.Trim(clip, 8362, 9887)
clip2 = adjust.Tweak(clip2, hue=0.0, sat=1.4, bright=15.0, cont=1.3, coring=True)
That is, it would not be an instant change, but a smooth transition within 100 frames.
You can use CrossFade from kagefunc
poisondeathray is offline   Reply With Quote
Old 14th October 2020, 18:40   #4053  |  Link
Jukus
Registered User
 
Join Date: Jul 2019
Location: Russia
Posts: 88
Quote:
Originally Posted by poisondeathray View Post
You can use CrossFade from kagefunc
No, need a smooth transition from some adjust settings to others, not frame blending.
Jukus is offline   Reply With Quote
Old 14th October 2020, 18:44   #4054  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,625
Quote:
Originally Posted by Jukus View Post
No, need a smooth transition from some adjust settings to others, not frame blending.
That's what it does, a smooth transition, if the base clip is the same "clip"

Think of it like this:

You have 1 clip. But 2 filtered versions.

1st clip fades out, but 2nd clip fades in , so the filter transition is applied smoothly over period "x"



If that doesn't do what you want, another way would be to write an animation helper function in python, using std.FrameEval . I'm not strong in python , someone can help you with that

Last edited by poisondeathray; 14th October 2020 at 18:56.
poisondeathray is offline   Reply With Quote
Old 14th October 2020, 22:13   #4055  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,625
Here is an example of an parameter animation helper function, using tweak's sat .

Interpolation is linear from startframe to endframe , from sat0 to sat1 . (In this example from frame 100 to frame 160, sat=1 to sat=3)

You can add other parameters, but linear interpolation and animation does not necessarily work with all parameters for all types of filters

Code:
import vapoursynth as vs
import adjust
import functools
core = vs.get_core()

c = core.colorbars.ColorBars(format=vs.YUV444P10)
c = core.std.SetFrameProp(c, prop="_FieldBased", intval=0) # progressive
c = core.resize.Point(c,format=vs.YUV444P8)
c = c * 300
c = core.std.AssumeFPS(c, fpsnum=30000, fpsden=1001)
c = core.text.FrameNum(c, 7)

def satanim(n, sat0, sat1, startframe, endframe):
    if n < startframe:
      return adjust.Tweak(c, sat=sat0)
    elif n > endframe:
      return adjust.Tweak(c, sat=sat1)
    else:
      return adjust.Tweak(c, sat=round(n-endframe)*(-1*sat0)/(endframe-startframe) + round(n-startframe)/(endframe-startframe) * sat1)
            
  
ani = core.std.FrameEval(c, functools.partial(satanim, sat0=1, sat1=3, startframe=100, endframe=160))

ani.set_output()
poisondeathray is offline   Reply With Quote
Old 14th October 2020, 22:43   #4056  |  Link
Jukus
Registered User
 
Join Date: Jul 2019
Location: Russia
Posts: 88
@poisondeathray
Thanks, I'll try again later.
I tried CrossFade and it really works as I suggested, that is, it does blending, while it loads the CPU very much. It also changes the total number of frames.

Last edited by Jukus; 14th October 2020 at 22:51.
Jukus is offline   Reply With Quote
Old 14th October 2020, 22:56   #4057  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,137
Note, that Jukus problem as posed, only applies correction 6223, 8361, and 8362, 9887, [ie below 6223 and above 9887 not touched]
whereas PDR script satanim alters entire clip [I assume that CrossFade does too].
This would seem to be correct, pointing this out to Jukus, that will not adjust only frames 6223 -> 9887. [CPU very much comment]

Of course the blending thing would not be appropriate where tweening eg HUE [circular].

EDIT:
Quote:
It also changes the total number of frames.
Typical with any kind of dissolve, eg CrossFade.

Try the PDR Satanim() thing, I think will preserve length.

EDIT: Ignore this
EDIT: Use trim to only process required range with satanim, then splice back into original clip.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 14th October 2020 at 23:22.
StainlessS is online now   Reply With Quote
Old 14th October 2020, 23:17   #4058  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,625
The helper function returns original clip, unless it's within startframe, endframe range. Length is unchanged . It's similar to animate() in avisynth, where parameters of a function are animated. It's a PITA IMO to setup. It's 100000x (or maybe more like 10000000x) easier to do any type of keyframe interpolation in a NLE or a GUI . And you can easily use other types of animation interpolation (not just linear), and some can GUIs have curves

Instead of using a dissolve function, the other way is to create an alpha channel control clip (white fade to black, or vice versa) where you use Overlay() with the alpha channel mask. This way the clip length is unchanged. This is essentially an animated blend between 2 or more layers.
poisondeathray is offline   Reply With Quote
Old 14th October 2020, 23:21   #4059  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,137
Quote:
The helper function returns original clip, unless it's within startframe, endframe range.
Oops, yes.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is online now   Reply With Quote
Old 14th October 2020, 23:30   #4060  |  Link
Jukus
Registered User
 
Join Date: Jul 2019
Location: Russia
Posts: 88
I've already thought about some kind of graphic editor, but I still need filters that only Vapoursynth / Avisynth have.
Сan quickly encode the video in a graphics editor, and only then do it good in Vapoursynth, but that's bd 90 minutes video.
Jukus is offline   Reply With Quote
Reply

Tags
speed, vaporware, vapoursynth

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:44.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.