惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
Engineering at Meta
Engineering at Meta
I
InfoQ
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 【当耐特】
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
腾讯CDC
雷峰网
雷峰网
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
D
Docker

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Hardware Video Compression in Rust on macOS — ffmpeg with...
hiyoyo · 2026-06-16 · via DEV Community
Cover image for Hardware Video Compression in Rust on macOS — ffmpeg with VideoToolbox

hiyoyo

All tests run on an 8-year-old MacBook Air. All results from shipping 7 Mac apps as a solo developer. No sponsored opinion.

HiyokoAutoSync optionally compresses videos during sync. Software compression on an 8-year-old MacBook Air is slow. Hardware compression via VideoToolbox is fast. Here's how to use ffmpeg's hardware acceleration from Rust.


VideoToolbox basics

VideoToolbox is Apple's hardware video encoding framework. ffmpeg supports it via the h264_videotoolbox encoder. The difference on Intel MacBook Air:

  • Software (libx264): 2-3 minutes for a 1-minute 4K video
  • Hardware (h264_videotoolbox): 15-30 seconds for the same video

For a sync app where users want to not think about it, this matters.


The ffmpeg command

ffmpeg -i input.mp4 \
  -c:v h264_videotoolbox \
  -b:v 5M \
  -c:a aac \
  -b:a 128k \
  output.mp4

h264_videotoolbox uses the hardware encoder. -b:v 5M sets video bitrate — adjust based on your quality/size tradeoff.


From Rust

use std::process::Command;

pub async fn compress_video(
    input: &Path,
    output: &Path,
    bitrate_mbps: u32,
) -> Result<(), AppError> {
    let bitrate = format!("{}M", bitrate_mbps);

    let status = tokio::task::spawn_blocking({
        let input = input.to_owned();
        let output = output.to_owned();
        move || {
            Command::new("ffmpeg")
                .args([
                    "-i", input.to_str().unwrap(),
                    "-c:v", "h264_videotoolbox",
                    "-b:v", &bitrate,
                    "-c:a", "aac",
                    "-b:a", "128k",
                    "-y", // overwrite output
                    output.to_str().unwrap(),
                ])
                .status()
        }
    }).await??;

    if !status.success() {
        return Err(AppError::Compression("ffmpeg failed".into()));
    }

    Ok(())
}


Fallback to software

VideoToolbox isn't available on all systems. Fallback gracefully:

async fn compress_with_fallback(input: &Path, output: &Path) -> Result<(), AppError> {
    // Try hardware first
    match compress_video_hw(input, output).await {
        Ok(()) => Ok(()),
        Err(_) => {
            log::warn!("Hardware encoding failed, falling back to software");
            compress_video_sw(input, output).await
        }
    }
}

Software fallback with libx264 is slower but reliable on any system.


Bundling ffmpeg

ffmpeg needs to be bundled with your Tauri app or assumed to be installed. I bundle a universal binary ffmpeg in the app resources. In tauri.conf.json:

{
  "bundle": {
    "resources": ["bin/ffmpeg"]
  }
}

Then access it via the resource directory at runtime.


TL;DR: Use ffmpeg's h264_videotoolbox encoder for hardware-accelerated video compression on macOS — 5-10x faster than libx264 on Intel Macs. Call via spawn_blocking in Rust, add a software fallback for systems where VideoToolbox isn't available, and bundle ffmpeg as a Tauri resource.


If this was useful, a ❤️ helps more than you'd think — thanks!

HiyokoAutoSync | X → @hiyoyok