【问题标题】:Video decoding using ffms2 (ffmpegsource)使用 ffms2 (ffmpegsource) 进行视频解码
【发布时间】:2013-06-22 04:21:47
【问题描述】:

我正在使用 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 fps 要求。但我不确定是否是这种情况。 请提出可能出了什么问题。

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);    
   }
}

【问题讨论】:

    标签: ffmpeg libav


    【解决方案1】:

    较大帧的视频解码速度较慢是完全正常的。 1080x720 的像素大约是 320x240 的十倍,因此让 GetFrame 花费大约十倍的时间也就不足为奇了(这不是严格的线性关系,因为影响解码速度的还有很多其他因素,而是像素数和解码时间是相当相关的)。

    为每一帧设置输出格式是不必要的,这会使事情变得更慢。除非您特别希望更改输出格式,否则您应该在打开视频后只调用一次,它将应用于之后请求的所有帧。

    【讨论】:

    • 你是对的,我已经看到这种设置输出格式增加了 10-20 毫秒的延迟。我会尝试在开始时设置一次,看看它的表现如何。但是,如果您有更多建议,请分享。现在我将这个答案标记为正确。
    猜你喜欢
    • 2013-04-25
    • 1970-01-01
    • 2011-10-22
    • 2019-03-16
    • 2013-12-26
    • 2013-07-13
    • 2020-10-13
    • 2020-03-21
    • 2020-09-24
    相关资源
    最近更新 更多