Mac FFmpeg打印音視頻信息

實戰 打印音視頻信息

Mac 已經配置好FFmpeg相關信息,如果沒有可以查看鏈接:https://blog.csdn.net/weixin_38735568/article/details/103282537

API有哪些

  1. av_reginster_all() 必須的
  2. avformat_open_input() / avformat_close_input() 打開和關閉多媒體文件
  3. av_dump_format() 多媒體文件信息

demo 獲取多媒體信息

創建:ffmpeg_media.c文件

#include<studio.h>
#include<libavutil/log.h>
#include<libavformat/format.h>
int main(int argc, char* argv[]) {
	int ret;
	AVFormatContext *fmt_ctx = NULL;
	av_log_set_level(AV_LOG_INFO);//設置日誌級別
	av_register_all();//註冊各種協議和相關配置
	/*
	*參數1:AVFormatContext,上下文的地址
	*參數2:輸入源URL
	*參數3:文件類型,不填去第二個參數eg:.mp4
	*參數4: 一般NULL,是一個函數傳參
	*/
	ret = avformat_open_input(&fmt_ctx, "./test.mp4", NULL, NULL);
	if (ret < 0) {
		av_log(NULL, AV_LOG_ERROR, "Cannot open file: %s\n", av_err2str(ret));
		return -1;
	}
	//讀取多媒體信息; 第四個參數0代表輸入,1代表輸出  參數2是流的索引值,可忽略
	av_dump_format(fmt_ctx, 0, "./test.mp4", 0)
	//關閉輸入源
	avformat_close_input(&fmt_ctx);
	return 0;
}

gcc編譯:

gcc -g -o ffmpeg_media ffmpeg_media.c `pkg-config --libs --cflags libavformat libavutil`
//pkg-config --libs --cflags libavformat libavutil作用就是給我們找到鏈接庫
//運行
./ffmpeg_mdeia

運行編譯好的文件:./ffmpeg_mdeia

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './test.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: isommp423gp5
    creation_time   : 2018-11-02T07:55:53.000000Z
    encoder         : FormatFactory : www.pcfreetime.com
  Duration: 00:13:49.28, bitrate: N/A  
    Stream #0:0(und): Video: mpeg4 (mp4v / 0x7634706D), none, 418 kb/s, SAR 1:1 DAR 0:0, 18 fps, 18 tbr, 18k tbn (default)
    Metadata:
      creation_time   : 2018-11-02T07:55:53.000000Z
      handler_name    : video
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, 2 channels, 125 kb/s (default)
    Metadata:
      creation_time   : 2018-11-02T07:55:53.000000Z
      handler_name    : sound
    Stream #0:2(und): Data: none (mp4s / 0x7334706D), 0 kb/s (default)
    Metadata:
      creation_time   : 2018-11-02T07:55:53.000000Z
      handler_name    : GPAC MPEG-4 OD Handler
    Stream #0:3(und): Data: none (mp4s / 0x7334706D), 0 kb/s (default)
    Metadata:
      creation_time   : 2018-11-02T07:55:53.000000Z
      handler_name    : GPAC MPEG-4 Scene Description Handler

解釋:

#0 代表是索引值,和我們傳的參數對應

Metadata:FFmpeg的版本相關

Duration: 00:13:49.28, bitrate: N/A 視頻時長

Stream #0:0(und): Video: mpeg4 (mp4v / 0x7634706D), none, 418 kb/s, SAR 1:1 DAR 0:0, 18 fps, 18 tbr, 18k tbn (default)

#0:0(und)低入流
Video 視頻
mpeg4 (mp4v / 0x7634706D)編碼格式
418 kb/s 比特率
18 fps 幀率
18 tbr, 18k tbn (default)時間基

第三部分
Metadata:
creation_time : 2018-11-02T07:55:53.000000Z
handler_name : video
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, 2 channels, 125 kb/s (default)

音頻流 相關信息 格式: aac 採樣率:44100 Hz, 聲道:2 channels, 比特率:125 kb/s (default)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章