资源简介
此代码封装了H264编解码和RTSP传输协议库,经过测试,此库可以直接调用,从本地的摄像头采集图像,经过H264编码、在本地计算机上建立RTSP Server,网络内的其它计算机可以通过RTSP Client进行访问拉流、也可以通过VLC软件进行直接访问。
代码片段和文件信息
// RtspService.cpp : Defines the entry point for the console application.
//
#include “stdafx.h“
#include “RtspService.h“
#include “MediaStreamH264.h“
#include “MediaStreamMP4ALatm.h“
#ifdef __cplusplus
extern “C“ {
#endif
#include “libavcodec/avcodec.h“
#include “libavformat/avformat.h“
#include “libswscale/swscale.h“
#include “libavutil/avutil.h“
#include “libavutil/opt.h“
#include “libavutil/frame.h“
#ifdef __cplusplus
}
#endif
RtspService_t* g_pRtspService = NULL;
AVCodecContext *c= NULL;
SwsContext * scxt = NULL;
CRITICAL_SECTION crtsection;
char g_pBmpData[1024*1024*3];
int g_nBmpSize = 0;
int g_nWidth g_nHeight;
bool g_exitcodecthread = false;
void H264CodecThread(LPVOID lpParam);
//1.
int StreamServerInit(int width int height)
{
InitializeCriticalSection(&crtsection);
g_nWidth = width;
g_nHeight = height;
av_register_all();
avcodec_register_all();
AVCodec *pCodecH264; //编码器
//查找h264编码器
pCodecH264 = avcodec_find_encoder(AV_CODEC_ID_H264);
if(!pCodecH264)
{
fprintf(stderr “h264 codec not found\n“);
return 0;
}
c= avcodec_alloc_context3(pCodecH264);
// c->bit_rate = 3000000;// put sample parameters
c->bit_rate = 400000;
c->rc_max_rate = 400000;
c->rc_min_rate = 400000;
c->rc_buffer_size = 200000;
c->width =g_nWidth;
c->height = g_nHeight;
// frames per second
AVRational rate;
rate.num = 1;
rate.den = 25; //帧率
c->time_base= rate;//(AVRational){125};
c->gop_size = 250; // emit one intra frame every ten frames
c->max_b_frames=0;
c->thread_count = 1;
c->pix_fmt = AV_PIX_FMT_YUV420P;//PIX_FMT_RGB24;
av_opt_set(c->priv_data “preset“ “superfast“ 0);
av_opt_set(c->priv_data “tune“ “zerolatency“ 0);
//打开编码器
if(avcodec_open2(cpCodecH264NULL)<0)
{
fprintf(stderr “不能打开编码库\n“);
return -1;
}
//初始化SwsContext
scxt = sws_getContext(g_nWidthg_nHeightAV_PIX_FMT_GRAY8g_nWidthg_nHeightAV_PIX_FMT_YUV420PSWS_POINTNULLNULLNULL);
if (NULL == scxt)
{
return -2;
}
g_exitcodecthread = false;
DWORD ThreadId;
HANDLE handle = CreateThread(NULL NULL (LPTHREAD_START_ROUTINE)H264CodecThread NULL NULL &ThreadId);
return 0;
}
//2-2
void H264CodecThread(LPVOID lpParam)
{
AVframe *m_pRGBframe = new AVframe[1]; //RGB帧数据
AVframe *m_pYUVframe = new AVframe[1]; //YUV帧数据s
m_pYUVframe->pts = 0;
AVCodecContext *in_c= NULL;
uint8_t * yuv_buff;
int size = g_nWidth * g_nHeight;
yuv_buff = (uint8_t *) malloc((size * 3) / 2); // size for YUV 420
//将rgb图像数据填充rgb帧
char * rgb_buff = new char[1024 * 1024 * 3];
//图象编码
int outbuf_size=2000000;
uint8_t * outbuf= (uint8_t*)malloc(outbuf_size);
int u_size = 0;
AVPacket avpkt;
while(true)
{
EnterCriticalSection(&crtsection);
if(g_exitcodecthread)
{
LeaveCriticalSection(&crtsection);
break;
}
if (g_nBmpSize > 0)
{
memcpy(rgb_buffg_pBmpData g_n
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1034 2017-09-11 11:45 VideoStreamServerDLL(备份)\clear.bat
文件 11362830 2017-09-11 11:46 VideoStreamServerDLL(备份)\Debug\avcodec-57.dll
文件 2232846 2017-09-11 11:46 VideoStreamServerDLL(备份)\Debug\avformat-57.dll
文件 482318 2017-09-11 11:46 VideoStreamServerDLL(备份)\Debug\avutil-55.dll
文件 396288 2017-11-10 14:52 VideoStreamServerDLL(备份)\Debug\D3DRender.dll
文件 122880 2017-11-10 14:52 VideoStreamServerDLL(备份)\Debug\libfaac.dll
文件 112142 2017-09-11 11:58 VideoStreamServerDLL(备份)\Debug\libgcc_s_dw2-1.dll
文件 1408750 2017-09-11 11:58 VideoStreamServerDLL(备份)\Debug\libiconv-2.dll
文件 143296 2017-11-10 14:52 VideoStreamServerDLL(备份)\Debug\libvlc.dll
文件 2631616 2017-11-10 14:52 VideoStreamServerDLL(备份)\Debug\libvlccore.dll
文件 1030120 2017-09-11 11:46 VideoStreamServerDLL(备份)\Debug\libx264-148.dll
文件 1460483 2017-11-10 14:52 VideoStreamServerDLL(备份)\Debug\libx264.dll
文件 116750 2017-09-11 11:46 VideoStreamServerDLL(备份)\Debug\swresample-2.dll
文件 525838 2017-09-11 11:46 VideoStreamServerDLL(备份)\Debug\swscale-4.dll
文件 142552 2017-09-11 11:58 VideoStreamServerDLL(备份)\Debug\tbb_Debug.dll
文件 332800 2017-11-13 18:09 VideoStreamServerDLL(备份)\Debug\VideoStream.dll
文件 938 2017-11-13 11:34 VideoStreamServerDLL(备份)\Debug\VideoStream.exp
文件 1304656 2017-11-13 11:34 VideoStreamServerDLL(备份)\Debug\VideoStream.ilk
文件 2280 2017-11-13 11:34 VideoStreamServerDLL(备份)\Debug\VideoStream.lib
文件 2124800 2017-11-13 11:34 VideoStreamServerDLL(备份)\Debug\VideoStream.pdb
文件 87552 2017-11-13 11:46 VideoStreamServerDLL(备份)\Release\VideoStream.dll
文件 968 2017-11-13 11:46 VideoStreamServerDLL(备份)\Release\VideoStream.exp
文件 2280 2017-11-13 11:46 VideoStreamServerDLL(备份)\Release\VideoStream.lib
文件 1264640 2017-11-13 11:46 VideoStreamServerDLL(备份)\Release\VideoStream.pdb
文件 1660 2017-09-11 11:45 VideoStreamServerDLL(备份)\sunday\aac.h
文件 8352 2017-11-13 11:32 VideoStreamServerDLL(备份)\sunday\Debug\Bitstream.obj
文件 20446 2017-11-13 11:34 VideoStreamServerDLL(备份)\sunday\Debug\cl.command.1.tlog
文件 285986 2017-11-13 11:34 VideoStreamServerDLL(备份)\sunday\Debug\CL.read.1.tlog
文件 11296 2017-11-13 11:34 VideoStreamServerDLL(备份)\sunday\Debug\CL.write.1.tlog
文件 2 2017-11-13 11:34 VideoStreamServerDLL(备份)\sunday\Debug\li
............此处省略300个文件信息
- 上一篇:大话通信:通信基础知识读本.pdf
- 下一篇:概率论基础教程_M.ROSS
相关资源
- 将rtsp转码为flv格式用于h5播放前端使
- rtsp-h264.zip
- websocket-rtsp-proxy-test.zip
- MP4v2录制rtsp流存为MP4文件
- rtsp摄像头推流上云使用浏览器播放
-
ijkpla
yer 最新rtsp .ts so库 - rtsp大全
- rtsp视频组帧(tcp和udp)
-
能够播放rtsp的ijkpla
yer动态库 - qt5.8实现rtsp流播放
- RtspRtcpRtpLoad_h264.tar.gz
- live555通过VS2013编译,自己整理的,附
- 简单的RTSP RTP RTCP推送H264码流服务器实
- 支持高版本谷歌播放rtsp的插件vxg me
- rtsp 服务器代码,VC可编译使用,RTS
- RTSP流媒体客户端播放器demo
- FLV测试文件,亲身验证,用过VLC可以
- RTSP_RFC2326(中文版).pdf
- zw_csharp_ffmpeg_rtsp_demo.zip
- h264码流rtp传输demo
- ActiveX RTSP实时流媒体播放器 支持录像
- onvif rtsp流对接
- VLC播放RTSP流
- 获取摄像头ip与视频流
- rtsp_server C 源码详解与分析
- live555 RTSP RTCP RTP。live555类关系图,
- A10-rtsph264_硬件编码.zip
- ONVIF RTSP查看助手
-
rtspPla
yer.rar - GB28181转RTSP、RTMP和HLS
评论
共有 条评论