获得音视频信息

https://blog.csdn.net/shunqixing/article/details/79692850

ffprobe是FFmpeg项目提供的用于分析视频信息的命令行工具。

随意下载一个测试视频testmp4, 然后终端中输入指令:

ffprobe -v quiet -print_format json -show_format -show_streams test.mp4
示例中使用-v quiet选项将日志级别设为quiet避免日志信息污染json,-show_format显示文件的容器信息,-show_stream显示容器中流的信息,-show_frames则可以显示视频中每一帧的信息。

更多关于ffprobe的内容可以参考官方文档

可以获得json格式输出的视频信息:

{
    "streams": [ // 文件中包含的流
        {
            "index": 0,  // 流的序号
            "codec_name": "h264", // 流的编码格式
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", // 编码格式的全名
            "profile": "High", 
            "codec_type": "video", // video表示这是一个视频流
            "codec_time_base": "1/60",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1080, // 视频宽为1080像素
            "height": 614, // 视频高为614像素
            "coded_width": 1080,
            "coded_height": 614,
            "has_b_frames": 2,
            "sample_aspect_ratio": "0:1",
            "display_aspect_ratio": "0:1",
            "pix_fmt": "yuv420p",
            "level": 31,
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "30/1", // 实际帧率
            "avg_frame_rate": "30/1",
            "time_base": "1/15360",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 153093,  
            "duration": "9.966992",  // 以秒为单位的视频时间
            "bit_rate": "2077265",  // 视频的比特率
            "bits_per_raw_sample": "8",
            "nb_frames": "299",
            "tags": {  // 流中的附加信息,其中的字段可能为空
                "rotate": 90, // 视频旋转的角度
                "language": "und",
                "handler_name": "VideoHandler"
            }
        },
        {
            "index": 1, // 流编号
            "codec_name": "aac", // 流的编码格式
            "codec_long_name": "AAC (Advanced Audio Coding)", // 编码格式的全名
            "profile": "LC",
            "codec_type": "audio", // 这是一个音频流
            "codec_time_base": "1/44100", 
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "44100", // 采样率
            "channels": 2, // 声道数
            "channel_layout": "stereo", // 声道布局,stereo为立体双声道
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/44100",  // 每帧时长
            "start_pts": 0,
            "start_time": "0.000000", // 流开始播放时间
            "duration_ts": 442367,
            "duration": "10.030998",  // 流时长
            "bit_rate": "129341",  // 比特率
            "max_bit_rate": "129341",
            "nb_frames": "433",
            "tags": {
                "language": "und",
                "handler_name": "SoundHandler"
            }
        }
    ],
    "format": {  // 容器信息
        "filename": "test.mp4",  // 文件名
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2", // 封装格式名
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "10.055000",
        "size": "2762615",  // 文件字节数
        "bit_rate": "2198002", // 比特率
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "encoder": "Lavf57.71.100"
        }
    }
}

转至:https://www.cnblogs.com/Finley/p/8646711.html#y--n

原文地址:https://www.cnblogs.com/lily1989/p/8868676.html