FFmpeg实现的简单视频编码器(YUV to H264)

该博客介绍了如何使用FFmpeg 4.3.1版本创建一个简单的视频编码器,将YUV格式的视频转换为H264编码。提供了encoder.h和encoder.cpp两个关键文件的概要,欢迎反馈和指正。
摘要由CSDN通过智能技术生成

FFmpeg实现的从YUV编码到H264的简单视频编码器,FFmpeg version = 4.3.1

encoder.h

#ifndef __ENCODER__
#define __ENCODER__

#include <iostream>
#include <string>
extern "C" {
   
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
}

#define FRAME_PRE_SECOND 25

class CEncoder {
   
public:
	CEncoder(std::string& infile, std::string& outfile);
	~CEncoder();
	void initialize();
	void compression(AVFrame* frame);
	void encode();
	
private:
	//*********** encode ***********
	std::string enInfilePath;
	std::string enOutfilePath;
	FILE* enInfile;
	uint8_t* rBuf;

	//*********** ffmpeg ***********
	AVFormatContext* pFmtCtx;
	AVCodecContext* pCodecCtx;
	AVStream* vStream;
	AVCodec* pCodec;
	AVPacket* pkt;
};

#endif //__ENCODER__

encoder.cpp

#include "encoder.h"

CEncoder::CEncoder(std::string& infile, std::string& outfile) : 
	//encode
	enInfilePath(infile),
	enOutfilePath(outfile),
	pFmtCtx(nullptr),
	vStream(nullptr),
	pCodecCtx(nullptr),
	pCodec(nullptr),
	rBuf(nullptr),
	enInfile(nullptr) {
    }

CEncoder::~CEncoder() {
   
	//free read file buffer
	if (!rBuf) {
   
		av_free(rBuf);
	}
	//free packet
	if (!pkt) {
   
		av_packet_free(&pkt);
	}
	//free AVCodecContext
	if (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值