ffmpeg学习4--ffmpeg类的简单封装,包含解码和定时录像功能

本文介绍了ffmpeg的学习第四部分,主要讲解如何对ffmpeg进行简单的类封装,实现视频解码和定时录像功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ffmpeg学习4--ffmpeg类的简单封装,包含解码和定时录像功能

        参考网上的资料,简单封装了一下ffmpeg,这里记录一下,其它传感器编码及项目中用到的已经抽离,这里只包含解码和录像部分。这只是个玩具级别的测试。完整测试代码下载:代码下载
   ffmpegDeCode.h
   
#pragma once
#include "stdafx.h"
#include<iostream>
using namespace std;
extern char *VideoPath;
extern int CameraIndex;
extern int fps;
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include <libavdevice/avdevice.h>  

};
class ffmpegDeCode
{
public:
	ffmpegDeCode();
	~ffmpegDeCode();
	bool DecoderInit(const char *sdpurl);
	void DecodeFrame();
	void DecodeLastFrame();
	void StopDecodeFrame();
	void GetopencvFrame();
	
	//////////解码部分////////
	AVFrame	*pFrame;//解码后的帧数据
	AVFormatContext	*pFormatCtx  ;//视频流编码上下文的指针
	int videoindex;//视频流索引
	AVCodecContext	*pCodecCtx;//用于编解码器的类型(视频,音频...)及设置
	AVCodec			*pCodec   ;//解码器指针
	long m_framenums;//帧序号
	SwsContext *img_convert_ctx;//根据编码信息设置渲染格式
	AVPacket *packet;////是存储压缩编码数据相关信息的结构体,数据流分包(一帧的分包)
	//1个AVPacket的data通常对应一个NAL。
	IplImage * pCVFrame ;
	char datatime[60];
	char Recordname[100];
	//////录像部分/////////
	AVStream *i_video_stream;
	AVFormatContext *opFormatCtx;
	AVStream *o_video_stream;
	void WriteVideoHead();
	void  WriteVideoTail();
	int m_recordframenums;
	int m_Toatlframenums;
	int last_pts ; 
	int last_dts;
	int64_t pts, dts; 
	int count;//录像文件计数
	
};

ffmpegDeCode.cpp
#include "stdafx.h"
#include"stdio.h"
#include"ffmpegDeCode.h"
#include "sqlite/sqlite3.h"
#include <fstream>
#include <windows.h> 
SYSTEMTIME sys; //系统时间
char systime[50];

ofstream outfile;//打印异常信息
ffmpegDeCode :: ffmpegDeCode()
{
	pFrame = NULL/**pFrameRGB = NULL*/;
	pFormatCtx  = NULL;
	videoindex=0;
	pCodecCtx   = NULL;
	pCodec      = NULL;
	m_framenums = 0;
	img_convert_ctx = NULL;
	packet = NULL;
	pCVFrame = NULL;
	//////////////
	i_video_stream= NULL;
	opFormatCtx= NULL;
	o_video_stream= NULL;
	m_recordframenums=1;
	last_pts = 0; 
	last_dts = 0;
	pts=0;
	dts=0;
	count=1;
	m_Toatlframenums=fps*60*60;//fps*3600
	memset(datatime, 0, 100*sizeof(char));
	memset(Recordname, 0, 100*sizeof(char));
	
}
ffmpegDeCode :: ~ffmpegDeCode()
{   
	WriteVideoTail();
	i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值