1.2 快進/慢放 (續) — 參考上篇 PORT、m_strPlayFileName、OpenFile() 定義
VC++ 完整邏輯:速度層級與 B 幀丟棄聯動
void CPlayerDlg::OnFastForward()
{
if(Hik_PlayM4_Fast(PORT))
{
m_nSpeed++;
if(m_nSpeed > 0) OnThrow2(); // 速度>正常時丟 2 個 B 幀
SetFastForwardState();
}
}
void CPlayerDlg::OnFastBackward()
{
if(Hik_PlayM4_Slow(PORT))
{
m_nSpeed--;
if(m_nSpeed <= 0) OnThrow0(); // 速度<=正常時不丟幀
SetFastBackWardState();
}
}
C# 完整實作
private int m_nSpeed = 0;
///
/// 快進按鈕
///
private void btnFastForward_Click(object sender, EventArgs e)
{
if (HikPlayer.Hik_PlayM4_Fast(PORT))
{
m_nSpeed++;
if (m_nSpeed > 0)
OnThrow2(); // 丟棄 2 個 B 幀
}
}
///
/// 慢放按鈕
///
private void btnFastBackward_Click(object sender, EventArgs e)
{
if (HikPlayer.Hik_PlayM4_Slow(PORT))
{
m_nSpeed--;
if (m_nSpeed <= 0)
OnThrow0(); // 恢復不丟幀
}
}
///
/// 不丟棄 B 幀 (正常/慢速)
///
public void OnThrow0()
{
HikPlayer.Hik_PlayM4_ThrowBFrameNum(PORT, 0);
}
///
/// 丟棄 2 個 B 幀 (快速播放提升效能)
///
public void OnThrow2()
{
HikPlayer.Hik_PlayM4_ThrowBFrameNum(PORT, 2);
}
技術原理說明
| 速度層級 | m_nSpeed 值 | B 幀處理 | API 呼叫 |
| 正常 | 0 | 全解碼 | ThrowBFrameNum(0) |
| 2倍速 | 1 | 丟 2 個 B 幀 | ThrowBFrameNum(2) |
| 4倍速 | 2 | 丟 2 個 B 幀 | ThrowBFrameNum(2) |
| 8倍速 | 3 | 丟 2 個 B 幀 | ThrowBFrameNum(2) |
| 16倍速 | 4 | 丟 2 個 B 幀 | ThrowBFrameNum(2) |
| 1/2倍速 | -1 | 全解碼 | ThrowBFrameNum(0) |
| 1/4倍速 | -2 | 全解碼 | ThrowBFrameNum(0) |
- B 幀特性:雙向預測幀,解碼需參考前後 I/P 幀,運算量大
- 丟棄策略:快轉時丟棄 B 幀可大幅降低解碼負載,畫面雖較不流暢但能維持高倍速播放
- 慢放不丟幀:慢動作需完整畫面細節,保留所有 B 幀