乐闻世界logo
搜索文章和话题

How can I get the resolution (width and height) for a video file from a linux command line?

1个答案

1

To retrieve the resolution of a video file via the Linux command line, multiple tools are available, but the most commonly used and powerful option is ffprobe, which is part of the FFmpeg suite. FFmpeg is a widely adopted multimedia processing tool that supports virtually all video formats.

Installing FFmpeg

First, ensure FFmpeg is installed on your system. On most Linux distributions, you can install it using the package manager. For example, on Ubuntu or Debian systems, use the following command:

bash
sudo apt-get update sudo apt-get install ffmpeg

Using ffprobe to Retrieve Video Resolution

After installation, use ffprobe to obtain detailed information about the video file, including its resolution. Here is a command-line example:

bash
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 input_video.mp4

Here's an explanation of the parameters:

  • -v error: Display only error messages to minimize output clutter and enhance clarity.
  • -select_streams v:0: Select the first video stream from the file.
  • -show_entries stream=width,height: Specify to show only the width and height of the video stream.
  • -of csv=p=0: Set the output format to CSV for straightforward data parsing.
  • input_video.mp4: The name of the video file to inspect.

Example Output

Suppose you have a video file named example.mp4. Running the command may produce output like this:

shell
1920,1080

This indicates a resolution of 1920 pixels wide by 1080 pixels high.

Practical Applications

This method is ideal for scripting, especially when processing multiple files or checking resolutions in bulk. It integrates seamlessly into shell scripts for automated analysis and management of video libraries.

For instance, in a multimedia project requiring specific resolution standards, you can write a script to automatically verify each file and report non-compliant entries. This streamlines media resource management.

2024年8月9日 01:50 回复

你的答案