Categories We Write About

Batch extract metadata from videos

To batch extract metadata from videos, you can use command-line tools or scripts that work across multiple files. One of the most effective tools for this task is FFmpeg (specifically using ffprobe), which can be paired with a script to automate metadata extraction.

Here’s how you can do it:


Requirements

  • FFmpeg installed (includes ffprobe)

  • Basic knowledge of using Terminal (Linux/macOS) or Command Prompt/Powershell (Windows)

  • Your video files collected in a single folder


Method 1: Bash Script (Linux/macOS)

bash
#!/bin/bash mkdir -p metadata_output for file in *.mp4; do filename="${file%.*}" ffprobe -v quiet -print_format json -show_format -show_streams "$file" > "metadata_output/${filename}_metadata.json" done

Save this script in the same directory as your videos (e.g., extract_metadata.sh), give it execution permissions:

bash
chmod +x extract_metadata.sh ./extract_metadata.sh

Method 2: PowerShell Script (Windows)

powershell
$files = Get-ChildItem -Path . -Filter *.mp4 foreach ($file in $files) { $output = ".metadata_output$($file.BaseName)_metadata.json" ffprobe -v quiet -print_format json -show_format -show_streams $file.FullName > $output }

Make sure to create the output folder first or add this line before the loop:

powershell
New-Item -ItemType Directory -Force -Path .metadata_output

Method 3: Python Script (Cross-platform)

python
import subprocess import json import os video_folder = "./videos" output_folder = "./metadata_output" os.makedirs(output_folder, exist_ok=True) for file in os.listdir(video_folder): if file.endswith(".mp4"): input_path = os.path.join(video_folder, file) output_path = os.path.join(output_folder, f"{os.path.splitext(file)[0]}_metadata.json") cmd = [ "ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", input_path ] with open(output_path, 'w') as out_file: subprocess.run(cmd, stdout=out_file)

Run it with:

bash
python extract_metadata.py

Output Example (.json)

Each .json will include details like:

  • Duration

  • Codec

  • Bitrate

  • Resolution

  • Frame rate

  • Audio channels

  • Creation time (if embedded)


Let me know if you want metadata in a CSV or need to process other formats like .mkv, .avi, or .mov.

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About