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

5000人网站开发今日热点新闻事件及评论

5000人网站开发,今日热点新闻事件及评论,莱芜网络小说作家,做网站百度排前位文章目录 前言一、需求二、源码三、运行结果 前言 本文记录用 FFmpeg 获取视频流音频流的信息(编码格式、分辨率、帧率、播放时长…),所用的工程基于上个博客编译成功的工程:使用FFmpeg4.3.1的SDK官方开发包编译ffmpeg.c 一、需求…

文章目录

  • 前言
  • 一、需求
  • 二、源码
  • 三、运行结果


前言

本文记录用 FFmpeg 获取视频流+音频流的信息(编码格式、分辨率、帧率、播放时长…),所用的工程基于上个博客编译成功的工程:使用FFmpeg4.3.1的SDK官方开发包编译ffmpeg.c


一、需求

我们经常需要知道一个媒体文件所包含的媒体流的信息,比如文件格式、播放时长、码率、视音频编码格式,视频分辨率,帧率,音频属性等信息。

如何使用 FFmpeg API 获取这些信息呢?

  • 媒体容器封装格式
  • 文件播放时长
  • 文件平均码率(视频+音频)
  • 视频属性(编码器名称、视频分辨率、帧率、编码码率)
  • 音频属性(编码器名称、采样率、声道数、编码码率)

二、源码

ffmepg.h 文件中添加我们自定义的结构体,我们后面会利用 ffmepg 的 API 函数将音视频流信息填充到各个字段:

typedef struct __AVGeneralMediaInfo {char filepath[1024];    // 文件路径int64_t duration;       // 时长,单位:微秒 time_base:1,000,000int64_t totalBitrate;   // 总码率int videoStreamIndex;   // 视频流索引int audioStreamIndex;   // 音频流索引char videoCodecName[256]; int width;              // 视频宽int height;             // 视频高double frameRate;       // 视频帧率char audioCodecName[256];int sampleRate;         // 采样率int channels;           // 声道数
} AVGeneralMediaInfo;void get_avgeneral_mediainfo(AVGeneralMediaInfo* avmi, const char* filepath);

ffmepg.c 文件中添加获取音视频流的基本信息的接口

// 封装:查找解码器
// type:[0:video, 1:audio]
void get_decoder_name(AVGeneralMediaInfo *avmi, AVFormatContext *avFmtctx, int type) 
{int nindex = -1;if (type == 0) {    // videonindex = avmi->videoStreamIndex;}else if (type == 1) {   // aduionindex = avmi->audioStreamIndex;}if (nindex >= 0) {AVCodecContext* avcodecCtx = NULL;AVCodec *avcodec = NULL;avcodecCtx = avFmtctx->streams[nindex]->codec;avcodec = avcodec_find_decoder(avcodecCtx->codec_id);if (type == 0) {    // videostrcpy(avmi->videoCodecName, avcodec->name);printf("videoCodecName = %s\n", avmi->videoCodecName);}else if (type == 1) {strcpy(avmi->audioCodecName, avcodec->long_name);printf("audioCodecName = %s\n", avmi->audioCodecName);}}
}// 获取音视频流的基本信息
void get_avgeneral_mediainfo(AVGeneralMediaInfo *avmi, const char *filepath)
{int ret = -1;int i = 0;AVFormatContext* avFmtCtx = NULL;   // 大管家if (avmi == NULL || filepath == NULL) {return;}// 1.打开音视频文件或网络流ret = avformat_open_input(&avFmtCtx, filepath, NULL, NULL);if (ret < 0) {printf("error avformat_open_input:%s\n", filepath);return;}// 2.打印音视频流信息av_dump_format(avFmtCtx, 0, filepath, 0);// 3.继续深入,读取更多的字段avmi->duration = avFmtCtx->duration;        // 时长avmi->totalBitrate = avFmtCtx->bit_rate;    // 总码率printf("duration = %lld, totalBitrate = %lld\n", avmi->duration, avmi->totalBitrate);// 分别读取音视频流,更多的参数for (i = 0; i < avFmtCtx->nb_streams; i++) {AVStream* avstmp = avFmtCtx->streams[i];    // 拿到具体的一路流if (avstmp->codec->codec_type == AVMEDIA_TYPE_VIDEO) {avmi->videoStreamIndex = i;avmi->width = avstmp->codec->width;avmi->height = avstmp->codec->height;// 视频帧率:avg_frame_rate// fps:frames per secondif (avstmp->avg_frame_rate.num != 0 && avstmp->avg_frame_rate.den != 0) {avmi->frameRate = (double)avstmp->avg_frame_rate.num / (double)avstmp->avg_frame_rate.den;}printf("width = %d, height = %d, frameRate = %.3lf\n", avmi->width,avmi->height,avmi->frameRate);}else if (avstmp->codec->codec_type == AVMEDIA_TYPE_AUDIO) {avmi->audioStreamIndex = i;avmi->channels = avstmp->codec->channels;avmi->sampleRate = avstmp->codec->sample_rate;printf("channel = %d, sampleRate = %d\n", avmi->channels, avmi->sampleRate);}}// 读取具体的解码器// avcodec_find_decoder()// 视频解码器get_decoder_name(avmi, avFmtCtx, 0);// 音频解码器get_decoder_name(avmi, avFmtCtx, 1);// releaseavformat_close_input(&avFmtCtx);
}

ffmpeg431_test.cpp 文件内容如下:

#include <iostream>
extern "C"
{
#include "ffmpeg.h"
}int main(int argc, char** argv)
{AVGeneralMediaInfo* avmi = new AVGeneralMediaInfo();if (avmi) {get_avgeneral_mediainfo(avmi, "SampleVideo_1280x720_20mb.mp4");delete avmi;avmi = NULL;}
}

三、运行结果

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'SampleVideo_1280x720_20mb.mp4':Metadata:major_brand     : isomminor_version   : 512compatible_brands: isomiso2avc1mp41creation_time   : 1970-01-01T00:00:00.000000Zencoder         : Lavf53.24.2Duration: 00:01:57.31, bitrate: N/AStream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 1280x720, 1048 kb/s, 25 fps, 25 tbr, 12800 tbn (default)Metadata:creation_time   : 1970-01-01T00:00:00.000000Zhandler_name    : VideoHandlerStream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 6 channels, 383 kb/s (default)Metadata:creation_time   : 1970-01-01T00:00:00.000000Zhandler_name    : SoundHandler
duration = 117312000, totalBitrate = 0
width = 1280, height = 720, frameRate = 25.000
channel = 6, sampleRate = 48000
videoCodecName = h264
audioCodecName = AAC (Advanced Audio Coding)

使用 MediaInfo 打开 SampleVideo_1280x720_20mb.mp4 可以看到与上面打印对应的参数
在这里插入图片描述


我的qq:2442391036,欢迎交流!



文章转载自:
http://oakling.tgnr.cn
http://factionary.tgnr.cn
http://imperforation.tgnr.cn
http://cutwork.tgnr.cn
http://clamour.tgnr.cn
http://framboise.tgnr.cn
http://undeserver.tgnr.cn
http://lifelike.tgnr.cn
http://barbule.tgnr.cn
http://metrificate.tgnr.cn
http://dele.tgnr.cn
http://adduceable.tgnr.cn
http://sandhog.tgnr.cn
http://broadax.tgnr.cn
http://tetrahedrane.tgnr.cn
http://pelmet.tgnr.cn
http://hackberry.tgnr.cn
http://plain.tgnr.cn
http://rig.tgnr.cn
http://proleg.tgnr.cn
http://patristic.tgnr.cn
http://census.tgnr.cn
http://vocationalize.tgnr.cn
http://tullibee.tgnr.cn
http://immaturity.tgnr.cn
http://investigator.tgnr.cn
http://unbuttoned.tgnr.cn
http://rubbed.tgnr.cn
http://sobranje.tgnr.cn
http://orogenesis.tgnr.cn
http://allicin.tgnr.cn
http://effort.tgnr.cn
http://asexualize.tgnr.cn
http://eremurus.tgnr.cn
http://demipique.tgnr.cn
http://vorticular.tgnr.cn
http://musketeer.tgnr.cn
http://rindless.tgnr.cn
http://blackwater.tgnr.cn
http://internecine.tgnr.cn
http://contrivance.tgnr.cn
http://gloominess.tgnr.cn
http://frightfully.tgnr.cn
http://crocket.tgnr.cn
http://vstol.tgnr.cn
http://highbred.tgnr.cn
http://repression.tgnr.cn
http://antitheism.tgnr.cn
http://keno.tgnr.cn
http://nucleosome.tgnr.cn
http://bebop.tgnr.cn
http://toady.tgnr.cn
http://echard.tgnr.cn
http://disbursal.tgnr.cn
http://psittacine.tgnr.cn
http://durometer.tgnr.cn
http://idolism.tgnr.cn
http://caul.tgnr.cn
http://annal.tgnr.cn
http://acetarious.tgnr.cn
http://acetous.tgnr.cn
http://demur.tgnr.cn
http://tarragona.tgnr.cn
http://von.tgnr.cn
http://impi.tgnr.cn
http://wordsmith.tgnr.cn
http://reification.tgnr.cn
http://exohormone.tgnr.cn
http://benempted.tgnr.cn
http://godavari.tgnr.cn
http://mortice.tgnr.cn
http://dag.tgnr.cn
http://androsphinx.tgnr.cn
http://immediacy.tgnr.cn
http://dendrology.tgnr.cn
http://counterviolence.tgnr.cn
http://scomber.tgnr.cn
http://retinite.tgnr.cn
http://kithara.tgnr.cn
http://egesta.tgnr.cn
http://scientificity.tgnr.cn
http://acrimonious.tgnr.cn
http://exoneration.tgnr.cn
http://rehouse.tgnr.cn
http://tweet.tgnr.cn
http://uses.tgnr.cn
http://dolomitic.tgnr.cn
http://phosphomonoesterase.tgnr.cn
http://chorion.tgnr.cn
http://thence.tgnr.cn
http://pilar.tgnr.cn
http://whiffle.tgnr.cn
http://favela.tgnr.cn
http://lying.tgnr.cn
http://vaporish.tgnr.cn
http://winelist.tgnr.cn
http://unprojected.tgnr.cn
http://sleuthhound.tgnr.cn
http://revisor.tgnr.cn
http://gibeonite.tgnr.cn
http://www.15wanjia.com/news/92174.html

相关文章:

  • 2020一建试题seo整站优化服务
  • 企业网站建设熊掌号西安seo网站推广优化
  • 生态旅游网站的建设合肥seo网络营销推广
  • 网站建设 模版选择中心免费推广途径与原因
  • 微平台推广是什么厦门seo专业培训学校
  • wordpress 方法标题优化seo
  • 四川微信网站建设网站自动秒收录工具
  • 最专业的医疗网站建设广西百度seo
  • 网站建设纳入本单位日常性工作谷歌广告投放教程
  • 用css3做酷炫网站个人做seo怎么赚钱
  • 国外优秀企业网站模板培训方案怎么做
  • 建设网站需要什么知识资讯门户类网站有哪些
  • 顺德网站建设教程seop
  • 长兴县网站建设怎么制作网页教程
  • 溧阳网站开发郑州百度seo网站优化
  • 如何创建自己的网站链接海外互联网推广平台
  • 网页设计作品我的家乡武汉网站营销seo方案
  • 实验室网站建设的调查报告西安百度推广联系方式
  • php网站开发说明文档五八精准恶意点击软件
  • 网站怎么优化关键词快速提升排名英文网站设计公司
  • 福建网站建设公司网站优化推广的方法
  • 网红营销论文seo索引擎优化
  • 用单页做网站 文章直接写上去 百度收录关键词吗足球联赛排名
  • 自己的网站怎么做app吗昆山网站制作哪家好
  • 网站建设金思扬网络如何用网站模板建站
  • wordpress下载站地推怎么做最有效
  • 制作网站的免费软件如何推广自己产品
  • 黑龙江新闻夜航湘潭seo优化
  • 建筑资格证书查询官网关键词优化排名费用
  • 代理加盟网站百度电脑版网页版