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 23rd March 2025, 05:27   #1  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 371
python piping subprocesses failes if print() is in vpy script

I have simple command line, which works ok, as it suppose to:
Code:
vspipe.exe  test.vpy -c y4m - | ffmpeg.exe -y -i -  out.mp4
test.vpy:
Code:
from vapoursynth import core
clip = core.ffms2.Source('source.avi')
clip.set_output()
print("Hi")
Notice that print() statement in it. In command prompt it works fine. Also it works in python script, as in code below, BUT only without that print() line in vapoursynth script:
Code:
import subprocess
import shlex

cmd = 'vspipe.exe  test.vpy -c y4m - | ffmpeg.exe -y -i -  out.mp4'
new_args = cmd.split('|')
cmd_lists = [shlex.split(arg) for arg in new_args]
process1 = subprocess.Popen(cmd_lists[0], stdout=subprocess.PIPE)
output, _ = process1.communicate()

process2 = subprocess.Popen(cmd_lists[1], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output2, _ = process2.communicate(input=output)
So if that print() is in that script, it fails if using python to encode.
Does anyone know what is going on? I tried to redirect stdout to nul, like below , it did not help.
Code:
import subprocess
import shlex
import contextlib
import os

cmd = 'vspipe.exe  test.vpy -c y4m - | ffmpeg.exe -y -i -  out.mp4'
new_args = cmd.split('|')
cmd_lists = [shlex.split(arg) for arg in new_args]

with contextlib.redirect_stdout(open(os.devnull, 'w')):
    process1 = subprocess.Popen(cmd_lists[0], stdout=subprocess.PIPE)
    output, _ = process1.communicate()
    process2 = subprocess.Popen(cmd_lists[1], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    output2, _ = process2.communicate(input=output)

Last edited by _Al_; 23rd March 2025 at 05:30.
_Al_ is offline   Reply With Quote
Old 23rd March 2025, 06:24   #2  |  Link
HolyWu
Registered User
 
Join Date: Aug 2006
Location: Taiwan
Posts: 393
Code:
import sys
print("Hi", file=sys.stderr)
HolyWu is offline   Reply With Quote
Old 23rd March 2025, 06:50   #3  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 371
Thanks! :-)
_Al_ is offline   Reply With Quote
Reply

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 15:57.


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