3

When vspipe calls a main Python program how do we set the output node?

The following does not work:

def main(argv):
   ...
   ... 
   vapoursynth code
   ...
   clip.set_output()

if __name__ == "__main__":
   main(sys.argv[1:])

Neither does this:

....
if __name__ == "__main__":
   clip = main(sys.argv[1:])
   clip.set_output()

Error message is: Failed to retrieve output node. Invalid index specified?

MarianD
  • 13,096
  • 12
  • 42
  • 54
Cary Knoop
  • 51
  • 4
  • Do you want **the same** VapourSynth code for **different** input videos and use it with the video file name as a **parameter**? Something as `vspipe -p your_script.vpy your_input_file_name output_name`? – MarianD Apr 14 '17 at 19:58

2 Answers2

2

Sorry for this late answer but I think this needs to be addressed:

The __name__ variable usually contains "__main__" when the script is main target of the Python interpreter, for example when it's called from the commandline.

However, less known because undocumented: when vspipe or any other vsscript-based application runs your script, the string "__vapoursynth__" is stored inside __name__.

Therefore your check should be this instead:

if __name__ == "__vapoursynth__":
   clip = main()
   clip.set_output()
FichteFoll
  • 663
  • 1
  • 6
  • 12
StuxCrystal
  • 846
  • 10
  • 20
0

If your VapourSynth script is not parametrized with the input video file name, i. e. the input file name is hard-coded in your script, e. g. in the statement

video = core.ffms2.Source("InputVideo.mkv")

you may directly write your whole script -

(without defining main() function (1st line of your sample code)
and the if block at the end)

- or -

replace them with

def main():

at the beginning, and

if __name__ == "__main__":
    main()

at the end.

You may consider vspipe as a specialized Python interpreter, so it knows (from your command clip.set_output()) which video to pipe, e. g. in the command

vspipe -y -p  your_script.vpy - |  ffmpeg -i -  output.mp4

or from which video to output uncompressed video, e. g. in the command

vspipe -y -p  your_script.vpy  uncompressed_output.y4m
MarianD
  • 13,096
  • 12
  • 42
  • 54