C++使用ffmpeg读取MP4文件,转换编码为H264,上传到rtsp服务器上

//
// @brief: 使用FFmpeg的库,实现MP4视频读取,转换成H264格式流,上传到rtsp的操作
// @copyright: 无
// @license:无
// @birth: created by lmc on 2025-02-21
// @version: V1.1.1
// @revision: last revised by lvlv on 2025-02-21
//

#include

//用C的规则调用库
extern “C” {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h>
#include <libavutil/avutil.h>
#include <libswscale/swscale.h>
}

#include"windows.h"

//获取同级目录信息
std::string getCurrentDirectory() {
char buffer[MAX_PATH];
// 获取当前可执行文件的完整路径
GetModuleFileNameA(NULL, buffer, MAX_PATH);
std::string fullPath(buffer);
// 查找最后一个反斜杠的位置
size_t pos = fullPath.find_last_of(“\”);
if (pos != std::string::npos) {
// 截取到最后一个反斜杠之前的部分,即为同级目录
return fullPath.substr(0, pos);
}
return “”;
}

//计数器
int num = 0;

//ffmpeg相关参数
AVFormatContext* input_ctx = nullptr;//输入流
AVCodecContext* encoder_ctx = nullptr;//输出编码上下文信息
AVFormatContext* output_ctx = nullptr;//输出流
//释放资源
void free()
{

avcodec_free_context(&encoder_ctx);
avformat_close_input(&input_ctx);
avformat_free_context(output_ctx);

std::
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值