Published on

Getting Audio/Video Information with FFmpeg

Authors
  • avatar
    Name
    Hieu Cao
    Twitter

Introduction

FFmpeg is a powerful multimedia framework capable of processing audio and video files. One of its many features is the ability to extract detailed metadata about audio and video files. This can be helpful for analyzing media properties, such as codec, bitrate, duration, resolution, and more. In this blog, you'll learn how to use FFmpeg to get audio and video information.


Why Extract Metadata?

Extracting metadata can provide valuable insights into your media files. Here are some common use cases:

  • Debugging playback or encoding issues.
  • Analyzing file properties for compatibility.
  • Automating media workflows.

Getting Started

Before we dive in, ensure FFmpeg is installed on your system. If you haven’t installed it yet, check out our guide on How to Install FFmpeg.


Extracting Metadata with FFmpeg

The ffprobe tool, bundled with FFmpeg, is specifically designed to extract metadata. Below are some common commands:

1. Basic File Information

To get basic metadata such as duration, codec, and format:

ffprobe -i input.mp4

Output Example:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Duration: 00:02:30.03, start: 0.000000, bitrate: 4000 kb/s
  Stream #0:0: Video: h264 (Main), yuv420p, 1920x1080, 30 fps
  Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp

2. Detailed Stream Information

For more detailed information about each stream:

ffprobe -i input.mp4 -show_streams

Output Example:

This command outputs information about video and audio streams, including codec, frame rate, resolution, and more.


3. Customizing Output Format

To extract metadata in a machine-readable format like JSON:

ffprobe -i input.mp4 -v quiet -print_format json -show_format -show_streams

This is especially useful for automating tasks or integrating metadata analysis into scripts.


4. Bitrate and Frame Rate

To focus on bitrate and frame rate:

ffmpeg -i input.mp4 2>&1 | grep 'bitrate\|fps'

Output Example:

bitrate: 4000 kb/s
fps: 30

5. Analyzing Audio Properties

To analyze audio properties, such as sample rate and channels:

ffmpeg -i input.mp4 2>&1 | grep 'Audio'

Output Example:

Audio: aac (LC), 48000 Hz, stereo, fltp

Tips and Best Practices

  • Use -v quiet for Cleaner Output: Suppress unnecessary logs by adding -v quiet to your commands.
  • Combine with Scripting: Automate metadata extraction using shell scripts or programming languages like Python.
  • Leverage JSON Format: Use JSON output for easier integration with data processing pipelines.

Conclusion

FFmpeg and ffprobe are invaluable tools for extracting and analyzing metadata from audio and video files. Whether you're debugging, analyzing, or automating, these tools provide a wealth of information to help you manage multimedia workflows efficiently. Try it out today and unlock the full potential of your media files!