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

做球服的网站有哪些网站设计是做什么的

做球服的网站有哪些,网站设计是做什么的,wordpress 文章完整导出文章及文章中的图片,中国建筑集团是央企吗调用FFmpeg库实现264软件解码 1. FFmpeg的编译2. 调用FFmpeg实现H264软解2.1 基本框架2.2 代码实现2.3 测试结果 3. 分析工具3.1 码流分析3.2 YUV分析 示例工程 【FFmpeg】调用FFmpeg库实现264软编 1. FFmpeg的编译 FFmpeg在Windows下的编译参考:http://t.csdni…

调用FFmpeg库实现264软件解码

  • 1. FFmpeg的编译
  • 2. 调用FFmpeg实现H264软解
    • 2.1 基本框架
    • 2.2 代码实现
    • 2.3 测试结果
  • 3. 分析工具
    • 3.1 码流分析
    • 3.2 YUV分析

====== 示例工程 ======
【FFmpeg】调用FFmpeg库实现264软编

1. FFmpeg的编译

FFmpeg在Windows下的编译参考:http://t.csdnimg.cn/BtAW5
本文使用的FFmpeg版本为7.0

2. 调用FFmpeg实现H264软解

参考FFmpeg当中的/doc/examples当中的video_decode.c文件,进行调用过程的理解和实现。

2.1 基本框架

根据/doc/examples当中的实现进行修改,包括:
1.增加pragma去除fopen的warning
2.增加extern调用ffmpeg库文件
3.增加error code的打印,可以查阅其对应的错误信息
4.修改一些变量的定义
5.文件存储的方式直接修改为yuv,不使用pgm

在解码过程当中,使用了如下的函数

函数名作用
avcodec_find_decoder根据ID查找编码器,输入为AVCodecID,返回为AVCodec,记录了解码器信息
avcodec_alloc_context3创建codec的上下文信息,输入为AVCodec,返回为AVCodecContext,其记录了编码过程上下文的流信息
av_packet_alloc创建数据包packet,并且初始化为默认值,返回为AVPacket;该结构存储压缩之后的数据。通常由解码器导出,然后作为输入传递给解码器,或者作为编码器的输出接收,然后传递给解码器
avcodec_open2打开编码器,输入为AVCodec,返回为ret。该函数初始化了codec线程和配置
av_parser_init创建解析器的上下文,用于解析码流,输入为AVCodecID,返回为AVCodecParserContext
av_frame_alloc创建frame,返回为AVFrame。这个结构描述待编码的原始的音频或视频数据
av_parser_parse2解析码流文件,从输入的一串码流当中解析出一帧数据,存储到AVPacket当中,返回值ret即为一帧数据结束的索引号
avcodec_send_packet将packet送入到解码器当中进行解码,输入为AVCodecContext和AVPacket,输出为ret
avcodec_receive_frame接收解码器已解码信息,输入为AVCodecContext和AVFrame,输出为ret
av_parser_close释放解析器
avcodec_free_context释放解码器的上下文信息
av_frame_free释放frame的缓冲区以及结构体本身
av_packet_freeav_packet_free以及结构体本身

从上面这一系列的函数调用来看,大致操作流程和数据走向大约是
1.解码器的创建和初始化(avcodec_find_decoder)
2.解码器上下文的创建和初始化(avcodec_alloc_context3)
3.创建解码器输入信息,使用AVPacket进行存储(av_packet_alloc)
4.创建解析器,用于解析解码器输入信息(av_parser_init)
5.创建解码器输出信息,使用AVFrame进行存储(av_frame_alloc)
6.打开解码器(avcodec_open2)
7.进入do循环,使用fread读取数据,存储变量名为inbuf
8.对输入的数据进行解析,因为解码器是一帧一帧解码的,所以需要将数据存储到AVPacket当中。同时必须知道码流中每一帧结束的索引,用以确定下一帧的起始位置(av_parser_parse2)
9.将当前帧信息送入到解码器当中去解码,输入载体是AVPacket(avcodec_send_packet)
10.将已经解码的数据取出,输出载体是AVFrame(avcodec_receive_frame)
11.将已解码的数据存储为yuv格式【可选操作】
12.解析下一帧数据
13.当所有帧解码完毕之后,释放解析器、上下文信息、AVFrame以及AVPacket等结构体

这里使用了avcodec_send_packet和avcodec_receive_frame两个函数,这里的send和receive可以假想为使用线上网络传输软件进行数据流的传输,send将码流文件送出,receive将已经解码的yuv文件接收。

2.2 代码实现

#pragma warning(disable : 4996)#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "video_decode.h"#ifdef _WIN32
//Windows
extern "C" // 在C++文件中调用C文件需要使用,ffmpeg是使用C实现的
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libavutil/opt.h"
};
#else
//Linux...
#ifdef __cplusplus
extern "C"
{
#endif
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libavutil/opt.h"
#ifdef __cplusplus
};
#endif
#endif#define IMG_WIDTH 1920
#define IMG_HEIGHT 1200
#define INBUF_SIZE IMG_WIDTH * IMG_HEIGHTstatic void pgm_save(unsigned char* buf, int wrap, int xsize, int ysize, const char* filename)
{FILE* f;f = fopen(filename, "wb");fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255);for (int i = 0; i < ysize; i++) {fwrite(buf + i * wrap, 1, xsize, f);}fclose(f);
}void decode_internal(AVCodecContext* av_codec_ctx, AVFrame* av_frm, AVPacket* av_pkt, FILE* fp_out)
{static char buf[1024];int ret;// 将当前帧送入到解码器当中去解码ret = avcodec_send_packet(av_codec_ctx, av_pkt);if (ret < 0) {fprintf(stderr, "Error sending a packet for decoding, error code:%d\n", ret);exit(1);}while (ret >= 0) {// 获取已经解码的数据ret = avcodec_receive_frame(av_codec_ctx, av_frm);if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {return;}else if (ret < 0) {fprintf(stderr, "Error during decoding, error code:%d\n", ret);exit(1);}fprintf(stderr, "saving frame %3" PRId64"\n", av_codec_ctx->frame_num);fflush(stdout);//snprintf(buf, sizeof(buf), "%s-%s" PRId64, out_filename, av_codec_ctx->frame_num);//pgm_save(av_frm->data[0], av_frm->linesize[0], av_frm->width, av_frm->height, out_filename);// 将已经解码的数据存储到文件中int size = av_frm->width * av_frm->height;fwrite(av_frm->data[0], 1, size, fp_out);//Yfwrite(av_frm->data[1], 1, size / 4, fp_out);//Ufwrite(av_frm->data[2], 1, size / 4, fp_out);//V}
}int decode(const char* in_file, const char* out_file)
{const AVCodec* av_codec;AVCodecParserContext* av_parser;AVCodecContext* av_codec_ctx = NULL;AVFrame* av_frame;uint8_t* data;size_t data_size;int ret;int eof;AVPacket* av_pkt;// malloc input bufferuint8_t* inbuf = (uint8_t*)malloc((INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) * sizeof(uint8_t));if (!inbuf) {fprintf(stderr, "Error! alloc inbuf failed");exit(1);}memset(inbuf + INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);// create h264 decoderav_codec = avcodec_find_decoder(AV_CODEC_ID_H264);if (!av_codec) {fprintf(stderr, "Codec not found\n");exit(1);}// create ctxav_codec_ctx = avcodec_alloc_context3(av_codec);if (!av_codec_ctx) {fprintf(stderr, "Could not allocate video codec context\n");exit(1);}// creat pktav_pkt = av_packet_alloc();if (!av_pkt) {fprintf(stderr, "Error! alloc pkt failed");exit(1);}// parse codec infoav_parser = av_parser_init(av_codec->id);if (!av_parser) {fprintf(stderr, "parser not found\n");exit(1);}// create frameav_frame = av_frame_alloc();if (!av_frame) {fprintf(stderr, "Could not allocate video frame\n");exit(1);}// open fileFILE* fp_in = fopen(in_file, "rb");if (!fp_in) {fprintf(stderr, "Could not open %s\n", in_file);exit(1);}FILE* fp_out = fopen(out_file, "wb");if (!fp_out) {fprintf(stderr, "Could not open %s\n", out_file);exit(1);}// open dec codecif (avcodec_open2(av_codec_ctx, av_codec, NULL) < 0) {fprintf(stderr, "Could not open codec\n");exit(1);}do {/* read raw data from the input file */data_size = fread(inbuf, 1, INBUF_SIZE, fp_in);if (ferror(fp_in)) {break;}eof = !data_size;/* use the parser to split the data into frames */data = inbuf;while (data_size > 0 || eof) {// 从输入码流当中解析出一帧数据,送入到解码器当中解码// 如果是第1帧(IDR)的话,ret表示的索引还包括头信息(SPS+PPS+SEI)ret = av_parser_parse2(av_parser, av_codec_ctx, &av_pkt->data, &av_pkt->size,data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);if (ret < 0) {fprintf(stderr, "Error! can not parse iput data");exit(1);}// 更新后面帧的起始地址data += ret;data_size -= ret;if (av_pkt->size) {// decodedecode_internal(av_codec_ctx, av_frame, av_pkt, fp_out);}else if (eof) {break;}}} while (!eof);/* flush the decoder */decode_internal(av_codec_ctx, av_frame, NULL, fp_out);fclose(fp_in);free(inbuf);av_parser_close(av_parser);avcodec_free_context(&av_codec_ctx);av_frame_free(&av_frame);av_packet_free(&av_pkt);return 0;
}

2.3 测试结果

saving frame   1
saving frame   2
saving frame   3
saving frame   4
saving frame   5
saving frame   6
saving frame   7
saving frame   8
saving frame   9
saving frame  10

3. 分析工具

3.1 码流分析

264/265码流分析工具(有release文件):https://gitcode.com/latelee/H264BSAnalyzer

3.2 YUV分析

YUV分析工具:https://gitcode.com/IENT/YUView/overview

Github: https://github.com/DoFulangChen/video_implementation.git

http://www.hrbkazy.com/news/24660.html

相关文章:

  • 驾校网站建设方案厦门seo优化多少钱
  • 挂机宝 可以做网站站长之家seo工具
  • 学做效果图的网站全网媒体发布平台
  • 百度做网站怎么样怎么制作网页广告
  • 电子商务网站流程设计seo怎么刷关键词排名
  • 提供企业网站建设定制数字营销策略有哪些
  • 多语种网站建设开发域名注册平台哪个好
  • 建网站卖虚拟资源需要怎么做代做百度首页排名
  • 门户网站的特点和优势东莞seo技术
  • 网站设计策划书模板seo职业
  • 高价做单网站网页制作与设计
  • 学校网站做几级等保推广之家
  • 索菲亚全屋定制官方网站游戏推广员好做吗
  • 进博会上海2022手机优化大师官方版
  • 外国一些做环保袋的网站百度seo是什么意思呢
  • 公司网站平台建设网站推广seo招聘
  • b2c网站建设 杭州百色seo快速排名
  • 厦门网站开发网站设计公司排行
  • 做同城购物网站网站建设公司简介
  • 免费自制qq主题appseo网站优化排名
  • 网站开发源代码修改百度招聘电话
  • 顶做抱枕网站长沙网络公关公司
  • 自适应h5网页模板seo优化信
  • 机械英语网站如何做网站
  • 专业网站建设哪里好山东网站seo
  • 京东优惠券网站怎么做乔拓云智能建站
  • 什么网站做的好看的平面设计正规培训机构
  • 网站优化套餐企业关键词优化专业公司
  • 宁波h5网站建设网站建设需要多少钱
  • 可以推广的网站有哪些网络营销的八大职能