資源簡介
rtmpdump實現flv視頻推流demo程序
代碼片段和文件信息
#include?
#include?
#include?
#include?
#ifndef?WIN32
#include?
#endif
#include?“librtmp/rtmp_sys.h“
#include?“librtmp/log.h“
?
#define?HTON16(x)??((x>>8&0xff)|(x<<8&0xff00))
#define?HTON24(x)??((x>>16&0xff)|(x<<16&0xff0000)|(x&0xff00))
#define?HTON32(x)??((x>>24&0xff)|(x>>8&0xff00)|\
?????????(x<<8&0xff0000)|(x<<24&0xff000000))
#define?HTONTIME(x)?((x>>16&0xff)|(x<<16&0xff0000)|(x&0xff00)|(x&0xff000000))
#define?RTMP_SERVER_URL?????“rtmp://172.16.1.65:1935/test1/myStream“
#define?LOCAL_FILE??????????“test.flv“
/*read?1?byte*/
int?ReadU8(uint32_t?*u8FILE*fp){
?????????if(fread(u811fp)!=1)
???????????????????return?0;
?????????return?1;
}
/*read?2?byte*/
int?ReadU16(uint32_t?*u16FILE*fp){
?????????if(fread(u1621fp)!=1)
???????????????????return?0;
?????????*u16=HTON16(*u16);
?????????return?1;
}
/*read?3?byte*/
int?ReadU24(uint32_t?*u24FILE*fp){
?????????if(fread(u2431fp)!=1)
???????????????????return?0;
?????????*u24=HTON24(*u24);
?????????return?1;
}
/*read?4?byte*/
int?ReadU32(uint32_t?*u32FILE*fp){
?????????if(fread(u3241fp)!=1)
???????????????????return?0;
?????????*u32=HTON32(*u32);
?????????return?1;
}
/*read?1?byteand?loopback?1?byte?at?once*/
int?PeekU8(uint32_t?*u8FILE*fp){
?????????if(fread(u811fp)!=1)
???????????????????return?0;
?????????fseek(fp-1SEEK_CUR);
?????????return?1;
}
/*read?4?byte?and?convert?to?time?format*/
int?ReadTime(uint32_t?*utimeFILE*fp){
?????????if(fread(utime41fp)!=1)
???????????????????return?0;
?????????*utime=HTONTIME(*utime);
?????????return?1;
}
?
int?InitSockets()
{
????/*
?????????WORD?version;
?????????WSADATA?wsaData;
?????????version=MAKEWORD(22);
?????????return?(WSAStartup(version?&wsaData)?==?0);
?????????*/
????????return?1;
}
?
void?CleanupSockets()
{
????????//?WSACleanup();
????????return;
}
?
//Publish?using?RTMP_SendPacket()
int?publish_using_packet(){
?????????RTMP?*rtmp=NULL;???????????????????????????
?????????RTMPPacket?*packet=NULL;
?????????uint32_t?start_time=0;
?????????uint32_t?now_time=0;
?????????uint32_t?add_time_times=0;
?????????//the?timestamp?of?the?previous?frame
?????????long?pre_frame_time=0;
?????????long?lasttime=0;
?????????//int?bNextIsKey=1;
?????????uint32_t?preTagsize=0;
????????
?????????//packet?attributes
?????????uint32_t?type=0;???????????????????????
?????????uint32_t?datalength=0;???????????
?????????uint32_t?timestamp=0;???????????
?????????uint32_t?streamid=0;????????????????????????
?
?????????FILE*fp=NULL;
?????????fp=fopen(LOCAL_FILE“rb“);
?????????if?(!fp){
???????????????????RTMP_LogPrintf(“Open?File?Error.\n“);
???????????????????CleanupSockets();
???????????????????return?-1;
?????????}
?????????
?????????/*?set?log?level?*/
?????????//RTMP_LogLevel?loglvl=RTMP_LOGDEBUG;
?????????//RTMP_LogSetLevel(loglvl);
?????????if?(!InitSockets()){
???????????????????RTMP
- 上一篇:H3C網絡學院 路由交換第一卷下冊高清版
- 下一篇:人頭檢測樣本
評論
共有 條評論