今日已更新 339 条资讯 | 累计 19899 条内容
关于我们

How to Use FFmpeg with Swift (No Installation Required)

Javid Jamae 2026年07月07日 08:15 4 次阅读 来源:Dev.to

Originally published at ffmpeg-micro.com You need server-side video processing in your Swift app. Maybe you're building a Vapor backend that transcodes user uploads, a macOS utility that batch-converts media files, or a command-line tool that generates thumbnails. FFmpeg is the standard tool for the job, but getting it into a Swift project isn't as simple as adding a package dependency. Running FFmpeg from Swift with Process Swift's Foundation framework provides the Process class for running external commands. If FFmpeg is installed on the machine, you can shell out to it directly: import Foundation let process = Process () process . executableURL = URL ( fileURLWithPath : "/opt/homebrew/bin/ffmpeg" ) process . arguments = [ "-i" , "input.mp4" , "-c:v" , "libx264" , "-crf" , "23" , "-preset" , "medium" , "-c:a" , "aac" , "-b:a" , "128k" , "output.mp4" ] let pipe = Pipe () process . standardOutput = pipe process . standardError = pipe try process . run () process . waitUntilExit () let data = pipe . fileHandleForReading . readDataToEndOfFile () let output = String ( data : data , encoding : . utf8 ) ?? "" print ( output ) guard process . terminationStatus == 0 else { fatalError ( "FFmpeg failed with exit code \( process . terminationStatus ) " ) } This works on macOS and Linux. Install FFmpeg with brew install ffmpeg on macOS or apt-get install ffmpeg on Ubuntu, point executableURL at the binary, and you're running. But you own that FFmpeg install on every machine. On Linux servers, you're managing the binary across deploys. On macOS CI runners, you're adding Homebrew steps to your build pipeline. And on iOS, Process doesn't exist at all. Processing Video via Cloud API (No FFmpeg Install) Skip the local binary entirely. FFmpeg Micro exposes full FFmpeg capabilities through a REST API. Send a video URL, pick your settings, get processed video back. If you're familiar with how this works in Node.js or Kotlin , the pattern is identical. Here's the basic flow using URLSe

本文内容来源于互联网,版权归原作者所有
查看原文