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

大型网站开发框架网络建站优化科技

大型网站开发框架,网络建站优化科技,网站收录了怎么做排名,优秀品牌企业网站建设案例要对H265文件进行编码和解码&#xff0c;需要使用FFmpeg库提供的相关API。以下是一个简单的C程序&#xff0c;演示如何使用FFmpeg进行H265文件的编码和解码&#xff1a; 编码&#xff1a; #include <cstdlib> #include <cstdio> #include <cstring> #inclu…

要对H265文件进行编码和解码,需要使用FFmpeg库提供的相关API。以下是一个简单的C++程序,演示如何使用FFmpeg进行H265文件的编码和解码:

编码:

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>extern "C" {
#include <libavutil/opt.h>
#include <libavcodec/avcodec.h>
}int main(int argc, char** argv) {AVCodec* codec = nullptr;AVCodecContext* codec_ctx = nullptr;AVFrame* frame = nullptr;AVPacket packet;FILE* infile, * outfile;avcodec_register_all();codec = avcodec_find_encoder_by_name("libx265");codec_ctx = avcodec_alloc_context3(codec);codec_ctx->bit_rate = 4000000;codec_ctx->width = 1280;codec_ctx->height = 720;codec_ctx->gop_size = 10;codec_ctx->max_b_frames = 1;codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;av_opt_set(codec_ctx->priv_data, "preset", "fast", 0);if (avcodec_open2(codec_ctx, codec, nullptr) < 0) {fprintf(stderr, "Could not open codec\n");return EXIT_FAILURE;}infile = std::fopen("input.yuv", "rb");if (!infile) {fprintf(stderr, "Could not open input file\n");return EXIT_FAILURE;}outfile = std::fopen("output.h265", "wb");if (!outfile) {fprintf(stderr, "Could not open output file\n");return EXIT_FAILURE;}frame = av_frame_alloc();frame->width = codec_ctx->width;frame->height = codec_ctx->height;frame->format = codec_ctx->pix_fmt;if (av_frame_get_buffer(frame, 32) < 0) {fprintf(stderr, "Could not allocate frame buffer\n");return EXIT_FAILURE;}int frame_size = av_image_get_buffer_size(codec_ctx->pix_fmt, codec_ctx->width, codec_ctx->height, 1);uint8_t* frame_buf = (uint8_t*)av_malloc(frame_size);while (true) {int ret = fread(frame_buf, 1, frame_size, infile);if (ret < frame_size) {break;}av_frame_make_writable(frame);uint8_t* pY = frame_buf;uint8_t* pU = frame_buf + frame_size / 4;uint8_t* pV = frame_buf + frame_size * 5 / 16;for (int y = 0; y < codec_ctx->height; y++) {memcpy(frame->data[0] + y * frame->linesize[0], pY + y * codec_ctx->width, codec_ctx->width);}for (int y = 0; y < codec_ctx->height / 2; y++) {memcpy(frame->data[1] + y * frame->linesize[1], pU + y * codec_ctx->width / 2, codec_ctx->width / 2);memcpy(frame->data[2] + y * frame->linesize[2], pV + y * codec_ctx->width / 2, codec_ctx->width / 2);}avcodec_send_frame(codec_ctx, frame);while (true) {ret = avcodec_receive_packet(codec_ctx, &packet);if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {break;} else if (ret < 0) {fprintf(stderr, "Error encoding frame\n");return EXIT_FAILURE;}fwrite(packet.data, 1, packet.size, outfile);av_packet_unref(&packet);}}avcodec_send_frame(codec_ctx, nullptr);while (true) {int ret = avcodec_receive_packet(codec_ctx, &packet);if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {break;} else if (ret < 0) {fprintf(stderr, "Error encoding frame\n");return EXIT_FAILURE;}fwrite(packet.data, 1, packet.size, outfile);av_packet_unref(&packet);}std::fclose(infile);std::fclose(outfile);av_frame_free(&frame);av_free(frame_buf);avcodec_free_context(&codec_ctx);return EXIT_SUCCESS;
}

解码:

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/frame.h>
#include <libavutil/imgutils.h>
}int main(int argc, char** argv) {AVCodec* codec = nullptr;AVCodecContext* codec_ctx = nullptr;AVFrame* frame = nullptr;AVPacket packet;FILE* infile, * outfile;avcodec_register_all();codec = avcodec_find_decoder_by_name("libx265");codec_ctx = avcodec_alloc_context3(codec);if (avcodec_open2(codec_ctx, codec, nullptr) < 0) {fprintf(stderr, "Could not open codec\n");return EXIT_FAILURE;}infile = std::fopen("input.h265", "rb");if (!infile) {fprintf(stderr, "Could not open input file\n");return EXIT_FAILURE;}outfile = std::fopen("output.yuv", "wb");if (!outfile) {fprintf(stderr, "Could not open output file\n");return EXIT_FAILURE;}frame = av_frame_alloc();while (true) {int ret = av_read_frame(format_ctx, &packet);if (ret < 0) {break;}if (packet.stream_index != video_stream_idx) {av_packet_unref(&packet);continue;}avcodec_send_packet(codec_ctx, &packet);while (true) {ret = avcodec_receive_frame(codec_ctx, frame);if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {break;} else if (ret < 0) {fprintf(stderr, "Error decoding frame\n");return EXIT_FAILURE;}uint8_t* pY = frame->data[0];uint8_t* pU = frame->data[1];uint8_t* pV = frame->data[2];for (int y = 0; y < codec_ctx->height; y++) {fwrite(pY + y * frame->linesize[0], 1, codec_ctx->width, outfile);}for (int y = 0; y < codec_ctx->height / 2; y++) {fwrite(pU + y * frame->linesize[1], 1, codec_ctx->width / 2, outfile);fwrite(pV + y * frame->linesize[2], 1, codec_ctx->width / 2, outfile);}av_frame_unref(frame);}av_packet_unref(&packet);}std::fclose(infile);std::fclose(outfile);av_frame_free(&frame);avcodec_free_context(&codec_ctx);return EXIT_SUCCESS;
}

需要注意的是,以上程序中的一些常量参数可能需要根据实际情况进行调整。

http://www.dt0577.cn/news/20097.html

相关文章:

  • 改图在线处理图片济南seo外包公司
  • 便宜的做网站淘宝搜索热词排名
  • 怎么看网站开发的好坏10条重大新闻事件
  • 邵阳网站建设哪家好网络推广100种方式
  • 网站开发定制合同范本企业推广方式
  • 带做网站绿标网络推广专家
  • 代做毕设网站可信么北京百度竞价托管公司
  • 网站上的产品五星怎样做优化今天最新新闻
  • 网络工作室网站青岛网站建设与设计制作
  • 武汉成交型网站建设百度快照怎么使用
  • 成都企业网站建设方案北京网站推广机构
  • 网站建设要到公安seo基本概念
  • 2021半夜好用的网站百度推广开户费用标准
  • 外国做的中国动画视频网站爱站长工具
  • 网站运营做的是什么工作网络营销常用工具
  • 网站cms系统 开源框架培训机构管理系统
  • wordpress皮肤下载站域名备案查询站长工具
  • 网站获取访客qq 原理软文网
  • 男生女生做污事网站 localhost搜索引擎优化方案
  • 青岛建站通百度竞价品牌广告
  • 购物网站最近浏览怎么做外链购买交易平台
  • 广告公司年终总结win10优化
  • 创业做婚恋交友网站廊坊百度推广seo
  • 海外服务器ip免费陕西seo关键词优化外包
  • 重庆模板建站软件百度网站怎么优化排名靠前
  • wordpress文章字体修改为宋体企业网站优化哪家好
  • 网站软件有哪些代理推广
  • 网站主页制作教程班级优化大师手机版下载
  • 做pc端软件可以参考那些网站经典软文案例分析
  • 上海网站制作与推广4a广告公司