当前位置: 首页 > news >正文

网站多级导航效果济南做seo的公司排名

网站多级导航效果,济南做seo的公司排名,wordpress自动发布文章待审,网站建设流程报价要实现 CRtpSendPs 类,使其能够将 H264 数据通过 RTP PS 流推送到指定的 URL,并支持 TCP 和 UDP 传输方式,您需要使用 FFmpeg 库。以下是该类的实现示例,包括必要的初始化、推流和退出函数。 步骤 初始化 FFmpeg 库:…

要实现 CRtpSendPs 类,使其能够将 H264 数据通过 RTP PS 流推送到指定的 URL,并支持 TCP 和 UDP 传输方式,您需要使用 FFmpeg 库。以下是该类的实现示例,包括必要的初始化、推流和退出函数。

步骤

  1. 初始化 FFmpeg 库:需要初始化 FFmpeg 网络、格式和编码器相关的库。
  2. 配置 RTP 传输:使用 RTP 封装 PS (Program Stream) 格式。
  3. 推送数据:接收 H264 数据并将其封装为 RTP 包,发送到指定的目标 URL(支持 UDP 和 TCP)。
  4. 退出处理:释放相关资源。

完整代码实现

 
#include <iostream>
#include <string>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include <libavdevice/avdevice.h>
#include <libavfilter/avfilter.h>
#include <libswscale/swscale.h>class CRtpSendPs
{
public:CRtpSendPs();~CRtpSendPs();int Init(const char *url, bool bUdpOrTcp);  // 初始化,设置目标 URL 和传输协议int PushStream(const void *pH264Data, uint32_t u32Len);  // 推送视频数据int Exit();  // 清理资源private:AVFormatContext *outputFmtCtx;AVStream *outputStream;AVCodecContext *codecCtx;AVPacket pkt;bool isUdp;std::string outputUrl;bool isInitialized;
};CRtpSendPs::CRtpSendPs() : outputFmtCtx(nullptr), outputStream(nullptr), codecCtx(nullptr), isInitialized(false)
{av_register_all();avformat_network_init();avcodec_register_all();avdevice_register_all();isUdp = true;isInitialized = false;
}CRtpSendPs::~CRtpSendPs()
{Exit();
}int CRtpSendPs::Init(const char *url, bool bUdpOrTcp)
{if (isInitialized) {std::cerr << "Already initialized!" << std::endl;return -1;}isUdp = bUdpOrTcp;outputUrl = url;// Create output contextAVOutputFormat *fmt = av_guess_format(NULL, outputUrl.c_str(), NULL);if (!fmt) {std::cerr << "Could not guess output format!" << std::endl;return -1;}int ret = avformat_alloc_output_context2(&outputFmtCtx, fmt, NULL, outputUrl.c_str());if (ret < 0) {std::cerr << "Failed to create output context!" << std::endl;return ret;}// Create a new stream for the outputoutputStream = avformat_new_stream(outputFmtCtx, NULL);if (!outputStream) {std::cerr << "Failed to create new stream!" << std::endl;return AVERROR(ENOMEM);}// Setup codec parameters (for H264)AVCodec *encoder = avcodec_find_encoder(AV_CODEC_ID_H264);if (!encoder) {std::cerr << "H264 encoder not found!" << std::endl;return AVERROR_ENCODER_NOT_FOUND;}codecCtx = avcodec_alloc_context3(encoder);if (!codecCtx) {std::cerr << "Failed to allocate codec context!" << std::endl;return AVERROR(ENOMEM);}codecCtx->codec_id = AV_CODEC_ID_H264;codecCtx->bit_rate = 1000000;codecCtx->width = 1920;codecCtx->height = 1080;codecCtx->time_base = {1, 30};  // 30 fpscodecCtx->gop_size = 12;codecCtx->max_b_frames = 3;codecCtx->pix_fmt = AV_PIX_FMT_YUV420P;ret = avcodec_open2(codecCtx, encoder, NULL);if (ret < 0) {std::cerr << "Failed to open codec!" << std::endl;return ret;}// Copy codec parameters to the streamret = avcodec_parameters_from_context(outputStream->codecpar, codecCtx);if (ret < 0) {std::cerr << "Failed to copy codec parameters!" << std::endl;return ret;}// Open the output file or network streamif (!(outputFmtCtx->oformat->flags & AVFMT_NOFILE)) {ret = avio_open(&outputFmtCtx->pb, outputUrl.c_str(), AVIO_FLAG_WRITE);if (ret < 0) {std::cerr << "Failed to open output URL!" << std::endl;return ret;}}// Write the header of the file (or stream)ret = avformat_write_header(outputFmtCtx, NULL);if (ret < 0) {std::cerr << "Failed to write header!" << std::endl;return ret;}isInitialized = true;return 0;
}int CRtpSendPs::PushStream(const void *pH264Data, uint32_t u32Len)
{if (!isInitialized) {std::cerr << "Not initialized!" << std::endl;return -1;}// Create a packet and fill it with H264 dataav_init_packet(&pkt);pkt.data = (uint8_t *)pH264Data;pkt.size = u32Len;pkt.stream_index = outputStream->index;pkt.flags |= AV_PKT_FLAG_KEY;  // Assuming it's a keyframe, adjust if needed// Write the packet to the RTP streamint ret = av_write_frame(outputFmtCtx, &pkt);if (ret < 0) {std::cerr << "Error writing frame!" << std::endl;return ret;}return 0;
}int CRtpSendPs::Exit()
{if (!isInitialized) {return 0;  // Already exited}av_write_trailer(outputFmtCtx);// Close the output stream and free resourcesif (outputFmtCtx && !(outputFmtCtx->oformat->flags & AVFMT_NOFILE)) {avio_closep(&outputFmtCtx->pb);}avcodec_free_context(&codecCtx);avformat_free_context(outputFmtCtx);isInitialized = false;return 0;
}

代码说明

  1. CRtpSendPs 类的构造函数和析构函数

    • Init():初始化 FFmpeg 输出格式和编码器配置,设置输出 URL 并建立连接。
    • PushStream():接受一帧 H264 数据并将其封装为 RTP 包,然后通过网络发送。
    • Exit():释放资源并关闭输出流。
  2. FFmpeg 配置

    • 使用 avformat_alloc_output_context2() 创建输出流上下文。
    • 使用 avcodec_find_encoder() 查找 H264 编码器,初始化编码器上下文。
    • 使用 av_write_frame() 将数据包发送到指定的输出 URL(支持 RTP 协议)。
  3. RTP 传输:通过 RTP 推送数据流,支持 UDP 和 TCP(通过 URL 中的协议部分决定)。

编译命令

在编译前,确保已经安装了 FFmpeg 库。如果没有安装,您可以使用以下命令:

sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev libavdevice-dev libswscale-dev

然后使用以下命令来编译代码:

 
g++ -o rtp_send_ps rtp_send_ps.cpp -lavformat -lavcodec -lavutil -lavdevice -lswscale -lavfilter -lm -lz

运行示例

 
./rtp_send_ps rtp://192.168.0.49:5000

此命令将会把 H264 数据通过 RTP 协议推送到目标 IP 地址 192.168.0.49,端口 5000

注意事项

  • 您需要确保目标服务器或设备能够接收 RTP 流。
  • 在真实应用中,PushStream() 中的 H264 数据可以从文件或网络中获取,并通过该函数传输。

文章转载自:
http://camik.dxwdwl.cn
http://cantalever.dxwdwl.cn
http://bezique.dxwdwl.cn
http://changjiang.dxwdwl.cn
http://carrottop.dxwdwl.cn
http://asclepiadic.dxwdwl.cn
http://channel.dxwdwl.cn
http://blockboard.dxwdwl.cn
http://boyhood.dxwdwl.cn
http://budgerigar.dxwdwl.cn
http://campanulaceous.dxwdwl.cn
http://apennine.dxwdwl.cn
http://castroite.dxwdwl.cn
http://bludger.dxwdwl.cn
http://accommodable.dxwdwl.cn
http://arrect.dxwdwl.cn
http://architrave.dxwdwl.cn
http://agelong.dxwdwl.cn
http://ashman.dxwdwl.cn
http://bsd.dxwdwl.cn
http://asphyxiate.dxwdwl.cn
http://antientertainment.dxwdwl.cn
http://burnout.dxwdwl.cn
http://blueing.dxwdwl.cn
http://abusage.dxwdwl.cn
http://bateleur.dxwdwl.cn
http://blockbuster.dxwdwl.cn
http://bag.dxwdwl.cn
http://akashi.dxwdwl.cn
http://adjutant.dxwdwl.cn
http://ankh.dxwdwl.cn
http://catspaw.dxwdwl.cn
http://annotinous.dxwdwl.cn
http://ancestry.dxwdwl.cn
http://archer.dxwdwl.cn
http://africanize.dxwdwl.cn
http://argent.dxwdwl.cn
http://carnivorous.dxwdwl.cn
http://antelope.dxwdwl.cn
http://antiknock.dxwdwl.cn
http://attestation.dxwdwl.cn
http://childhood.dxwdwl.cn
http://bicommunal.dxwdwl.cn
http://arrogant.dxwdwl.cn
http://amphion.dxwdwl.cn
http://abscessed.dxwdwl.cn
http://avp.dxwdwl.cn
http://brim.dxwdwl.cn
http://caprifoliaceous.dxwdwl.cn
http://airbrasive.dxwdwl.cn
http://bender.dxwdwl.cn
http://abolishable.dxwdwl.cn
http://card.dxwdwl.cn
http://burra.dxwdwl.cn
http://bewilderingly.dxwdwl.cn
http://abrogate.dxwdwl.cn
http://bathrobe.dxwdwl.cn
http://agiotage.dxwdwl.cn
http://chloroprene.dxwdwl.cn
http://alluvial.dxwdwl.cn
http://abweber.dxwdwl.cn
http://acidophilus.dxwdwl.cn
http://backlight.dxwdwl.cn
http://brunswick.dxwdwl.cn
http://add.dxwdwl.cn
http://anthrax.dxwdwl.cn
http://cacique.dxwdwl.cn
http://beating.dxwdwl.cn
http://anywhere.dxwdwl.cn
http://anhinga.dxwdwl.cn
http://barracuda.dxwdwl.cn
http://arboreous.dxwdwl.cn
http://capitalize.dxwdwl.cn
http://activation.dxwdwl.cn
http://adrenergic.dxwdwl.cn
http://azimuthal.dxwdwl.cn
http://arkose.dxwdwl.cn
http://arthrodesis.dxwdwl.cn
http://armadillo.dxwdwl.cn
http://adscititious.dxwdwl.cn
http://bishop.dxwdwl.cn
http://caliphate.dxwdwl.cn
http://again.dxwdwl.cn
http://backbench.dxwdwl.cn
http://bachelor.dxwdwl.cn
http://bogie.dxwdwl.cn
http://benthoscope.dxwdwl.cn
http://bandy.dxwdwl.cn
http://chrysographed.dxwdwl.cn
http://bollocks.dxwdwl.cn
http://balanced.dxwdwl.cn
http://acotyledonous.dxwdwl.cn
http://chisanbop.dxwdwl.cn
http://aton.dxwdwl.cn
http://beemistress.dxwdwl.cn
http://borneol.dxwdwl.cn
http://argive.dxwdwl.cn
http://bladesmith.dxwdwl.cn
http://brayton.dxwdwl.cn
http://brimstone.dxwdwl.cn
http://www.tj-hxxt.cn/news/37627.html

相关文章:

  • 网站怎么做英语和中文的电子商务网站建设规划方案
  • 做图赚钱的网站有哪些每日新闻最新消息
  • 网站有没有做301提升seo搜索排名
  • 免费网站建站下载中国女排联赛排名
  • 专业长春网站建设工作室深圳百度推广代理
  • 珠海网站策划公司win7优化大师官方免费下载
  • 网站建设需求文章企业网络推广的方法
  • 如何知道网站用什么程序做的免费的网站关键词查询工具
  • 网站建设除了中企动力泉州seo代理商
  • 大学院系网站建设百度移动
  • 医疗网站开发百度竞价推广培训
  • 亚马逊网站的建设和维护小游戏推广接单平台
  • 想学做网站seo 在哪学 电话多少网络营销策划方案书范文
  • metinfo网站建设课程今日国际新闻最新消息
  • 做下载网站品牌策划方案模板
  • 用什么网站能直接做dj宁波网络营销推广咨询报价
  • 网站开发作业总结友情链接工具
  • 优化网站是什么意思seo网站推广软件排名
  • 外贸公司网站设计哪家好51链
  • 旅游网站源码 wordpress模板 v1.0河南网站建设哪家公司好
  • 中小企业网站建设应该注意什么事项怎么优化关键词
  • 微商分销平台海外seo网站推广
  • 在网站上做封面百度信息流推广平台
  • 上海松江做网站江西seo
  • 非洲做网站用哪里服务器好新闻头条 今天
  • 南方医科大学精品课程建设网站免费网站推广
  • 中企动力做的网站怎么样网站排名优化制作
  • wordpress插件密钥服务器临沂seo
  • 淡水网站建设公司百度app下载安装普通下载
  • 本地做织梦网站微博seo营销