以前在項目中一直用mediainfo來獲取媒體文件或流的信息,好比封裝格式、音視頻編碼格式、碼率等信息。 html
但實際使用中發現mediainfo輸出的字段不容易被解析,並且表述方法不統一。例如,對於h264這種編碼格式,mediainfo可能輸出的表述爲H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10;還好比,對於mp3這樣的音頻格式,竟然會分兩個字段進行描述,分別說明mpeg和layer3。因此在項目中苦於這種不肯定的因素。 shell
以前就在ffmpeg官網上看過ffprobe,不過名氣被ffmpeg蓋過了,沒多少人使用,網上也沒有什麼介紹的資料。算了,本身寫一點,記錄一下吧。 json
官網說明:http://ffmpeg.org/ffprobe.html ide
ffprobe的編譯就不說了,編譯ffmpeg時控制一下configure的參數便可。 編碼
OK,下面簡單使用一下。 spa
命令行: 命令行
./ffprobe -print_format json -show_format -show_streams -i ./video/c.ts code
其中: orm
-print_format json(以json格式輸出), 視頻
-show_format(輸出封裝格式信息),
-show_streams(輸出流信息),
-i ./video/c.ts(輸入文件)
Input #0, mpegts, from './video/c.ts': Duration: 00:00:59.67, start: 1.172511, bitrate: 919 kb/s Program 1 Metadata: service_name : Service01 service_provider: FFmpeg Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 640x360, 25 fps, 25 tbr, 90k tbn, 50 tbc Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 103 kb/s "streams": [ { "index": 0, "codec_name": "h264", "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", "profile": "High", "codec_type": "video", "codec_time_base": "1/50", "codec_tag_string": "[27][0][0][0]", "codec_tag": "0x001b", "width": 640, "height": 360, "has_b_frames": 2, "sample_aspect_ratio": "0:1", "display_aspect_ratio": "0:1", "pix_fmt": "yuv420p", "level": 30, "is_avc": "0", "nal_length_size": "0", "id": "0x100", "r_frame_rate": "25/1", "avg_frame_rate": "25/1", "time_base": "1/90000", "start_pts": 108000, "start_time": "1.200000", "duration_ts": 5367600, "duration": "59.640000", "disposition": { "default": 0, "dub": 0, "original": 0, "comment": 0, "lyrics": 0, "karaoke": 0, "forced": 0, "hearing_impaired": 0, "visual_impaired": 0, "clean_effects": 0, "attached_pic": 0 } }, { "index": 1, "codec_name": "aac", "codec_long_name": "AAC (Advanced Audio Coding)", "codec_type": "audio", "codec_time_base": "1/44100", "codec_tag_string": "[15][0][0][0]", "codec_tag": "0x000f", "sample_fmt": "fltp", "sample_rate": "44100", "channels": 2, "bits_per_sample": 0, "id": "0x101", "r_frame_rate": "0/0", "avg_frame_rate": "0/0", "time_base": "1/90000", "start_pts": 105526, "start_time": "1.172511", "duration_ts": 5340780, "duration": "59.342000", "bit_rate": "103359", "disposition": { "default": 0, "dub": 0, "original": 0, "comment": 0, "lyrics": 0, "karaoke": 0, "forced": 0, "hearing_impaired": 0, "visual_impaired": 0, "clean_effects": 0, "attached_pic": 0 } } ], "format": { "filename": "./video/c.ts", "nb_streams": 2, "format_name": "mpegts", "format_long_name": "MPEG-TS (MPEG-2 Transport Stream)", "start_time": "1.172511", "duration": "59.667489", "size": "6859932", "bit_rate": "919754" } }
嗯,效果仍是不錯的。