实例代码
Code
| int video_audio_info(int argc, char *argv[]) |
| { |
| if (argc < 2) { |
| printf("Usage : %s mediaFile\n", argv[0]); |
| return -1; |
| } |
| AVFormatContext *ic = NULL; |
| char path[20] = { 0 }; |
| strcpy(path, argv[1]); |
| |
| int ret = avformat_open_input(&ic, path, 0, 0); |
| if (ret != 0) |
| { |
| printf("avformat_open_input called failed:"); |
| return -1; |
| } |
| printf("avformat_open_input called success\n"); |
| |
| |
| printf("before duration :%ld, nb_stream :%d\n", ic->duration, ic->nb_streams); |
| if (avformat_find_stream_info(ic, 0) >= 0) { |
| printf("after duration :%ld, nb_stream :%d\n", ic->duration, ic->nb_streams); |
| } |
| |
| int fps = 0; |
| int videoStream = 0; |
| int audioStream = 1; |
| for (int i = 0; i < ic->nb_streams; i++) { |
| AVStream *as = ic->streams[i]; |
| |
| |
| if (as->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
| |
| printf("video stream.................\n"); |
| videoStream = i; |
| |
| printf("width = %d, height = %d, codecid = %d, format = %d, fps = %d\n", |
| as->codecpar->width, |
| as->codecpar->height, |
| as->codecpar->codec_id, |
| as->codecpar->format, |
| as->avg_frame_rate.num); |
| } |
| |
| |
| else if (as->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { |
| printf("audio stream.................\n"); |
| audioStream = i; |
| printf("sample_rate = %d, channels = %d, sample_format = %d\n", |
| as->codecpar->sample_rate, |
| as->codecpar->channels, |
| as->codecpar->format); |
| } |
| } |
| |
| avformat_close_input(&ic); |
| return 0; |
| } |
结果

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
2023-01-28 心理学-心理学效应-熵增定律
2023-01-28 心理学-心理效应-达克效应