npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mp4-compressor

v1.2.0

Published

A Node.js CLI tool for batch processing MP4 videos with intelligent compression, scaling and force compression mode / MP4视频批量处理工具,支持智能压缩、缩放和强制压缩模式

Readme

MP4文件处理工具

一个基于Node.js的命令行工具,用于批量处理MP4文件,支持自动压缩和分类管理。

中文 | English

功能特性

  • 🔍 自动扫描当前目录下的所有MP4文件
  • 📏 检测视频分辨率,小于720P的文件直接归档
  • 🎬 识别横屏/竖屏视频,采用不同的压缩策略
  • 🗜️ 使用FFmpeg进行高质量压缩(H.264 + AAC)
  • 🔥 强制压缩模式:可压缩所有视频,包括小于720P的
  • 📁 自动创建和管理文件夹(Done/Processed/Error)
  • ♻️ 持续处理直到目录清空

安装要求

系统依赖

  • Node.js >= 16.0.0
  • FFmpeg(包含ffprobe)
  • pnpm包管理器

安装FFmpeg(macOS)

brew install ffmpeg

安装项目依赖

pnpm install

安装和使用

全局安装(推荐)

  1. 一键安装:

    ./install-global.sh
  2. 在任意目录使用:

    # 处理当前目录下的MP4文件
    mp4-compressor
       
    # 指定其他目录
    mp4-compressor -d "/path/to/your/video/directory"
       
    # 强制压缩所有视频(包括小于720P的)
    mp4-compressor -f
       
    # 组合使用参数
    mp4-compressor -d "/path/to/videos" -f
       
    # 查看帮助
    mp4-compressor --help
  3. 卸载全局命令:

    pnpm unlink --global mp4-compressor

本地使用

如果不想全局安装,也可以在项目目录下直接运行:

# 使用默认目录
node index.js

# 指定其他目录
node index.js -d "/path/to/your/video/directory"

处理逻辑

  1. 扫描文件: 查找当前目录下所有.mp4/.MP4文件
  2. 验证文件: 使用ffprobe检查文件是否为有效视频
  3. 分辨率检查:
    • 较短边 ≤ 720: 直接移动到Done/目录(除非使用-f强制压缩)
    • 较短边 > 720: 进行压缩处理
    • 强制模式(-f): 压缩所有视频,无论分辨率大小
  4. 压缩设置:
    • 横屏视频: 缩放到1280x720,保持宽高比
    • 竖屏视频: 缩放到720x1280,保持宽高比
    • 比例处理: 自动添加黑边保持目标尺寸
    • 编码: H.264 (libx264) + AAC音频
  5. 文件管理:
    • 压缩后的文件: 保存到Done/目录
    • 原始文件: 移动到Processed/目录
    • 无效文件: 移动到Error/目录

目录结构

处理完成后会在工作目录下自动创建以下子目录:

工作目录/
├── *.mp4          # 待处理的MP4文件
├── Done/          # 处理完成的视频文件
├── Processed/     # 已处理的原始文件
└── Error/         # 无效或处理失败的文件

注意事项

  • 确保有足够的磁盘空间进行压缩操作
  • 大文件压缩可能需要较长时间
  • 建议在处理前备份重要文件
  • 工具会持续运行直到当前目录没有MP4文件

故障排除

如果遇到问题,请检查:

  1. FFmpeg是否正确安装:ffmpeg -version
  2. 文件权限是否足够
  3. 磁盘空间是否充足
  4. 视频文件是否损坏