1 Star 0 Fork 0

shchlu/ffmpeg_clpus_learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.cpp 2.92 KB
一键复制 编辑 原始数据 按行查看 历史
shchlu 提交于 3年前 . 基本信息打印
#include <iostream>
extern "C" {
#include <libavformat/avformat.h>
}
using namespace std;
/*
* 编解码器(CODEC):能够进行视频和音频压缩(CO)与解压缩(DEC),是视频编解码的核心部分。
* 容器/多媒体文件(Container/File)
*常下载的电影的文件的后缀(avi,mkv,rmvb等)是其封装的方式。
* 一个视频文件通常有视频数据、音频数据以及字幕等,封装的格式决定这些数据在文件中是如何的存放的,
* 封装在一起音频、视频等数据组成的多媒体文件,也可以叫做容器(其中包含了视音频数据)。所以,只看多媒体文件的后缀名是难以知道视音频的编码方式的。
*
*流数据 Stream,例如视频流(Video Stream),音频流(Audio Stream)。流中的数据元素被称为帧Frame。
* */
int main() {
// 测试路径文件
const char *path = "../test_file/test_video.mp4";
AVFormatContext *avc = avformat_alloc_context();
AVDictionary *opts = nullptr;
// av_log_set_level(AV_LOG_DEBUG);
int ret = avformat_open_input(&avc, path, nullptr, &opts);
if (ret != 0) {
char buf[1024] = {0};
av_strerror(ret, buf, sizeof(buf) - 1);
printf("open %s failed!:%s", path, buf);
exit(ret);
}
cout << "文件打开成功" << endl;
// 文件流数据
ret = avformat_find_stream_info(avc, nullptr);
if (ret != 0) {
cout << "获取流数据信息错误" << endl;
exit(ret);
}
cout << "url: " << avc->url << endl;
cout << "stream个数:" << avc->nb_streams << endl;
cout << "视频时长(微妙):" << avc->duration << endl;
auto sec = avc->duration / AV_TIME_BASE;
cout << "总时长: " << sec / 3600 << "时" << sec % 3600 / 60 << "分" << sec % 60 << "秒" << endl;
//stream
for (int i = 0; i < avc->nb_streams; ++i) {
AVStream *pStream = avc->streams[i];
if (AVMEDIA_TYPE_AUDIO == pStream->codecpar->codec_type) {
auto s = pStream->time_base.den == 0 ? 0 : (double) pStream->time_base.num /(double) pStream->time_base.den;
cout << "音频信息:" << endl;
cout << "index: " << pStream->index << endl
<< "采样率: " << pStream->codecpar->sample_rate << " Hz" << endl
<< "采样格式: " << pStream->codecpar->format << endl
<< "音频信道数目:" << pStream->codecpar->channels << endl
<< "音频压缩编码格式:" << pStream->codecpar->codec_id << endl
<< "音频时长: " << (double)pStream->duration * s<<"秒";
}
}
// 释放资源
avformat_close_input(&avc);
return 0;
}
int main1() {
unsigned int version = avformat_version();
cout << "version:" << version << endl;
const char *config = avcodec_configuration();
cout << "config: " << config << endl;
cout << avcodec_license() << endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/shchlu/ffmpeg_clpus_learn.git
git@gitee.com:shchlu/ffmpeg_clpus_learn.git
shchlu
ffmpeg_clpus_learn
ffmpeg_clpus_learn
master

搜索帮助