//
// @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::