资源简介
C++ 通过FFmpeg将rtsp视频流到本地mp4文件,源代码仅供参考。
代码片段和文件信息
#pragma once
#include “MP4Encoder.h“
//#pragma comment(lib “../lib/libmp4v2.lib“)
#define INVALID_PTS 0xFFFFFFFFFFFFFFFF
#define DEFAULT_VIDEO_TRACK_NUM 3
#define DEFAULT_VIDEO_PROFILE_LEVEL 1
#define DEFAULT_AUDIO_PROFILE_LEVEL 2
MP4Encoder::MP4Encoder(void)
: m_hFile(MP4_INVALID_FILE_HANDLE)
m_videoTrack(MP4_INVALID_TRACK_ID)
m_audioTrack(MP4_INVALID_TRACK_ID)
{
}
MP4Encoder::~MP4Encoder(void)
{
}
int MP4Encoder::MP4CreateFile(const char *sFileNameint Movie_Time_Scale)
{
m_hFile = MP4Create(sFileName);
if (m_hFile == MP4_INVALID_FILE_HANDLE)
{
printf(“create mp4 file error!\n“);
return -1;
}
if (!MP4SetTimeScale(m_hFile Movie_Time_Scale))
{
printf(“set time Scale error!\n“);
return -1;
}
return 0;
}
int MP4Encoder::MP4AddH264Track(const uint8_t *sData int nSize
int nWidth int nHeight int nframeRate int Video_Time_Scale)
{
int sps pps;
for (sps = 0; sps < nSize;)
if (sData[sps++] == 0x00 && sData[sps++] == 0x00 && sData[sps++] == 0x00
&& sData[sps++] == 0x01)
break;
for (pps = sps; pps < nSize;)
if (sData[pps++] == 0x00 && sData[pps++] == 0x00 && sData[pps++] == 0x00
&& sData[pps++] == 0x01)
break;
if (sps >= nSize || pps >= nSize)
return -1;
m_videoTrack = MP4AddH264VideoTrack(m_hFile Video_Time_Scale
Video_Time_Scale / nframeRate nWidth nHeight
sData[sps + 1] sData[sps + 2] sData[sps + 3] DEFAULT_VIDEO_TRACK_NUM);//sps 后面的三个字节
if (MP4_INVALID_TRACK_ID == m_videoTrack)
{
printf(“add video track error!\n“);
return -1;
}
MP4SetVideoProfileLevel(m_hFile DEFAULT_VIDEO_PROFILE_LEVEL);
MP4AddH264SequenceParameterSet(m_hFile m_videoTrack sData + spspps - sps - 4);//sps 内容 起始位置+长度
MP4AddH264PictureParameterSet(m_hFile m_videoTrack sData + ppsnSize - pps);// pps 内容 起始位置+长度
return 0;
}
int MP4Encoder::MP4AddAACTrack(const uint8_t *sData int nSizeint Audio_Time_Scale)
{
m_audioTrack = MP4AddAudioTrack(m_hFile Audio_Time_Scale
/**
* In fact this is not a magic number. A formula might be:
* SampleRate * ChannelNum * 2 / SampleFormat
* 8000 * 1 * 2 / 16 (字节对齐,这里是 AV_SAMPLE_FMT_S16)
*/
1024 MP4_MPEG4_AUDIO_TYPE);
if (MP4_INVALID_TRACK_ID == m_audioTrack)
{
printf(“add audio track error!\n“);
return -1;
}
MP4SetAudioProfileLevel(m_hFile DEFAULT_AUDIO_PROFILE_LEVEL);
if (!MP4SetTrackESConfiguration(m_hFile m_audioTrack sData nSize))
{
printf(“set track ESConfiguration error!\n“);
return -1;
}
return 0;
}
int MP4Encoder::MP4WriteH264Data(uint8_t *sData int nSizeuint64_t video_cur_pts)
{
bool result = false;
sData[0] = (nSize - 4) >> 24;
sData[1] = (nSize - 4) >> 16;
sData[2] = (nSize - 4) >> 8;
sData[3] = nSize - 4;
if(nSize<0||sData==NULL)
return -1;
if ((sData[4] & 0x1F) == 5)//判断I帧
result = MP4WriteSample(m_hFile m_videoTrack sData nSizeMP4_INVALID_DURATION0true);
else
result =
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-07-31 11:40 MP4Record\
目录 0 2019-08-06 16:41 MP4Record\MP4Recorder\
目录 0 2019-07-31 11:41 MP4Record\MP4Recorder\.vs\
目录 0 2019-07-31 11:41 MP4Record\MP4Recorder\.vs\MP4Recorder\
目录 0 2019-07-31 11:41 MP4Record\MP4Recorder\.vs\MP4Recorder\v14\
文件 50176 2019-07-31 12:03 MP4Record\MP4Recorder\.vs\MP4Recorder\v14\.suo
目录 0 2019-08-01 15:17 MP4Record\MP4Recorder\Debug\
文件 31476736 2018-07-25 16:07 MP4Record\MP4Recorder\Debug\avcodec-58.dll
文件 1307136 2018-07-25 16:07 MP4Record\MP4Recorder\Debug\avdevice-58.dll
文件 6681600 2018-07-25 16:07 MP4Record\MP4Recorder\Debug\avfilter-7.dll
文件 5897216 2018-07-25 16:07 MP4Record\MP4Recorder\Debug\avformat-58.dll
文件 671232 2018-07-25 16:07 MP4Record\MP4Recorder\Debug\avutil-56.dll
文件 616960 2014-06-10 15:48 MP4Record\MP4Recorder\Debug\libmp4v2.dll
文件 8247888 2013-06-09 19:53 MP4Record\MP4Recorder\Debug\mfc110ud.dll
文件 821224 2012-11-06 02:20 MP4Record\MP4Recorder\Debug\msvcp110d.dll
文件 1697232 2012-11-06 02:20 MP4Record\MP4Recorder\Debug\msvcr110d.dll
文件 116736 2018-07-25 16:07 MP4Record\MP4Recorder\Debug\postproc-55.dll
文件 324608 2018-07-25 16:07 MP4Record\MP4Recorder\Debug\swresample-3.dll
文件 513024 2018-07-25 16:07 MP4Record\MP4Recorder\Debug\swscale-5.dll
目录 0 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\
目录 0 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\
文件 17160 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Encoder.obj
文件 2988 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.Build.CppClean.log
文件 69 2018-08-22 19:42 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.lastbuildstate
文件 3579 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.log
目录 0 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.tlog\
文件 42504 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.tlog\CL.read.1.tlog
文件 1586 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.tlog\CL.write.1.tlog
文件 211 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.tlog\MP4Recorder.lastbuildstate
文件 1554 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.tlog\cl.command.1.tlog
文件 0 2019-08-01 15:17 MP4Record\MP4Recorder\MP4Recorder\Debug\MP4Recorder.tlog\unsuccessfulbuild
............此处省略157个文件信息
相关资源
- windows下的ffmpeg、MFC制作的播放器
- FFmpeg x86 x64库
- C H264格式 转MP4格式
- MP4文件切片生成TS和M3U8文件
- C++ ffmpeg Release版本
- ffplay for MFC 1.0.1
- live555&RTSP;源码解析笔记
- MFC读取RTSP视频流
- RTMP/RTSP推流组件推送AAC到EasyDarwin
- MFC实现rtsp视频流的播放
- 非常完整的ffmpeg+mfc播放器
- ffmpeg简易播放器-音视频同步
- C++ 解析rtsp流后返回Iplimage,用Opengl显
- 使用RTP协议发送和接收H264的(支持解
- ffmpeg for MFC 1.2 测试版
- RTSP PUSH tcp udp h264 easydarwin
- Qt/C++模仿酷狗音乐播放器执行文件
- C#开发FFMPEG(API方式) FFmpeg拉取RTMP流
- FFMpeg_FFPlay 源码剖析(杨书良)
- H264视频解压缩封装 c++
- C++ MP4v2获取rtsp流并保存为MP4文件
- ffmpeg-20191004-e6625ca-win64-static.rar
- VS2019编译的32位最新版ffmpeg类库文件
- C++ RTSP/RTP流媒体客户端源码
- RTSP服务器 C语言
- RTSP_Client.c
- RTSP请求客户端
- 最小RTSP服务器,C语言代码
- linux下最小RTSP服务器实现
- yasm FFmpeg必备
评论
共有 条评论