使用ffms2(ffmpegsource)的视频解码
我使用ffms2(又名FFmpegSource)解码视频帧,并基于wxWidgets在UI上显示。 我的播放器适用于低分辨率视频(320*240、640*480),但对于高分辨率视频(1080),速度非常慢。我无法满足高分辨率视频所需的帧。 经过时间分析,我发现FFMS_GetFrame()帧函数对于高分辨率帧需要更长的时间。 以下是结果。 1.320*240 FFMS_GetFrame需要4-6ms 2.640*480 FFMS_GetFrame需要>20ms 3.1080*720 FFMS_GetFrame拍摄时间>40 这意味着我永远不会满足使用FFMS2的1080p帧每秒30帧的要求。但我不确定情况是否如此。 请提出可能出现的问题使用ffms2(ffmpegsource)的视频解码,ffmpeg,libav,Ffmpeg,Libav,我使用ffms2(又名FFmpegSource)解码视频帧,并基于wxWidgets在UI上显示。 我的播放器适用于低分辨率视频(320*240、640*480),但对于高分辨率视频(1080),速度非常慢。我无法满足高分辨率视频所需的帧。 经过时间分析,我发现FFMS_GetFrame()帧函数对于高分辨率帧需要更长的时间。 以下是结果。 1.320*240 FFMS_GetFrame需要4-6ms 2.640*480 FFMS_GetFrame需要>20ms 3.1080*720 FFMS_
void SetPosition(int64 pos)
{
uint8_t* data_ptr = NULL;
/*check if position is valid*/
if (!m_track || pos < 0 && pos > m_videoProp->NumFrames - 1)
return; // ERR_POS;
wxMilliClock_t start_wx_t = wxGetLocalTimeMillis();
long long start_t = start_wx_t.GetValue();
m_frameId = pos;
if(m_video)
{
m_frameProp = FFMS_GetFrame(m_video, m_frameId, &m_errInfo);
if(!m_frameProp) return;
if(m_frameProp)
{
m_width_ffms2 = m_frameProp->EncodedWidth;
m_height_ffms2 = m_frameProp->EncodedHeight;
}
wxMilliClock_t end_wx_t = wxGetLocalTimeMillis();
long long end_t = end_wx_t.GetValue();
long long diff_t = end_t - start_t;
wxLogDebug(wxString(wxT("Frame Grabe Millisec") + ToString(diff_t)));
//m_frameInfo = FFMS_GetFrameInfo(m_track, FFMS_TYPE_VIDEO);
/* If you want to change the output colorspace or resize the output frame size, now is the time to do it.
IMPORTANT: This step is also required to prevent resolution and colorspace changes midstream. You can
always tell a frame's original properties by examining the Encoded properties in FFMS_Frame. */
/* A -1 terminated list of the acceptable output formats (see pixfmt.h for the list of pixel formats/colorspaces).
To get the name of a given pixel format, strip the leading PIX_FMT_ and convert to lowercase. For example,
PIX_FMT_YUV420P becomes "yuv420p". */
#if 0
int pixfmt[2];
pixfmt[0] = FFMS_GetPixFmt("bgr24");
pixfmt[1] = -1;
#endif
// FFMS_SetOutputFormatV2 returns 0 on success. It Returns non-0 and sets ErrorMsg on failure.
int failure = FFMS_SetOutputFormatV2(m_video, pixfmt, m_width_ffms2, m_height_ffms2, FFMS_RESIZER_BICUBIC, &m_errInfo);
if (failure)
{
//FFMS_DestroyVideoSource(m_video);
//m_video = NULL;
return; //return ERR_POS;
}
data_ptr = m_frameProp->Data[0];
}
else
{
m_width_ffms2 = 320;
m_height_ffms2 = 240;
}
if(data_ptr)
{
memcpy(m_buf, data_ptr, 3*m_height_ffms2 * m_width_ffms2);
}
else
{
memset(m_buf, 0, 3*m_height_ffms2 * m_width_ffms2);
}
}
void设置位置(int64位置)
{
uint8_t*数据_ptr=NULL;
/*检查位置是否有效*/
如果(!m|u track | pos<0&&pos>m|u videoProp->NumFrames-1)
return;//ERR\u POS;
wxMilliClock_t start_wx_t=wxGetLocalTimeMillis();
long long start_t=start_wx_t.GetValue();
m_frameId=pos;
if(MU视频)
{
m_frameProp=FFMS_GetFrame(m_视频、m_frameId和m_errInfo);
如果(!m_frameProp)返回;
if(m_frameProp)
{
m_width_ffms2=m_frameProp->EncodedWidth;
m_height_ffms2=m_frameProp->EncodedHeight;
}
wxMilliClock_t end_wx_t=wxGetLocalTimeMillis();
long long end_t=end_wx_t.GetValue();
长-长差异=结束-开始;
wxLogDebug(wxString(wxT(“帧捕获毫秒”)+ToString(diff_t));
//m_frameInfo=FFMS_GetFrameInfo(m_曲目,FFMS_类型\u视频);
/*如果要更改输出颜色空间或调整输出帧大小,现在是时候了。
重要提示:这一步也是防止分辨率和颜色空间中途改变所必需的。您可以
始终通过检查FFMS_帧中的编码属性来说明帧的原始属性*/
/*A-1可接受输出格式的终止列表(像素格式/颜色空间列表见pixfmt.h)。
要获取给定像素格式的名称,请去掉前导的PIX_FMT_并转换为小写。例如,
PIX_FMT_YUV420P变为“YUV420P”*/
#如果0
int-pixfmt[2];
pixfmt[0]=FFMS_GetPixFmt(“bgr24”);
pixfmt[1]=-1;
#恩迪夫
//FFMS_SetOutputFormatV2在成功时返回0。在失败时返回非0并设置ErrorMsg。
int failure=FFMS_设置输出格式v2(m_视频、pixfmt、m_宽度、ffms2、m_高度、ffms2、FFMS_大小调整器、双三次和m_错误信息);
如果(失败)
{
//FFMS_视频源(m_视频);
//m_video=NULL;
return;//return ERR\u POS;
}
data_ptr=m_frameProp->data[0];
}
其他的
{
m_宽度_ffms2=320;
m_高度_ffms2=240;
}
如果(数据检查)
{
memcpy(m_buf,数据ptr,3*m_高度\u ffms2*m_宽度\u ffms2);
}
其他的
{
memset(m_buf,0,3*m_高度\u ffms2*m_宽度\u ffms2);
}
}
较大帧的较慢视频解码是完全正常的。1080x720的像素数大约是320x240的十倍,因此让GetFrame花费大约十倍的时间并不令人惊讶(这不是严格的线性关系,因为有很多其他因素影响解码速度,但像素数和解码时间是相当相关的)
为每一帧设置输出格式是不必要的,这将使事情变得更慢。除非您特别希望更改输出格式,否则您应该在打开视频后调用它一次,然后它将应用于请求的所有帧。您是对的,我看到此设置输出格式会额外增加10-20毫秒的延迟。我将尝试在开始时设置一次,然后查看它的行为。然而,如果你有更多的建议,请分享。现在我将把这个答案标记为正确。