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

`北京网站建设国内精自线一二区网页版

`北京网站建设,国内精自线一二区网页版,做个视频网站,深圳龙岗做网站公司哪家好我们在FFmpeg简单总结对FFmpeg 组成模块,编码进行了简单介绍。 FFmpeg组成部分: libavcodec: 提供了音视频编解码器的库。 libavformat: 处理多媒体容器格式的库,包括封装和解封装。 libavutil: 包含一些公…

我们在FFmpeg简单总结对FFmpeg 组成模块,编码进行了简单介绍。

FFmpeg组成部分:
libavcodec: 提供了音视频编解码器的库。
libavformat: 处理多媒体容器格式的库,包括封装和解封装。
libavutil: 包含一些公共的实用工具函数。
libswscale: 提供图像缩放和颜色转换功能的库。
libavfilter: 实现音视频过滤器的库,用于进行各种音视频处理操作。
ffmpeg: 命令行工具,用于进行音视频处理和转码。
ffprobe: 用于检测多媒体文件信息的命令行工具。
ffplay: 简单的播放器,支持音视频播放。

libswscale

libswscale(Software Scaling and Conversion Library)是FFmpeg中的一个库,用于执行图像缩放、颜色空间转换以及图像格式转换等操作。它主要提供了一些函数和工具,使得在视频处理过程中可以方便地进行图像大小和颜色空间的调整。

常用的API介绍

sws_getContext: 创建并返回一个SwsContext对象,用于设置缩放和颜色空间转换的参数。

struct SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat,int dstW, int dstH, enum AVPixelFormat dstFormat,int flags, SwsFilter *srcFilter,SwsFilter *dstFilter, const double *param);

sws_scale: 将输入图像进行缩放和颜色空间转换,并将结果输出到目标图像。

int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],const int srcStride[], int srcSliceY, int srcSliceH,uint8_t *const dst[], const int dstStride[]);

sws_freeContext: 释放SwsContext对象占用的资源。

void sws_freeContext(struct SwsContext *swsContext);

灰度化

下面给出一个例子,使用FFmpeg对图像进行处理,该程序解码视频流,选取视频流中的输入图片,进行灰度化处理,然后保存为新的图片

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>void process_image(const char *input_filename, const char *output_filename) {AVFormatContext *input_format_context = NULL;AVCodecContext *codec_context = NULL;AVCodec *codec = NULL;AVFrame *frame = NULL;AVFrame *gray_frame = NULL;AVPacket packet;struct SwsContext *sws_context = NULL;// Register FFmpeg componentsav_register_all();// Open input fileif (avformat_open_input(&input_format_context, input_filename, NULL, NULL) != 0) {fprintf(stderr, "Error opening input file\n");exit(EXIT_FAILURE);}// Retrieve stream informationif (avformat_find_stream_info(input_format_context, NULL) < 0) {fprintf(stderr, "Error finding stream information\n");exit(EXIT_FAILURE);}// Find the first video streamint video_stream_index = -1;for (int i = 0; i < input_format_context->nb_streams; i++) {if (input_format_context->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {video_stream_index = i;break;}}if (video_stream_index == -1) {fprintf(stderr, "Error: No video stream found\n");exit(EXIT_FAILURE);}// Find the decoder for the video streamcodec = avcodec_find_decoder(input_format_context->streams[video_stream_index]->codecpar->codec_id);if (!codec) {fprintf(stderr, "Error: No decoder found\n");exit(EXIT_FAILURE);}// Allocate a codec context for the decodercodec_context = avcodec_alloc_context3(codec);if (!codec_context) {fprintf(stderr, "Error allocating codec context\n");exit(EXIT_FAILURE);}// Copy codec parameters from input stream to codec contextif (avcodec_parameters_to_context(codec_context, input_format_context->streams[video_stream_index]->codecpar) < 0) {fprintf(stderr, "Error setting codec parameters\n");exit(EXIT_FAILURE);}// Open codecif (avcodec_open2(codec_context, codec, NULL) < 0) {fprintf(stderr, "Error opening codec\n");exit(EXIT_FAILURE);}// Allocate video framesframe = av_frame_alloc();gray_frame = av_frame_alloc();if (!frame || !gray_frame) {fprintf(stderr, "Error allocating frames\n");exit(EXIT_FAILURE);}// Determine required buffer size and allocate bufferint num_bytes = av_image_get_buffer_size(AV_PIX_FMT_GRAY8, codec_context->width, codec_context->height, 1);uint8_t *buffer = (uint8_t *)av_malloc(num_bytes * sizeof(uint8_t));// Assign appropriate parts of buffer to image planes in gray_frameav_image_fill_arrays(gray_frame->data, gray_frame->linesize, buffer, AV_PIX_FMT_GRAY8, codec_context->width, codec_context->height, 1);// Initialize SwsContext for converting between color spacessws_context = sws_getContext(codec_context->width, codec_context->height, codec_context->pix_fmt,codec_context->width, codec_context->height, AV_PIX_FMT_GRAY8,SWS_BILINEAR, NULL, NULL, NULL);// Open output fileFILE *output_file = fopen(output_filename, "wb");if (!output_file) {fprintf(stderr, "Error opening output file\n");exit(EXIT_FAILURE);}// Read frames from the input file, convert to grayscale, and write to the output filewhile (av_read_frame(input_format_context, &packet) == 0) {if (packet.stream_index == video_stream_index) {// Decode video frameif (avcodec_receive_frame(codec_context, frame) == 0) {// Convert frame to grayscalesws_scale(sws_context, frame->data, frame->linesize, 0, frame->height, gray_frame->data, gray_frame->linesize);// Write grayscale frame to output filefwrite(gray_frame->data[0], 1, num_bytes, output_file);}}av_packet_unref(&packet);}// Cleanupfclose(output_file);av_frame_free(&frame);av_frame_free(&gray_frame);av_free(buffer);sws_freeContext(sws_context);avcodec_close(codec_context);avformat_close_input(&input_format_context);
}int main() {const char *input_filename = "input.jpg";const char *output_filename = "output.gray";process_image(input_filename, output_filename);return 0;
}

放大缩小

也可以直接用接口函数,对image操作


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libswscale/swscale.h>int main() {// Input image parametersint src_width = 1920;int src_height = 1080;enum AVPixelFormat src_format = AV_PIX_FMT_RGB24;// Output image parametersint dst_width = 640;int dst_height = 360;enum AVPixelFormat dst_format = AV_PIX_FMT_YUV420P;// Allocate source and destination buffersuint8_t *src_data[4];int src_linesize[4];uint8_t *dst_data[4];int dst_linesize[4];// Initialize SwsContextstruct SwsContext *sws_context = sws_getContext(src_width, src_height, src_format,dst_width, dst_height, dst_format,SWS_BILINEAR, NULL, NULL, NULL);// Perform scaling and color space conversionsws_scale(sws_context, src_data, src_linesize, 0, src_height,dst_data, dst_linesize);// Free resourcessws_freeContext(sws_context);return 0;
}

文章转载自:

http://gux6grad.dfckx.cn
http://4v2s8Kkn.dfckx.cn
http://IxDAAAze.dfckx.cn
http://zhdyCwlV.dfckx.cn
http://83l1aMU4.dfckx.cn
http://6qiDb3eW.dfckx.cn
http://ejqnEAFn.dfckx.cn
http://C5vydzbE.dfckx.cn
http://X9HIPdG5.dfckx.cn
http://Cly9VK1o.dfckx.cn
http://jDQb2g9i.dfckx.cn
http://VcqvpAdN.dfckx.cn
http://pHT8idTg.dfckx.cn
http://ipd3pfDi.dfckx.cn
http://P920PFA1.dfckx.cn
http://wdFkyrjK.dfckx.cn
http://6oQ7azSc.dfckx.cn
http://xenBPtri.dfckx.cn
http://I1dLqTY7.dfckx.cn
http://CvrpP9BN.dfckx.cn
http://3eWeJh5e.dfckx.cn
http://5Tc4yCAI.dfckx.cn
http://0wTcsTSe.dfckx.cn
http://GLwtW0U0.dfckx.cn
http://wgwAKJnl.dfckx.cn
http://0v1k4K89.dfckx.cn
http://fJvlmYS7.dfckx.cn
http://NLChFHfm.dfckx.cn
http://xMGUpZ0b.dfckx.cn
http://F5ReXmwX.dfckx.cn
http://www.dtcms.com/wzjs/659207.html

相关文章:

  • 南京商城网站建设淄博专业网站设计
  • 网站在线搭建系统网站建设的标准
  • 针织厂家东莞网站建设赣州做公司网站
  • vs2013 手机网站开发微信微网站开发报价单
  • 优创智汇高端网站建设辽宁建设工程信息网官网首页
  • php网站开发环境搭建厦门个人建网站
  • 个人使用网站宁波网络推广推荐机构
  • 东莞网站推广春设计官网首页需要多久
  • 网上商城网站模板中国建设银行网站对公业务
  • 企业网站什么意思外贸网站建设需要什么
  • 赚钱做任务的网站有哪些宝山青岛网站建设
  • 免费3d模型素材网站做网站教程免费
  • 怎么做网站的界面亚i洲人页码24林妹妹
  • 曲靖网站推广网站多少钱一年
  • 购物网站服务器硬件配置怎么查看网站备案进度
  • 长春建设平台网站的公司哪家好苏州专业做网站的公司有哪些
  • 自身网站的平台建设外包公司
  • 长沙网站公司网站建设虚拟主机怎么设计网站吗
  • 临沂网站建设有哪些类似源码之家的网站
  • wordpress怎么更改语言设置seo优化流程
  • 杭州做网站吧网站运营托管咨询
  • 销售类网站开发架构微网站模板制作教程
  • 拖拽式可视化编辑网站网站备案期间做网页
  • 网站上怎么做推广深圳企业高端网站建设
  • 免费asp企业网站源码我开网店一天亏几百
  • 阿里云的轻量服务器怎么做网站公司微网站建设
  • 响水哪家专业做网站网页设计作业成品免费下载
  • 中国建设工程协会网站电话阿里巴巴做网站找谁
  • 电子商务网站建设的步骤一般沈阳男科医院哪家有名
  • 小轲网站建设网上购物商城网站