我一直在寻找一种从python脚本运行外部进程的方法,并在执行期间打印其stdout消息.
下面的代码可以工作,但在运行时打印没有stdout输出.当它退出时,我收到以下错误:
sys.stdout.write(nextline)TypeError:必须是str,而不是bytes
p = subprocess.Popen(["demo.exe"],stdout = subprocess.PIPE, stderr= subprocess.PIPE)
# Poll process for new output until finished
while True:
nextline = p.stdout.readline()
if nextline == '' and p.poll() != None:
break
sys.stdout.write(nextline)
sys.stdout.flush()
output = p.communicate()[0]
exitCode = p.returncode
Run Code Online (Sandbox Code Playgroud)
我使用的是python 3.3.2
我正在多路复用视频和音频流.视频流来自生成的图像数据.音频流来自aac文件.有些音频文件比我设置的总视频时间长,所以当我的时间变得大于总视频时间(我用数字编码的视频帧控制的最后一个)时,我的策略是停止音频流复用.
我不会在这里放置整个设置代码,但它类似于最新的FFMPEG repo中的muxing.c示例.唯一的区别是我使用来自文件的音频流,正如我所说的,不是来自合成生成的编码帧.我很确定问题是在muxer循环期间我的错误同步.这就是我所做的:
void AudioSetup(const char* audioInFileName)
{
AVOutputFormat* outputF = mOutputFormatContext->oformat;
auto audioCodecId = outputF->audio_codec;
if (audioCodecId == AV_CODEC_ID_NONE) {
return false;
}
audio_codec = avcodec_find_encoder(audioCodecId);
avformat_open_input(&mInputAudioFormatContext,
audioInFileName, 0, 0);
avformat_find_stream_info(mInputAudioFormatContext, 0);
av_dump_format(mInputAudioFormatContext, 0, audioInFileName, 0);
for (size_t i = 0; i < mInputAudioFormatContext->nb_streams; i++) {
if (mInputAudioFormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
inAudioStream = mInputAudioFormatContext->streams[i];
AVCodecParameters *in_codecpar = inAudioStream->codecpar;
mAudioOutStream.st = avformat_new_stream(mOutputFormatContext, NULL);
mAudioOutStream.st->id = mOutputFormatContext->nb_streams - 1;
AVCodecContext* c = avcodec_alloc_context3(audio_codec);
mAudioOutStream.enc = c;
c->sample_fmt = audio_codec->sample_fmts[0]; …Run Code Online (Sandbox Code Playgroud) 我正在修改SDK示例包中的CUDA视频编码器(NVCUVENC)编码样本,以便数据不是来自外部yuv文件(如示例中所做),而是来自纹理填充的cudaArray.
因此,对帧进行编码的关键API方法是:
int NVENCAPI NVEncodeFrame(NVEncoder hNVEncoder, NVVE_EncodeFrameParams *pFrmIn, unsigned long flag, void *pData);
Run Code Online (Sandbox Code Playgroud)
如果我把它弄好了:
CUdeviceptr dptr_VideoFrame
Run Code Online (Sandbox Code Playgroud)
应该将数据传递给encode.But我真的不明白如何将它与GPU上的一些纹理数据连接.示例源代码非常含糊,因为它与CPU yuv文件输入一起工作.
例如,在main.cpp,第555-560行中,有以下块:
// If dptrVideoFrame is NULL, then we assume that frames come from system memory, otherwise it comes from GPU memory
// VideoEncoder.cpp, EncodeFrame() will automatically copy it to GPU Device memory, if GPU device input is specified
if (pCudaEncoder->EncodeFrame(efparams, dptrVideoFrame, cuCtxLock) == false)
{
printf("\nEncodeFrame() failed to encode frame\n");
}
Run Code Online (Sandbox Code Playgroud)
所以,从评论来看,似乎dptrVideoFrame应该填充来自设备的yuv数据来编码帧.但是没有地方可以解释如何这样做.
更新:
我想分享一些发现.首先,我设法对帧缓冲区纹理中的数据进行编码.现在的问题是输出视频是一团糟.

这是理想的结果:

这是我做的:
在OpenGL方面,我有2个自定义FBO - …
我正在将一个应用程序从ActionScript3.0(Flex)移植到C#(WPF).AS3.0有一个名为getTimer()的方便实用程序,它返回自Flash虚拟机启动以来的时间毫秒.我在C#中通过类搜索
DateTime
DispatcherTimer
System.Diagnostics.Process
System.Diagnostics.Stopwatch
Run Code Online (Sandbox Code Playgroud)
但是没有发现这样的东西.这对我来说似乎是一个非常基本的功能.例如,在Mono上运行的Unity3D有一些熟悉的东西.我在这里想念一些实用工具吗?
提前致谢.
免责声明:几天前我在codereview上问了这个问题,但没有得到答案.在这里我将问题格式从审核请求更改为特定问题.
我正在开发一个具有以下设计的视频播放器:
主线程 - 是GUI线程(Qt SDK).
第二个线程 - 玩家线程接受来自GUI线程的命令来播放,前进,后退,停止等等.现在,该线程以恒定循环运行,并使用互斥锁和等待条件与主线程命令同步.
我有这个代码的2个问题:
我不觉得我的设计是完全正确的:我正在使用互斥锁和原子变量.我想知道我是否只能保留原子并仅使用锁来设置等待条件.
我正在遇到不一致的错误(可能是由于当播放命令试图锁定已经被播放循环工作的线程锁定的互斥锁时的条件竞争)当我运行"play"命令激活线程循环内的循环时.所以我想它阻止了对主线程的共享变量的访问.
我已经从不需要的东西中删除了代码,它通常是这样的:
void PlayerThread::drawThread()//thread method passed into new boost::thread
{
//some init goes here....
while(true)
{
boost::unique_lock<boost::mutex> lock(m_mutex);
m_event.wait(lock); //wait for event
if(!m_threadRun){
break; //exit the tread
}
///if we are in playback mode,play in a loop till interrupted:
if(m_isPlayMode == true){
while(m_frameIndex < m_totalFrames && m_isPlayMode){
//play
m_frameIndex ++;
}
m_isPlayMode = false;
}else{//we are in a single frame play mode:
if(m_cleanMode){ ///just clear the screen …Run Code Online (Sandbox Code Playgroud) 我知道如何使用固定管道绘制圆点.但是我需要使用现代OpenGL来做同样的事情.是可能的,还是应该使用点精灵和纹理?
对于感兴趣的人.这是如何使用固定管道完成的:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL, 0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_POINT_SMOOTH );
glPointSize( 8.0 );
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(myMatrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(myAnotherMatrix);
glBegin(GL_POINTS);
glColor3f(1,1,1);
glVertex3fv(position);
glEnd();
glDisable(GL_POINT_SMOOTH);
glBlendFunc(GL_NONE, GL_NONE);
glDisable(GL_BLEND);
Run Code Online (Sandbox Code Playgroud) 我使用OpenGL4.X.最近我读到了这个 Apple OpenGLES2文档,其中声明使用交错属性数组可以提高IOS移动设备的性能,并且是推荐的方式(而不是使用属性块).
对于那些不明白我的意思的人来说,这是一个例子:
单个属性数组中的属性块:
float vertices[]{
//Triangle vertices:
v0x , v0y , v0z ,
v1x , v1y , v1z ,
v2x , v2y , v2z ,
//Triangle UVs:
uv0s , uv0t ,
uv1s , uv1t ,
uv2s , uv2t ,
//Triangle Normals:
n0x , n0y , n0z ,
n1x , n1y , n1z ,
n2x , n2y , n2z
}
Run Code Online (Sandbox Code Playgroud)
交错属性数组:
float vertices[]{
v0x , v0y , v0z ,
uv0s , uv0t , ////vertex 1 attributes
n0x , …Run Code Online (Sandbox Code Playgroud) 我正在逐行读取Python中的文件,我需要知道在读取时哪一行是最后一行,如下所示:
f = open("myfile.txt")
for line in f:
if line is lastline:
#do smth
Run Code Online (Sandbox Code Playgroud)
从我发现的例子中我发现它涉及搜索和完整的文件读数以计算行数等.我可以检测到当前行是最后一行吗?我试图检查"\n"是否存在,但在很多情况下,最后一行后面没有反斜杠N.
对不起,如果我的问题是多余的,因为我没有在SO上找到答案
我正在学习如何从这个例子中创建MP4视频.问题是该示例演示了动态生成的一些虚拟源数据的音频编码.我需要对文件中的音频进行编码.我检查了很多例子,其中大部分显示相同或只是一个单独的音频编码.在我的试错过程中,我对音频和视频帧使用相同的AVFormatContext.我不确定这是否正确,或者我是否应该有2个单独的上下文?到目前为止,我的视频编码还可以,但是音频流失败了因为AVPacket无法找到正确的音频流索引.以下是我设置音频流的方法:
void open_audio(AVFormatContext *oc, AVCodec **codec, AVStream **st ,enum AVCodecID codec_id){
// AVCodecContext *c;
int ret;
// c = st->codec;
*codec = avcodec_find_encoder(codec_id);
if (!(*codec)) {
fprintf(stderr, "Could not find encoder for '%s'\n",avcodec_get_name(codec_id));
}
/* open it */
if(avformat_open_input(&oc,_audioInName.c_str(),NULL,NULL) !=0){
Msg::PrintErrorMsg("Error opening audio file");
}
AVStream* audioStream = NULL;
// Find the audio stream (some container files can have multiple streams in them)
for (uint32_t i = 0; i < oc->nb_streams; ++i)
{
if (oc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
{ …Run Code Online (Sandbox Code Playgroud)