View Full Version : Vapoursynth
lansing
8th August 2017, 09:27
It's all there in the documentation:
FrameNum (http://www.vapoursynth.com/doc/functions/framenum.html) | FrameProps (http://www.vapoursynth.com/doc/functions/frameprops.html) | SetFrameProp (http://www.vapoursynth.com/doc/functions/setframeprop.html)
A frame's properties can be accessed by using the get_frame function along with the props attribute. Like so:
src.get_frame(num).props.someFrameProperty = someValue
Reference (http://www.vapoursynth.com/doc/pythonreference.html#classes-and-functions).
That still doesn't tell me the list of properties of a frame. The problem I have is that I didn't even know the name. In my example, how do I know the name to call frame number? Is it ".props.frame_number" or ".props.frame_num", or is it "props.framenum"? The reference sure doesn't have them.
TheFluff
8th August 2017, 09:34
http://www.vapoursynth.com/doc/apireference.html#reserved-frame-properties
I'm not sure if there's a standard for anything else. The props are just a key-value map that can contain anything though so just iterate over the keys and all secrets will be revealed to you. Maybe.
lansing
8th August 2017, 22:35
http://www.vapoursynth.com/doc/apireference.html#reserved-frame-properties
I'm not sure if there's a standard for anything else. The props are just a key-value map that can contain anything though so just iterate over the keys and all secrets will be revealed to you. Maybe.
Thanks, I didn't know that they were listed on that page, I was looking all over the python reference and function reference page.
lansing
11th August 2017, 17:24
Hi I have another question, is there a function that can delete a series of ranges of frames? For example, I wanted to delete frame 1-10, 100-200 and 500-600 of a clip.
Myrsloik
11th August 2017, 17:26
Hi I have another question, is there a function that can delete a series of ranges of frames? For example, I wanted to delete frame 1-10, 100-200 and 500-600 of a clip.
Sure is. Trim and splice.
lansing
12th August 2017, 09:39
DeleteFrames (http://www.vapoursynth.com/doc/functions/deleteframes.html) should be easier to use.
Can you give an example?
tuanden0
12th August 2017, 15:28
I'm new to vapoursynth, Can someone help me?
I need to change this line in Aviysnth with aWarpSharp filter to Vapoursynth with aWarpSharp2.
I haven't used aWarpSharp2 filter with Avisynth yet :(
aWarpSharp(depth=12, thresh=0.2, cm=1)
WolframRhodium
12th August 2017, 18:52
I'm new to vapoursynth, Can someone help me?
I need to change this line in Aviysnth with aWarpSharp filter to Vapoursynth with aWarpSharp2.
I haven't used aWarpSharp2 filter with Avisynth yet :(
According to pinterf's code (https://github.com/pinterf/aWarpSharp/blob/master/src/aWarpSharp.cpp#L1699)
aWarpSharp(depth=12, thresh=0.2, cm=1)
in Avisynth is (almost) equivalent to
aWarpSharp2(depth=12, thresh=51, chroma=4)
So in VapourSynth, I think it should be
last = core.warp.AWarpSharp2(last, depth=12, thresh=51, chroma=0)
ChaosKing
12th August 2017, 18:55
I'm new to vapoursynth, Can someone help me?
I need to change this line in Aviysnth with aWarpSharp filter to Vapoursynth with aWarpSharp2.
I haven't used aWarpSharp2 filter with Avisynth yet :(
From aWarpSharp2 readme (avisynth)
Original aWarpSharp compatibility:
Mapping from original aWarpSharp parameters:
thresh = thresh*256
blur = blurlevel
depth = depth*blurlevel/2
chroma = 0->2, 1->4, 2->3
aWarpSharp(depth=12, thresh=0.2, cm=1)
You should change thresh to 51 or 52 in awarpsharp2
WolframRhodium
12th August 2017, 19:00
Can you give an example?
I'll use following code in this case:
frame_list = list(range(1, 10+1)) + list(range(100, 200+1)) + list(range(500, 600+1))
last = core.std.DeleteFrames(last, frame_list)
lansing
12th August 2017, 21:05
I'll use following code in this case:
frame_list = list(range(1, 10+1)) + list(range(100, 200+1)) + list(range(500, 600+1))
last = core.std.DeleteFrames(last, frame_list)
Thanks, this is what I'm looking for.
tuanden0
13th August 2017, 03:15
@WolframRhodium, @ChaosKing
Thank You very much :)
hydra3333
13th August 2017, 04:25
R38 is released.
The usual post (http://www.vapoursynth.com/2017/06/r38-boxblur-is-best-blur/)
Thank you for your great work !
I also appreciate your enabling people to compile their own bits (in my case avisynth_compat.cpp). Beaut !
lansing
13th August 2017, 09:45
How do I overlay text on the frame, like showing frame number of every frame? I can only think of this, but it's certainly a wrong way to do it because it ate up all my ram until the program crashed on longer videos.
for i in range (len(clip)):
if (i==0):
sub_clip = core.sub.Subtitle(clip[i], text=str(i))
else:
sub_clip += core.sub.Subtitle(clip[i], text=str(i))
AzraelNewtype
13th August 2017, 10:19
clip = core.text.FrameNum(clip)
You really might want to actually read the docs.
lansing
13th August 2017, 13:41
clip = core.text.FrameNum(clip)
You really might want to actually read the docs.
Thanks. I did read the documents many many times, I thought this function is to print the frame number out to the console, like "print(x)". And there's no sample codes showing what it does.
TheFluff
13th August 2017, 13:59
The use of the word "print" in the docs is a bit confusing, yes. It should probably clarify that it refers to printing on the video frame.
Either way though, requesting all frames in the input clip in Python and splicing one frame at a time is an extremely awkward way of doing things in VS. If you ever find yourself writing a loop that requests frames in Python, you're probably doing things wrong. Yes, iterating over a sequence is intuitive for most programmers, but in the VS world, you need to stop thinking imperative programming and start thinking functional. What you want to write is a composition of functions that does what you want, handling one or at most a few frames at a time, and leave invoking that function chain up to the client application (usually vspipe). Or in other words, start attaching callbacks to things. One more idiomatic way of reimplementing the equivalent of what core.text.FrameNum does yourself is by using FrameEval (example stolen from the docs and slightly modified):
import vapoursynth as vs
import functools
core = vs.get_core()
base_clip = core.std.BlankClip(format=vs.YUV420P8, length=1000, color=[255, 128, 128])
def PrintFrameNumber(n, clip):
return core.sub.Subtitle(clip, text=str(n))
number_clip = core.std.FrameEval(base_clip, functools.partial(PrintFrameNumber, clip=base_clip))
You might be thinking that this is just doing the same thing that you did. The difference is that here, the subtitling is done when a frame is actually requested, not when the Python script is compiled, and it can be parallelized by the VS thread pool to subtitle many frames at once.
lansing
14th August 2017, 01:25
Thanks for the explanation, that's really clear. I practiced with a few simple function, but I got the error "BuildSCClip() missing 1 required positional argument: 'f'", what does it mean?
update: I figured out the last problem. And for this one, why didn't it return a delete even clip back to me?
import vapoursynth as vs
import functools
core = vs.get_core(accept_lowercase=True)
source = abc.avi
def DeleteEven(n, clip):
if n % 2 ==0:
return core.std.DeleteFrames(clip, n)
return clip
odd = core.std.FrameEval(source, functools.partial(DeleteEven, clip=source))
odd.set_output()
tuanden0
14th August 2017, 06:17
Can someone give me an example of using TCanny to create a mask and apply it to keep detail in dark area?
I tried it myself but the output turn on black and mask :(
Here's my output:
http://i.imgur.com/yBgilc4.png
TheFluff
14th August 2017, 22:25
Thanks for the explanation, that's really clear. I practiced with a few simple function, but I got the error "BuildSCClip() missing 1 required positional argument: 'f'", what does it mean?
update: I figured out the last problem. And for this one, why didn't it return a delete even clip back to me?
import vapoursynth as vs
import functools
core = vs.get_core(accept_lowercase=True)
source = abc.avi
def DeleteEven(n, clip):
if n % 2 ==0:
return core.std.DeleteFrames(clip, n)
return clip
odd = core.std.FrameEval(source, functools.partial(DeleteEven, clip=source))
odd.set_output()
Well, I dunno. Aside from DeleteFrames taking a list of ints, not a single int (I think) that kinda looks like it should work (maybe; I'm a bit unsure of what'll happen on the last frame of the clip). I don't think "source = abc.avi" is what's actually in your script though. What does happen when you try to run it?
lansing
14th August 2017, 22:55
Well, I dunno. Aside from DeleteFrames taking a list of ints, not a single int (I think) that kinda looks like it should work (maybe; I'm a bit unsure of what'll happen on the last frame of the clip). I don't think "source = abc.avi" is what's actually in your script though. What does happen when you try to run it?
There's no error, it skips the first return and just do the second return, which give me back the source clip.
TheFluff
14th August 2017, 23:28
Are you sure about that? I suspect the problem might be that calling deleteframes there doesn't do what you think it does. It won't change the length of the clip returned by frameeval, I'm pretty darn sure. What I'd expect it to do is to replace even numbered frames with the following frame.
lansing
14th August 2017, 23:55
Are you sure about that? I suspect the problem might be that calling deleteframes there doesn't do what you think it does. It won't change the length of the clip returned by frameeval, I'm pretty darn sure. What I'd expect it to do is to replace even numbered frames with the following frame.
Oh yes it did replace the even number frame with the odd one.
So I can't delete frames with arbitrary functions using FrameEval?
Myrsloik
15th August 2017, 01:55
Oh yes it did replace the even number frame with the odd one.
So I can't delete frames with arbitrary functions using FrameEval?
If you're clever you can reorder things. Note that frameeval takes a clip argument that's only used to set the output format and length. Adjist the total number of frames there.
Probably what you wanted to do. Halve the framecount and you're done.
def DeleteEven(n, clip):
return clip[n // 2]
Can also be expressed as clip[::2] without resorting to frameeval at all.
TheFluff
15th August 2017, 11:48
Oh yes it did replace the even number frame with the odd one.
So I can't delete frames with arbitrary functions using FrameEval?
You can't change the length of the clip, no. When you use FrameEval, the frame number requested from the clip you return from the evaluator function doesn't change. When the client application requests (say) frame 4, and your evaluator function gets n = 4 as an argument and returns a clip that's the same as the original but with frame 4 deleted, FrameEval requests frame 4 from that clip, but since you deleted the original frame 4, the frame now numbered 4 in that clip is number 5 in the original clip. That's why even numbered frames get replaced with the following even one.
The thing Myrsloik did relies on the fact that requesting a frame beyond the end of a clip just returns the last frame, so you get back a clip with the same length as the original, but every frame after the halfway point is just the same as the last.
Selur
16th August 2017, 18:54
Is there something like ffmpegs shuffleframes (https://www.ffmpeg.org/ffmpeg-all.html#toc-shuffleframes) in Vapoursynth? (A filter which allows so swap and drop frames by a given pattern?)
Myrsloik
16th August 2017, 18:56
Is there something like ffmpegs shuffleframes (https://www.ffmpeg.org/ffmpeg-all.html#toc-shuffleframes) in Vapoursynth? (A filter which allows so swap and drop frames by a given pattern?)
See frameeval. Especially the most recent posts. A simple callback and you can apply any remapping.
sneaker_ger
16th August 2017, 19:00
Isn't it easier with SelectEvery?
Myrsloik
16th August 2017, 19:03
Isn't it easier with SelectEvery?
If your pattern can be expressed with it. Yes. But it gets kinda iffy for 1000+ frame cycles and can't do stuff like drop all prime number frames.
Selur
16th August 2017, 19:05
SelectEvery could do the dropping, but not the shuffling, or am I misunderstanding the filter?
Myrsloik
16th August 2017, 19:06
SelectEvery could do the dropping, but not the shuffling, or am I misunderstanding the filter?
Correct, no shuffle.
sneaker_ger
16th August 2017, 19:13
I think Selur means "shuffle" as in "re-order with fixed pattern", not "re-order randomly". :confused:
So it should be able to do everything ffmpeg's shuffleframes can do.
Selur
16th August 2017, 19:17
Yes, given a pattern like for example "0 2 7 5 4 3 1 6 8" would do some crazy reordering on each set of 9 frames.
Myrsloik
16th August 2017, 19:20
Yes, given a pattern like for example "0 2 7 5 4 3 1 6 8" would do some crazy reordering on each set of 9 frames.
I think that works. Try it and see. I probably made selectevery take the order into account.
feisty2
18th August 2017, 07:22
@Myrsloik
can you write something to convert a vaporsynth video clip to a numpy array and a reverse conversion like-wise? so, like
forward conversion: video clip -> numpy.array((framecount, height, width, channel))
reverse conversion: numpy.array((framecount, height, width, channel)) -> video clip
the conversion should only support GRAYS/RGBS/YUV444PS inputs obviously
the thing is... I wanna pre-process my image samples with vaporsynth before feeding them to keras
I could use vspipe to generate raw files and load them with numpy.memmap for now, but it sucks
Myrsloik
18th August 2017, 11:15
All frames are exposed as a memoryview. Just use get_frame(). I don't know the exact python way but I'm very certain you can create numpy arrays from memoryviews. Or maybe it already is one.
For the reverse you can probably use modifyframe (see the insane filter writing in python thread). No idea what the speed will be like, probably not that bad as long as you find the appropriate.
Or do it all in a single modifyframe callback. I have no idea what kind of preprocessing you want to do.
feisty2
18th August 2017, 13:57
I have no idea what kind of preprocessing you want to do.
say I wanna do a super resolution neural net with keras, first I would need to generate the corresponding low resolution version of the high resolution samples, and for that I need resampling filters.
there's scipy.misc.imresize but it's pretty rudimentary comparing to fmtc, it has very few resampling kernels, doesn't even have spline! and you can't tweak stuff like "taps" or whatever for each kernel, with fmtc I got control over everything, I can even create my own resampling kernel or resize under linear light
so I want vaporsynth (filters) to do stuff like that
concretely, something like
def GenLowResSamples(samples):
core = vs.get_core()
samples = ArrayToVideo(samples) #reverse conversion
samples = core.fmtc.resample(samples, sample.width//2, sample.height//2, kernel="sinc", taps=128, fulls=True, fulld=True)
samples = core.fmtc.resample(samples, sample.width*2, sample.height*2, kernel="sinc", taps=128, fulls=True, fulld=True)
samples = VideoToArray(samples) #forward conversion
return samples
lansing
20th August 2017, 01:42
Hi I'm trying to frame serve a video from Adobe Premiere to Vapoursynth using this frame server called advanced frame server, when I try to grab it with avisource, the editor crashed and I got this error "setVideoInfo: The frame rate specified by AVISource must be a reduced fraction. (Instead, it is 23976/1000.)", and there's no option in avisource to change it.
Selur
20th August 2017, 08:30
I think that works. Try it and see. I probably made selectevery take the order into account.
Works fine! Thanks to myrsloik and sneaker_ger for the help and pointing to SelectEvery() ! :D
shekh
23rd August 2017, 02:24
Tried to implement r210 DIB. Have issue with VapourSynth-R38
r = core.avisource.AVISource('rgb.avi')
r = core.resize.Point(r, format=vs.RGB30)
r.set_output()
Source is 784x400 but appears to have 832*4 pitch from vs (I derived it from total size and it works).
Is this error on output or there is some rule for it?
Myrsloik
23rd August 2017, 06:47
Hi I'm trying to frame serve a video from Adobe Premiere to Vapoursynth using this frame server called advanced frame server, when I try to grab it with avisource, the editor crashed and I got this error "setVideoInfo: The frame rate specified by AVISource must be a reduced fraction. (Instead, it is 23976/1000.)", and there's no option in avisource to change it.
Wil be fixed in the next version
Myrsloik
23rd August 2017, 06:59
Tried to implement r210 DIB. Have issue with VapourSynth-R38
r = core.avisource.AVISource('rgb.avi')
r = core.resize.Point(r, format=vs.RGB30)
r.set_output()
Source is 784x400 but appears to have 832*4 pitch from vs (I derived it from total size and it works).
Is this error on output or there is some rule for it?
Pitch is a multiple of 256 bytes. Can't even find a source on it rogjt now.
shekh
23rd August 2017, 09:35
Pitch is a multiple of 256 bytes. Can't even find a source on it rogjt now.
Good, found it in ffmpeg code.
Myrsloik
23rd August 2017, 09:39
Good, found it in ffmpeg code.
Note that you can't always assume it because for v210 and r210 and just about every format with special stride requirements at least half the software gets it wrong. Fun fact.
Myrsloik
24th August 2017, 18:36
Here's R39 test1 (https://dl.dropboxusercontent.com/u/73468194/VapourSynth-R39-test1.exe)
It would be a proper RC if it wasn't for a bit more optimization and refactoring I want to do in the 3x3 pixel filter part of the code (aka the previously known as genericfilters part).
Glorious changes:
r39:
fixed missing fps correction in avisource that would produce an error with some files
switched to nasm as the assembler
updated to zimg v2.6
visual studio runtime detection is improved in the installer, it should no longer attempt re-installs when a newer version is present
minor optimization in vspipe, you can now output blankclip into the void much faster
memory will now be 64 byte aligned on systems with avx512 support
added swapn and dupn operators to expr
reverted the argument handling in levels, arguments no longer take a 3 plane list due it making no sense when combined with the planes argument
optimized levels, the integer version is now implemented with a lut and the floating point version is faster when gamma=1.0
improved get_outputs() in python (stuxcrystal)
format objects can now be cast to int which will return the format id (stuxcrystal)
added method to make it easier to query formats from python (stuxcrystal)
made it possible to install the python part as a module (stuxcrystal)
lansing
24th August 2017, 23:28
Here's R39 test1 (https://dl.dropboxusercontent.com/u/73468194/VapourSynth-R39-test1.exe)
It would be a proper RC if it wasn't for a bit more optimization and refactoring I want to do in the 3x3 pixel filter part of the code (aka the previously known as genericfilters part).
Glorious changes:
r39:
fixed missing fps correction in avisource that would produce an error with some files
switched to nasm as the assembler
updated to zimg v2.6
visual studio runtime detection is improved in the installer, it should no longer attempt re-installs when a newer version is present
minor optimization in vspipe, you can now output blankclip into the void much faster
memory will now be 64 byte aligned on systems with avx512 support
added swapn and dupn operators to expr
reverted the argument handling in levels, arguments no longer take a 3 plane list due it making no sense when combined with the planes argument
optimized levels, the integer version is now implemented with a lut and the floating point version is faster when gamma=1.0
improved get_outputs() in python (stuxcrystal)
format objects can now be cast to int which will return the format id (stuxcrystal)
added method to make it easier to query formats from python (stuxcrystal)
made it possible to install the python part as a module (stuxcrystal)
My video from frameserve is able to open now, but it was turned upside down
Myrsloik
25th August 2017, 12:07
What's the format? Can I have a sample of the input? 10 frames is enough
lansing
25th August 2017, 14:06
What's the format? Can I have a sample of the input? 10 frames is enough
The video file was a dummy generated by the frame server, here's the video info
Video
ID : 0
Format : VFW
Codec ID : DFSC
Codec ID/Info : DebugMode FrameServer VFW
Duration : 24 min 13 s
Bit rate : 767 b/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate : 23.976 (24000/1001) FPS
Bits/(Pixel*Frame) : 0.000
Stream size : 136 KiB (14%)
You can reproduce it with Premiere and this frame server (https://sourceforge.net/projects/advancedfs/). Media player classic play the file with no problem.
Myrsloik
25th August 2017, 18:45
The video file was a dummy generated by the frame server, here's the video info
Video
ID : 0
Format : VFW
Codec ID : DFSC
Codec ID/Info : DebugMode FrameServer VFW
Duration : 24 min 13 s
Bit rate : 767 b/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate : 23.976 (24000/1001) FPS
Bits/(Pixel*Frame) : 0.000
Stream size : 136 KiB (14%)
You can reproduce it with Premiere and this frame server (https://sourceforge.net/projects/advancedfs/). Media player classic play the file with no problem.
I said a sample. As in a piece of raw video. Not going to install that mess.
lansing
25th August 2017, 19:16
I said a sample. As in a piece of raw video. Not going to install that mess.
The frameserver export a dummy avi while Premiere was still on, then I loaded that dummy avi into vs. The problem was not on any particular video that was frameserved, as I tried on a couple of different videos already, so there's no sample I can give.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.