帧率是固定的。
现在决定写个变帧率的例子,第一分钟的帧率为10,第二分钟的帧率为5.
这个设置AVFrame的pts即可。
第一分钟,pts大致如下(以毫秒为单位):
100,200,300,400,500,600,700,800,900,1000,…
第二分钟,pts大致如下(以毫秒为单位):
60200,60400,60600,60800,61000
录制后,在播放时,会发现帧率为7,如下所示:

下面是代码结构

CaptureScreen.h内容如下:
#ifndef _CCAPTURE_SCREEN_HH
#define _CCAPTURE_SCREEN_HH
#include<time.h>
#include <d3d9.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <windows.h>
#include <tchar.h>
#include <winbase.h>
#include <winreg.h>
#include <Strsafe.h>
//
// ---抓屏类----
//
class CCaptureScreen
{
public:
CCaptureScreen(void);
~CCaptureScreen(void);
public:
/*-----------定义外部调用函数-----------*/
int Init(int&, int&);//初始化
BYTE* CaptureImage(); //抓取屏幕
private:
/*-----------定义内部调用函数-----------*/
void* CaptureScreenFrame(int, int, int, int);//抓屏
HCURSOR FetchCursorHandle(); //获取鼠标光标
private:
/*-----------定义私有变量-----------*/
int m_width;
int m_height;
UINT wLineLen;
DWORD dwSize;
DWORD wColSize;
//设备句柄
HDC hScreenDC;
HDC hMemDC;
//图像RGB内存缓存
PRGBTRIPLE m_hdib;
//位图头信息结构体
BITMAPINFO pbi;
HBITMAP hbm;
//鼠标光标
HCURSOR m_hSavedCursor;
};
#endif //--_CCAPTURE_SCREEN_HH
CaptureScreen.cpp的内容如下:
//#include "stdafx.h"
#include "CaptureScreen.h"
CCaptureScreen::CCaptureScreen(void)
{
m_hdib = NULL;
m_hSavedCursor = NULL;
hScreenDC = NULL;
hMemDC = NULL;
hbm = NULL;
m_width = 1920;
m_height = 1080;
FetchCursorHandle();
}
//
// 释放资源
//
CCaptureScreen::~CCaptureScreen(void)
{
DeleteObject(hbm);
if (m_hdib){
free(m_hdib);
m_hdib = NULL;
}
if (hScreenDC){
::ReleaseDC(NULL, hScreenDC);
}
if (hMemDC) {
DeleteDC(hMemDC);
}
if (hbm)
{
DeleteObject(hbm);
}
}
//
// 初始化
//
int CCaptureScreen::Init(int& src_VideoWidth, int& src_VideoHeight)
{
hScreenDC = ::GetDC(GetDesktopWindow());
if (hScreenDC == NULL) return 0;
int m_nMaxxScreen = GetDeviceCaps(hScreenDC, HORZRES);
int m_nMaxyScreen = GetDeviceCaps(hScreenDC, VERTRES);
hMemDC = ::CreateCompatibleDC(hScreenDC);
if (hMemDC == NULL) return 0;
m_width = m_nMaxxScreen;
m_height = m_nMaxyScreen;
if (!m_hdib){
m_hdib = (PRGBTRIPLE)malloc(m_width * m_height * 3);//24位图像大小
}
//位图头信息结构体
pbi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbi.bmiHeader.biWidth = m_width;
pbi.bmiHeader.biHeight = m_height;
pbi.bmiHeader.biPlanes = 1;
pbi.bmiHeader.biBitCount = 24;
pbi

本文介绍了一个使用FFmpeg实现变帧率录屏的例子,通过调整每帧的时间戳(pts)来改变不同时间段的帧率,例如第一分钟帧率为10fps,第二分钟变为5fps,并提供了完整的代码实现。
最低0.47元/天 解锁文章
3556

被折叠的 条评论
为什么被折叠?



