linux - 如何从 linux 命令行获取视频文件的分辨率(宽度和高度)?

我一直在研究 mplayer/mencoder 和 ffmpeg 文档,但我似乎想不出任何东西。我对输出格式并不是特别挑剔,因为我可以使用正则表达式将其拉出,我似乎一开始就无法获取数据。

最佳答案

使用 ffprobe (FFmpeg 工具包的一部分)

示例:

ffprobe -v quiet -print_format json -show_format -show_streams ~/Movies/big_buck_bunny_720p_5mb.mp4

输出:

{
    "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/50",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1280,
            "height": 720,
            "coded_width": 1280,
            "coded_height": 720,
            "has_b_frames": 0,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 31,
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "1",
            "nal_length_size": "4",
            "r_frame_rate": "25/1",
            "avg_frame_rate": "25/1",
            "time_base": "1/12800",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 378368,
            "duration": "29.560000",
            "bit_rate": "1032960",
            "bits_per_raw_sample": "8",
            "nb_frames": "739",
            "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": "1970-01-01 00:00:00",
                "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/48000",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 6,
            "channel_layout": "5.1",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 1419264,
            "duration": "29.568000",
            "bit_rate": "383960",
            "max_bit_rate": "416704",
            "nb_frames": "1386",
            "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": "1970-01-01 00:00:00",
                "language": "und",
                "handler_name": "SoundHandler"
            }
        }
    ],
    "format": {
        "filename": "/Users/farsheed/Movies/big_buck_bunny_720p_5mb.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": "29.568000",
        "size": "5253880",
        "bit_rate": "1421504",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "creation_time": "1970-01-01 00:00:00",
            "encoder": "Lavf53.24.2"
        }
    }
}

有关详细信息,请参阅文档。

https://stackoverflow.com/questions/684015/

相关文章:

linux - 如何在linux中停止 screen 进程?

python - standard_init_linux.go :178: exec user pr

linux - curl 用于获取标题

linux - 在 Unix 上计算每行/字段的字符出现次数

linux - 远程 Linux 服务器到远程 linux 服务器目录复制。如何?

linux - 如何使用 Linux 命令获取可用内存百分比?

linux - 如何自动化 HTML 到 PDF 的转换?

php - 使用 WGET 运行 cronjob PHP

linux - 如何将一个文本文件拆分为多个 *.txt 文件?

linux - 如何运行 nohup 并将其 pid 文件写入单个 bash 语句