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

如何用php做电商网站衡阳网站优化公司

如何用php做电商网站,衡阳网站优化公司,江苏镇江论坛,日本文创产品设计文章目录 流程音频视频 api核心代码audioencoder.haudioencoder.cppvideoencoder.hvideoencoder.cpp pcm和yuv编码为aac和h264,封装为c的AudioEncoder类和VideoEncoder类 流程 音频 初始化音频参数 int InitAAC(int channels, int sample_rate, int bit_rate); 音…

文章目录

      • 流程
        • 音频
        • 视频
      • api
      • 核心代码
        • audioencoder.h
        • audioencoder.cpp
        • videoencoder.h
        • videoencoder.cpp

pcm和yuv编码为aac和h264,封装为c++的AudioEncoder类和VideoEncoder类

流程

音频
  • 初始化音频参数
    int InitAAC(int channels, int sample_rate, int bit_rate);

  • 音频编码,pts需要转化为编码时的pts, 发送帧frame, 获取 packet
    AVPacket *Encode(AVFrame *farme, int stream_index, int64_t pts, int64_t time_base);

  • 获取一帧数据通道号的采样点
    int GetFrameSize()

  • 获取编码器需要的采样格式
    int GetSampleFormat()

  • 释放资源
    void DeInit();

视频
  • 初始化视频参数
    int InitH264(int width, int height, int fps, int bit_rate);

  • 视频编码,pts需要转化为编码时的pts, 需要初始化AVFrame结构体,发送帧frame, 获取 packet
    AVPacket *Encode(AVFrame *farme, int stream_index, int64_t pts, int64_t time_base);

  • 释放资源
    void DeInit();

api

  • 用于初始化一个AVFrame结构体,包括设置AVFrame中的各项参数,不需要重新分配buffer,需要传入一个指向AVFrame结构体的指针
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],const uint8_t *src,enum AVPixelFormat pix_fmt, int width, int height, int align);

核心代码

audioencoder.h
#ifndef AUDIOENCODER_H
#define AUDIOENCODER_Hextern "C"
{
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
}
class AudioEncoder
{
public:AudioEncoder();~AudioEncoder();int InitAAC(int channels, int sample_rate, int bit_rate);
//    int InitMP3(/*int channels, int sample_rate, int bit_rate*/);void DeInit();  // 释放资源AVPacket *Encode(AVFrame *farme, int stream_index, int64_t pts, int64_t time_base);int GetFrameSize(); // 获取一帧数据 每个通道需要多少个采样点int GetSampleFormat();  // 编码器需要的采样格式
private:int channels_ = 2;int sample_rate_ = 44100;int bit_rate_ = 128*1024;int64_t pts_ = 0;AVCodecContext * codec_ctx_ = NULL;
};#endif // AUDIOENCODER_H
audioencoder.cpp
#include "audioencoder.h"AudioEncoder::AudioEncoder()
{}AudioEncoder::~AudioEncoder()
{if(codec_ctx_) {DeInit();}
}int AudioEncoder::InitAAC(int channels, int sample_rate, int bit_rate)
{channels_ = channels;sample_rate_ = sample_rate;bit_rate_ = bit_rate;AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_AAC);if(!codec) {printf("avcodec_find_encoder AV_CODEC_ID_AAC failed\n");return -1;}codec_ctx_ = avcodec_alloc_context3(codec);if(!codec_ctx_) {printf("avcodec_alloc_context3 AV_CODEC_ID_AAC failed\n");return -1;}codec_ctx_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;codec_ctx_->bit_rate = bit_rate_;codec_ctx_->sample_rate = sample_rate_;codec_ctx_->sample_fmt = AV_SAMPLE_FMT_FLTP;codec_ctx_->channels = channels_;codec_ctx_->channel_layout = av_get_default_channel_layout(codec_ctx_->channels);int ret = avcodec_open2(codec_ctx_, NULL, NULL);if(ret != 0) {char errbuf[1024] = {0};av_strerror(ret, errbuf, sizeof(errbuf) - 1);printf("avcodec_open2 failed:%s\n", errbuf);return -1;}printf("InitAAC success\n");return 0;
}void AudioEncoder::DeInit()
{if(codec_ctx_) {avcodec_free_context(&codec_ctx_);  // codec_ctx_被设置为NULL
//        codec_ctx_ = NULL;  // 不需要再写}
}AVPacket *AudioEncoder::Encode(AVFrame *frame, int stream_index, int64_t pts, int64_t time_base)
{if(!codec_ctx_) {printf("codec_ctx_ null\n");return NULL;}pts = av_rescale_q(pts, AVRational{1, (int)time_base}, codec_ctx_->time_base);if(frame) {frame->pts = pts;}int ret = avcodec_send_frame(codec_ctx_, frame);if(ret != 0) {char errbuf[1024] = {0};av_strerror(ret, errbuf, sizeof(errbuf) - 1);printf("avcodec_send_frame failed:%s\n", errbuf);return NULL;}AVPacket *packet = av_packet_alloc();ret = avcodec_receive_packet(codec_ctx_, packet);if(ret != 0) {char errbuf[1024] = {0};av_strerror(ret, errbuf, sizeof(errbuf) - 1);printf("avcodec_receive_packet failed:%s\n", errbuf);av_packet_free(&packet);return NULL;}packet->stream_index = stream_index;return packet;
}int AudioEncoder::GetFrameSize()
{if(codec_ctx_)return codec_ctx_->frame_size;return 0;
}int AudioEncoder::GetSampleFormat()
{if(codec_ctx_)return codec_ctx_->sample_fmt;return -1;  // AV_SAMPLE_FMT_NONE
}
videoencoder.h
#ifndef VIDEOENCODER_H
#define VIDEOENCODER_H
extern "C"
{
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
}class VideoEncoder
{
public:VideoEncoder();~VideoEncoder();int InitH264(int width, int height, int fps, int bit_rate);void DeInit();AVPacket *Encode(uint8_t *yuv_data, int yuv_size,int stream_index, int64_t pts, int64_t time_base);private:int width_ = 0;int height_ = 0;int fps_ = 25;int bit_rate_ = 500*1024;int64_t pts_ = 0;AVCodecContext * codec_ctx_ = NULL;AVFrame *frame_ = NULL;
};#endif // VIDEOENCODER_H
videoencoder.cpp
#include "videoencoder.h"
extern "C"
{
#include "libavutil/imgutils.h"
}
VideoEncoder::VideoEncoder()
{}VideoEncoder::~VideoEncoder()
{if(codec_ctx_) {DeInit();}
}int VideoEncoder::InitH264(int width, int height, int fps, int bit_rate)
{width_ = width;height_ = height;fps_ = fps;bit_rate_ = bit_rate;AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_H264);if(!codec) {printf("avcodec_find_encoder AV_CODEC_ID_H264 failed\n");return -1;}codec_ctx_ = avcodec_alloc_context3(codec);if(!codec_ctx_) {printf("avcodec_alloc_context3 AV_CODEC_ID_H264 failed\n");return -1;}codec_ctx_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;codec_ctx_->bit_rate = bit_rate_;codec_ctx_->width = width_;codec_ctx_->height = height_;codec_ctx_->framerate = {fps_, 1};codec_ctx_->time_base = {1, 1000000};   // 单位为微妙codec_ctx_->gop_size = fps_;codec_ctx_->max_b_frames = 0;codec_ctx_->pix_fmt = AV_PIX_FMT_YUV420P;int ret = avcodec_open2(codec_ctx_, NULL, NULL);if(ret != 0) {char errbuf[1024] = {0};av_strerror(ret, errbuf, sizeof(errbuf) - 1);printf("avcodec_open2 failed:%s\n", errbuf);return -1;}frame_ = av_frame_alloc();if(!frame_) {printf("av_frame_alloc failed\n");return -1;}frame_->width = width_;frame_->height = height_;frame_->format = codec_ctx_->pix_fmt;printf("Inith264 success\n");return 0;
}void VideoEncoder::DeInit()
{if(codec_ctx_) {avcodec_free_context(&codec_ctx_);}if(frame_) {av_frame_free(&frame_);}
}AVPacket *VideoEncoder::Encode(uint8_t *yuv_data, int yuv_size, int stream_index, int64_t pts, int64_t time_base)
{if(!codec_ctx_) {printf("codec_ctx_ null\n");return NULL;}int ret = 0;pts = av_rescale_q(pts, AVRational{1, (int)time_base}, codec_ctx_->time_base);frame_->pts = pts;if(yuv_data) {//该函数用于初始化一个AVFrame结构体,包括设置AVFrame中的各项参数,不需要重新分配buffer//使用该函数需要传入一个指向AVFrame结构体的指针int ret_size = av_image_fill_arrays(frame_->data, frame_->linesize,yuv_data, (AVPixelFormat)frame_->format,frame_->width, frame_->height, 1);if(ret_size != yuv_size) {printf("ret_size:%d != yuv_size:%d -> failed\n", ret_size, yuv_size);return NULL;}ret = avcodec_send_frame(codec_ctx_, frame_);} else {ret = avcodec_send_frame(codec_ctx_, NULL);}if(ret != 0) {char errbuf[1024] = {0};av_strerror(ret, errbuf, sizeof(errbuf) - 1);printf("avcodec_send_frame failed:%s\n", errbuf);return NULL;}AVPacket *packet = av_packet_alloc();ret = avcodec_receive_packet(codec_ctx_, packet);if(ret != 0) {char errbuf[1024] = {0};av_strerror(ret, errbuf, sizeof(errbuf) - 1);printf("avcodec_receive_packet failed:%s\n", errbuf);av_packet_free(&packet);return NULL;}packet->stream_index = stream_index;return packet;
}

文章转载自:
http://jurimetrics.pwrb.cn
http://gybe.pwrb.cn
http://unschooled.pwrb.cn
http://imamate.pwrb.cn
http://euro.pwrb.cn
http://inadequate.pwrb.cn
http://proof.pwrb.cn
http://cuckoopint.pwrb.cn
http://unadmitted.pwrb.cn
http://accidentalism.pwrb.cn
http://entireness.pwrb.cn
http://paradisaic.pwrb.cn
http://kharakteristika.pwrb.cn
http://landlocked.pwrb.cn
http://maleate.pwrb.cn
http://overgreat.pwrb.cn
http://irregardless.pwrb.cn
http://ethnohistoric.pwrb.cn
http://wimple.pwrb.cn
http://outwore.pwrb.cn
http://sequestrum.pwrb.cn
http://spiffy.pwrb.cn
http://newham.pwrb.cn
http://homotaxis.pwrb.cn
http://noninterference.pwrb.cn
http://demodulation.pwrb.cn
http://trial.pwrb.cn
http://met.pwrb.cn
http://godhead.pwrb.cn
http://karsey.pwrb.cn
http://biggity.pwrb.cn
http://belgrade.pwrb.cn
http://chondrosarcoma.pwrb.cn
http://omnipotent.pwrb.cn
http://chi.pwrb.cn
http://accessory.pwrb.cn
http://unweave.pwrb.cn
http://photometer.pwrb.cn
http://agro.pwrb.cn
http://legiron.pwrb.cn
http://phospholipase.pwrb.cn
http://jarvey.pwrb.cn
http://rapturously.pwrb.cn
http://metazoic.pwrb.cn
http://ideamonger.pwrb.cn
http://atilt.pwrb.cn
http://inappeasable.pwrb.cn
http://encapsulant.pwrb.cn
http://stunning.pwrb.cn
http://henroost.pwrb.cn
http://buttress.pwrb.cn
http://everblooming.pwrb.cn
http://smuttily.pwrb.cn
http://gastriloquy.pwrb.cn
http://sophi.pwrb.cn
http://norway.pwrb.cn
http://scammony.pwrb.cn
http://crone.pwrb.cn
http://thermogeography.pwrb.cn
http://organon.pwrb.cn
http://hyperchromic.pwrb.cn
http://ensorcellment.pwrb.cn
http://purchasable.pwrb.cn
http://module.pwrb.cn
http://formally.pwrb.cn
http://leathercraft.pwrb.cn
http://poltroonery.pwrb.cn
http://otp.pwrb.cn
http://regensburg.pwrb.cn
http://thermophysical.pwrb.cn
http://vitaminology.pwrb.cn
http://charry.pwrb.cn
http://ayudhya.pwrb.cn
http://tupelo.pwrb.cn
http://microcephaly.pwrb.cn
http://medievalize.pwrb.cn
http://sustentation.pwrb.cn
http://cordelle.pwrb.cn
http://hetairism.pwrb.cn
http://buhl.pwrb.cn
http://petechia.pwrb.cn
http://unmusical.pwrb.cn
http://preinvasion.pwrb.cn
http://nunchaku.pwrb.cn
http://bowls.pwrb.cn
http://fagmaster.pwrb.cn
http://knackwurst.pwrb.cn
http://swordplay.pwrb.cn
http://labourer.pwrb.cn
http://heterophyllous.pwrb.cn
http://haleness.pwrb.cn
http://owlish.pwrb.cn
http://pons.pwrb.cn
http://piolet.pwrb.cn
http://prevalence.pwrb.cn
http://mitsvah.pwrb.cn
http://lusty.pwrb.cn
http://stillness.pwrb.cn
http://fireplace.pwrb.cn
http://massy.pwrb.cn
http://www.dt0577.cn/news/102645.html

相关文章:

  • ps制作网站优化网站排名茂名厂商
  • 公司网站建设框架网站推广的常用途径有哪些
  • 专门做游戏交易的网站中央突然宣布一个大消息
  • 龙岗做网站公司哪家好软文生成器
  • wordpress获取文章类别目录seo优化专员招聘
  • 嘉兴网站建设网店推广的渠道有哪些
  • 网络广告的类型合肥网站优化排名推广
  • 专业的微网站公司东莞网站推广公司黄页
  • java网站开发现状宁波seo公司推荐
  • 北京网站建设及app盘多多百度网盘搜索引擎
  • 旅游网官方网站软件培训班学费多少
  • 正规网站建设模板免费自学电商教程
  • 众筹网站建设 网站定制开发想做网站找什么公司
  • 深圳网站建设公司的英文名是重庆网站排名公司
  • 遵义市网站建设公司深圳网站设计三把火
  • 哈尔滨个人优化排名伟哥seo博客
  • 美女做爰视频免费安全的网站seo排名系统
  • 石家庄疫情全面开放山东东营网络seo
  • 织梦dede建站教程视频公司快速建站
  • 织梦网站文章发布信息模板下载汕头网站建设开发
  • wordpress 如何备份数据库郑州seo询搜点网络效果佳
  • 大学网站建设专业模板网站哪个好
  • 济南网络营销外包排名优化软件
  • 深圳建网站兴田德润可信风云榜小说排行榜
  • b2c商城网站有哪些淘宝联盟怎么推广
  • 盐城网站推广怎么网站推广
  • 成都seo工程师兰州网络推广关键词优化
  • 阿里云网站建设考试题目南昌seo外包公司
  • 影视网站视频接口怎么做怎样做网站推广
  • 网站建设 廊坊渠道网络