Log in

View Full Version : How to call ffmpeg subprocess as input into raws.Source in .vpy script ?


poisondeathray
25th January 2022, 01:24
As demonstrated in the vsrawsource thread, raws.Source accepts "-" stdin raw pipe input

e.g. something like this


ffmpeg -f lavfi -i testsrc2=rate=24000/1001:duration=10:s=640x480 -f rawvideo - | vspipe --y4m script.vpy - | ffplay -f yuv4mpegpipe -i -

import vapoursynth as vs
core = vs.core
clip = core.raws.Source("-", width=640, height=480, src_fmt="YUV420P8", fpsnum=24000, fpsden=1001)
clip.set_output()



1) How to call ffmpeg within vpy script , perhaps as a subprocess ?

pseudo code crashes vsedit , I tried several combinations

import vapoursynth as vs
core = vs.core
import subprocess

#subprocess.call(['ffmpeg', '-f', 'lavfi', '-i', 'testsrc2=rate=24000/1001:duration=10:s=640x480', '-f', 'rawvideo', '-', '|'])
process = subprocess.Popen(['ffmpeg', '-f', 'lavfi', '-i', 'testsrc2=rate=24000/1001:duration=10:s=640x480', '-f', 'rawvideo', '-', '|'])

clip = core.raws.Source("-", width=640, height=480, src_fmt="YUV420P8", fpsnum=24000, fpsden=1001)
#clip.set_output()
clip.set_output(process.stdin)
process.communicate()




2) Is there another pipe input filter that accepts yuv4mpegpipe instead of rawvideo ?

_Al_
25th January 2022, 02:44
1)If using subprocess, you can copy/paste ffmpeg output from memory directly into vapoursynth arrays and make a clip.
This is sort of redneck ffmpeg source plugin solution , and has disadvantages, no seeking, only straight forward frame after frame to the end, and also the end is a problem, you need to catch error and stop process, I can see output visually using a python previewer but not sure if it comes out ok using vsedit for example, and as I said it is just moving forward frame after frame, no seeking.
That is why I did not respond on videohelp, because not sure how practical it would be.
I posted it here:
https://forum.doom9.org/showpost.php?p=1925640&postcount=4049

poisondeathray
25th January 2022, 03:09
Thanks it works. Yes, seeking is not frame accurate and you "lose your place".

I wanted to play with some (currently) ffmpeg only filters such as grayworld , but in the context of vsedit or avspmod without the hassle of intermediates
https://forum.doom9.org/showthread.php?p=1962218

(yes, I know I could use ffplay or mpv , but there are other transforms and filters that I want to apply as well)