如何获取存储在七牛上的视频长度

作者: php 发布时间: 2017-08-14 浏览: 4559 次 编辑

我们在开发视频中经常需要获取存储在七牛上的视频长度。我们可以通过视频的url 拼接上?avinfo 来获取视频的信息,其中duration就是视频的时间,单位是秒(s

例如地址:http://v.niwoxuexi.com/android/base/%E5%AF%BC%E8%AF%BB.mp4?avinfo

获取的信息如下:

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Main",
            "codec_type": "video",
            "codec_time_base": "1/60",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1280,
            "height": 800,
            "coded_width": 1280,
            "coded_height": 800,
            "has_b_frames": 2,
            "sample_aspect_ratio": "0:1",
            "display_aspect_ratio": "0:1",
            "pix_fmt": "yuv420p",
            "level": 32,
            "color_space": "bt709",
            "color_transfer": "bt709",
            "color_primaries": "bt709",
            "chroma_location": "left",
            "refs": 5,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "30/1",
            "avg_frame_rate": "30/1",
            "time_base": "1/3000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 1296800,

            "duration": "432.266667",

            "bit_rate": "1022922",
            "bits_per_raw_sample": "8",
            "nb_frames": "12968",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },

            "tags": {

                "creation_time": "2017-07-16 14:33:34",

                "language": "und",

                "encoder": "JVT/AVC Coding"
            }
        },
        {
            "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",
            "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": 19062784,
            "duration": "432.262676",
            "bit_rate": "217513",
            "max_bit_rate": "292136",
            "nb_frames": "18616",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {

                "creation_time": "2017-07-16 14:33:34",

                "language": "und"
            }
        }
    ],

    "format": {

        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "432.266000",
        "size": "67263559",
        "bit_rate": "1244854",
        "probe_score": 100,
        "tags": {
            "major_brand": "mp42",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "creation_time": "2017-07-16 14:33:34"
        }
    }
}