0
我使用ffmpeg 1.2从IP摄像头拍摄视频。我在屏幕上绘制视频,所以我想知道是否有一些事件机制来知道是否应该调用av_read_frame ? 如果我读帧不那么频繁的相机给我帧分割得到故障=里面的ffmpeg程序(video_get_buffer)一些的malloc函数在屏幕上使用ffmpeg绘图的IP摄像头
我也得到分段错误只是在屏幕上绘制时。
在渲染函数调用每一个0毫秒
void BasicGLPane::DrawNextFrame()
{
int f=1;
while(av_read_frame(pFormatCtx, &packet)>=0)
{
// Is this a packet from the video stream?
if(packet.stream_index==videoStream)
{
// Decode video frame
avcodec_decode_video2(pCodecCtx, pFrame, &FrameFinished,
&packet);
// Did we get a video frame?
if(FrameFinished)
{
f++;
this->fram->Clear();
// if (pFrame->pict_type == AV_PICTURE_TYPE_I) wxMessageBox("I cadr");
if (pFrame->pict_type != AV_PICTURE_TYPE_I)
printMVMatrix(f, pFrame, pCodecCtx);
pFrameRGB->linesize[0]= pCodecCtx->width*3; // in case of rgb4 one plane
sws_scale(swsContext, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
//glGenTextures(1, &VideoTexture);
if ((*current_Vtex)==VideoTexture) current_Vtex = &VideoTexture2;else current_Vtex = &VideoTexture;
glBindTexture(GL_TEXTURE_2D, (*current_Vtex));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pCodecCtx->width, pCodecCtx->height, GL_RGB, GL_UNSIGNED_BYTE, pFrameRGB->data[0]);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pCodecCtx->width, pCodecCtx->height, 0, GL_RGB, GL_UNSIGNED_BYTE, pFrameRGB->data[0]);
//glDeleteTextures(1, &VideoTexture);
GLenum err;
while ((err = glGetError()) != GL_NO_ERROR)
{
cerr << "OpenGL error: " << err << endl;
}
// av_free(buffer);
}
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&packet);
if (f>1) break;
}
//av_free(pFrameRGB);
}
我得到的屏幕上的画面怪(绿色四边形和红色系是四边形的运动向量)
http://i.stack.imgur.com/9HJ9t.png
我得到的第一帧质量很好,观看也很正常,但随后一步一步将图片转化为如此奇怪的东西。几分钟的工作程序后,我甚至会在零等待帧时崩溃。 – user3177342
您的相机是否正常工作?你可以通过使用ffmpeg命令行来获得清晰的高质量视频吗? –
是的,ffplay(ffmpeg(libav)1.2)显示了这个rtsp流的正常视频。 – user3177342