停止函数写入标准输出 [英] Stop a function from writing to stdout

查看:59
本文介绍了停止函数写入标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有这一行:

writer = cv.CreateVideoWriter('video.avi', cv.CV_FOURCC('X','V','I','D'), 30 ,(480,800), 1)

哪个输出可以对此进行控制:

Which outputs to console this:

Output #0, avi, to 'video.avi':
Stream #0:0: Video: mpeg4, yuv420p, 480x800, q=2-31, 24576 kb/s, 90k tbn, 30 tbc

我想阻止它将任何内容打印到stdout,但是可以自己在代码中进一步输出一些内容.我该如何实现?

I want to stop it from printing anything to stdout, but keep the possibility to output by myself something further in the code. How can I achieve this?

我尝试过,但是没有用.

I tried this, but it didn't worked.

class NullStream:
    def write(self, text):
        pass

sys.stdout = NullStream()
sys.stderr = NullStream()

print "hello" #This doesn't outputs

#This function still outputs to console:
writer = cv.CreateVideoWriter('video.avi', cv.CV_FOURCC('X','V','I','D'), 30 ,(480,800), 1)

sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__

推荐答案

不是OpenCV输出此信息.是FFMPEG(OpenCV称之为).

It's not OpenCV that outputs this info. It's FFMPEG (which is called by OpenCV).

您可以重新编译FFMPEG以禁用这些调试.

You can recompile FFMPEG to disable these debugs.

这篇关于停止函数写入标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆