求支持Windows/Linux的视频(MP4/AVI/MPEG2)颜色数量统计软件
Hey there! Let's break down some solid tools that can help you count distinct colors in MP4, AVI, and MPEG-2 videos for palette comparison, covering both Windows and Linux systems:
These work seamlessly on both systems, giving you flexibility no matter your setup.
FFmpeg + Python Script
FFmpeg is the Swiss Army knife of video processing, and pairing it with a quick Python script gives you full control over color counting:
- First, extract frames from your video (adjust the frame rate based on how accurate you need the count to be):
This pulls 1 frame per second into affmpeg -i input.mp4 -vf fps=1 frames/%04d.pngframesfolder. Use-vf select='eq(n,0)'instead if you only want the first frame for a quick sample. - Next, use this Python script (requires the Pillow library) to tally up all unique colors across the frames:
Install Pillow withfrom PIL import Image import os unique_colors = set() frame_folder = "frames" for file in os.listdir(frame_folder): if file.endswith(".png"): img = Image.open(os.path.join(frame_folder, file)) unique_colors.update(img.getdata()) print(f"Total distinct colors found: {len(unique_colors)}")pip install pillowif you don't have it already.
DaVinci Resolve
If you're looking for a professional, GUI-based option, DaVinci Resolve is free and cross-platform. While it doesn't spit out a raw color count, it lets you visualize video palettes, compare color distributions across clips, and export palette swatches—perfect for side-by-side palette comparison work.
IrfanView + Plugins Pack
IrfanView is a lightweight, free image/video viewer that's great for quick palette analysis:
- Install IrfanView and the full Plugins Pack (make sure to enable video and color-related plugins during setup).
- Open your video file—IrfanView will load the first frame automatically.
- Head to
Image > Palette > Generate Paletteto create a palette from the frame. For multiple frames, useFile > Batch Conversion/Renameto extract frames as images first, then run the palette generator on the batch.
ImageMagick + MPlayer
For a command-line Linux workflow, this combo gets the job done efficiently:
- Extract frames from your video with MPlayer (adjust
-framesto control how many frames you analyze):mplayer input.mpeg2 -vo png:outdir=frames -frames 100 - Use ImageMagick to count all unique colors across the extracted frames:
Subtract 1 from the final number to exclude the header line in the output, and you'll have your distinct color count.convert frames/*.png -unique-colors txt:- | wc -l
All these options cover different workflows—whether you want quick GUI results or flexible command-line control. Let me know if you need help tweaking any of these methods!
内容的提问来源于stack exchange,提问作者celsowm

