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

知道一个网站怎么知道是谁做的百度优化seo网络专员招聘

知道一个网站怎么知道是谁做的百度优化,seo网络专员招聘,利用电脑做网站,合肥网络公司排名一、视频解码流程 使用ffmpeg解码视频帧主要可分为两大步骤:初始化解码器和解码视频帧,以下代码以mjpeg为例 1. 初始化解码器 初始化解码器主要有以下步骤: (1)查找解码器 // 查找MJPEG解码器pCodec avcodec_fin…

一、视频解码流程

使用ffmpeg解码视频帧主要可分为两大步骤:初始化解码器解码视频帧,以下代码以mjpeg为例

1. 初始化解码器

初始化解码器主要有以下步骤:

(1)查找解码器

// 查找MJPEG解码器pCodec = avcodec_find_decoder_by_name(videoCodecName);if (pCodec == nullptr) {release();return false;}// 分配解码器上下文pCodecCtx = avcodec_alloc_context3(pCodec);if (!pCodecCtx) {release();return false;}

(2)设置解码器参数

    pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;pCodecCtx->width = mVideoSrcWidth; // 视频宽度pCodecCtx->height = mVideoSrcHeight; // 视频高度pCodecCtx->pix_fmt = AV_PIX_FMT_YUVJ422P; // 或者其他适合的格式pCodecCtx->time_base = { 1, mVideoSrcFps }; // 帧率pCodecCtx->thread_count = 2;

(3)打开解码器

 // 打开解码器if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0) {release();return false;}

2. 解码视频帧数据

解码视频帧数据主要有以下步骤:

(1)将编码数据送往解码器

AVPacket* packet = av_packet_alloc();if (!packet) {release();return false;}packet->data = data; // 待解码数据地址packet->size = size; // 待解码数据大小// 发送数据到解码器int ret = avcodec_send_packet(pCodecCtx, packet);if (ret < 0) {release();return false;}

(2)接收解码数据

ret = avcodec_receive_frame(pCodecCtx, pFrame);

二、使用ffmpeg实现对内存中的视频帧数据解码

以下代码中InitDecoder为初始化解码器接口,DecodeVideoFrame为解码视频帧接口

需注意

(1)解码的色彩空间pCodecCtx->pix_fmt不可随意指定,调用avcodec_send_packet后可能会变化,这与视频帧的编码方式有关
(2)每次接收完解码数据要调用av_frame_unref进行释放,否则会有内存泄漏问题


extern "C" { // ffmpeg为使用C语言库,因此要声明为C语言的方式链接
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include <libavutil/opt.h>
#include <libavutil/mathematics.h>
#include <libavutil/timestamp.h>
#include <libswresample/swresample.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#include <libavutil/error.h>
}char videoCodecName[] = "mjpeg";
FILE* out_file = nullptr;AVFormatContext* pFormatCtx = nullptr;AVCodecContext* pCodecCtx = nullptr;
const AVCodec* pCodec = nullptr;
AVFrame* pFrame = nullptr;
AVFrame* pFrameYUYV = nullptr;
int yuyv_size = 0;
uint8_t* buffer = nullptr;
SwsContext* sws_ctx = nullptr;int      mVideoSrcWidth = 1920;
int      mVideoSrcHeight = 1080;
int      mVideoSrcFps = 30;bool InitDecoder() {fopen_s(&out_file, "test_yuv.yuv", "wb");// 查找MJPEG解码器pCodec = avcodec_find_decoder_by_name(videoCodecName);if (pCodec == nullptr) {release();return false;}// 分配解码器上下文pCodecCtx = avcodec_alloc_context3(pCodec);if (!pCodecCtx) {release();return false;}pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;pCodecCtx->width = mVideoSrcWidth; // 视频宽度pCodecCtx->height = mVideoSrcHeight; // 视频高度pCodecCtx->pix_fmt = AV_PIX_FMT_YUVJ422P; // 或者其他适合的格式pCodecCtx->time_base = { 1, mVideoSrcFps }; // 帧率pCodecCtx->thread_count = 2;// 打开解码器if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0) {release();return false;}// 分配帧pFrame = av_frame_alloc();pFrameYUYV = av_frame_alloc();if (!pFrame || !pFrameYUYV) {release();return false;}// 分配YUYV帧的缓冲区yuyv_size = av_image_get_buffer_size(AV_PIX_FMT_YUYV422, pCodecCtx->width, pCodecCtx->height, 1);buffer = (uint8_t*)av_malloc(yuyv_size * sizeof(uint8_t));if (!buffer) {release();return false;}av_image_fill_arrays(pFrameYUYV->data, pFrameYUYV->linesize, buffer, AV_PIX_FMT_YUYV422, pCodecCtx->width, pCodecCtx->height, 1);// 创建图像转换上下文sws_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_YUYV422,SWS_BILINEAR, nullptr, nullptr, nullptr);if (!sws_ctx) {release();return false;}
}bool DecodeVideoFrame(uint8_t* data, int size)
{AVPacket* packet = av_packet_alloc();if (!packet) {release();return false;}packet->data = data;packet->size = size;// 发送数据到解码器int ret = avcodec_send_packet(pCodecCtx, packet);if (ret < 0) {release();return false;}// 循环接收解码后的帧while (ret >= 0) {ret = avcodec_receive_frame(pCodecCtx, pFrame);if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {break;}else if (ret < 0) {release();return false;}/******** 将解码后数据进行处理 ********/// 转换为YUYV格式if (sws_scale(sws_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUYV->data, pFrameYUYV->linesize) < 0) {return false;}fwrite(pFrameYUYV->data[0], 1, yuyv_size, out_file);/******** 将解码后数据进行处理 ********/av_frame_unref(pFrame); // 将每次接收的解码帧释放掉,否则会内存泄露}av_packet_unref(packet);av_packet_free(&packet);return true;
}void release()
{if (buffer) {av_free(buffer);buffer = nullptr;}if (pCodecCtx) {avcodec_free_context(&pCodecCtx);pCodecCtx = nullptr;}if (pFormatCtx) {avformat_close_input(&pFormatCtx);pFormatCtx = nullptr;}if (pFrame) {av_frame_free(&pFrame);pFrame = nullptr;}if (pFrameYUYV) {av_frame_free(&pFrameYUYV);pFrameYUYV = nullptr;}if (out_file) {fclose(out_file);}}
http://www.yayakq.cn/news/153736/

相关文章:

  • 建房的网站单品网站模板
  • 这是我自己做的网站吗如何在linux服务器上架设网站
  • 个人网站变现京美建站
  • 网站建设只是typecho与Wordpress同步
  • 上海建筑网站设计十种营销方式
  • 网站邮件设置方法艺术培训网站模板
  • 吉安微信网站简洁物流网站模板免费下载
  • 南京做网站优化网络推广图片大全
  • 广东移动宽带官网站武清网站开发tjniu
  • 健身顾问在哪些网站做推广企业新闻稿发布平台
  • 如何做融资网站wordpress静态化教程
  • 长春能开发网站的公司阳江市商品房备案查询
  • 做网站的盈利点南昌网站建设过程
  • 网站建设关键的问题是淘宝分销平台
  • 设计平台网站中国职业球队
  • 社区问答网站开发做企业网站的合同
  • 如何本地搭建自己的网站湘西州建设银行网站
  • 如何网站数据备份建材类网站模板
  • 毕业设计做健身房网站的意义查询建设用地规划许可证在哪个网站
  • 做流量网站有收入吗国外优惠卷网站如何做
  • 浙江华纳建设有限公司网站网站优化服务
  • 西城网站建设浩森宇特深圳市住房和城乡建设局网站
  • 自建电商网站销售商品做网站的软件
  • 怎样在华为云服务器里建设网站做网站的分页查询
  • 网站界面设计的表现房子
  • 叮当设计网ppt模板免费重庆网站排名优化教程
  • 太原网站建设策划方案黄骅贴吧最新消息金鼎18号
  • 网站开发语言 知乎网页制作方案策划
  • 网站规划与设计大作业商标设计网上接单app
  • 新建网站wordpress软件下载主题