Getting video dimension / resolution / width x height from ffmpeg

前端 未结 8 1573
粉色の甜心
粉色の甜心 2020-11-27 05:33

How would I get the height and width of a video from ffmpeg\'s information output. For example, with the following output:

$ ffmpeg -i video.mp4         


        
8条回答
  •  青春惊慌失措
    2020-11-27 06:07

    Use ffprobe

    Example 1: With keys / variable names

    ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 input.mp4
    width=1280
    height=720
    

    Example 2: Just width x height

    ffprobe -v error -show_entries stream=width,height -of csv=p=0:s=x input.m4v
    1280x720
    

    Example 3: JSON

    ffprobe -v error -show_entries stream=width,height -of json input.mkv 
    {
        "programs": [
    
        ],
        "streams": [
            {
                "width": 1280,
                "height": 720
            },
            {
    
            }
        ]
    }
    

    What the options do:

    • -v error Make a quiet output, but allow errors to be displayed. Excludes the usual generic FFmpeg output info including version, config, and input details.

    • -show_entries stream=width,height Just show the width and height stream information.

    • -of option chooses the output format (default, compact, csv, flat, ini, json, xml). See FFprobe Documentation: Writers for a description of each format and to view additional formatting options.

    • -select_streams v:0 This can be added in case your input contains multiple video streams. v:0 will select only the first video stream. Otherwise you'll get as many width and height outputs as there are video streams.

    • See the FFprobe Documentation and FFmpeg Wiki: FFprobe Tips for more info.

提交回复
热议问题