ffmpeg 音频提取与转码
audio-extraction
使用 ffmpeg 模式从视频文件中提取音频,并在不同格式之间进行转码。
- License 许可
- MIT
- 所属仓库
- jmagly/aiwg
- 最近更新
- 2026-11-14
- Stars
- ★ 229
- Forks
- 36
01 前言 Front Matter
- name
- audio-extraction
- category
- media-curator
- namespace
- aiwg
- platforms
- [ "all" ]
- description
- ffmpeg patterns for extracting audio from video files and transcoding between formats
02 资源文件 1
- 参考文档logic-locate-guide.md4.1 KB
03 SKILL.md 正文
Audio Extraction
Patterns for extracting audio tracks from video files and transcoding between audio formats using ffmpeg.
Extract Audio from Video
To Opus (Recommended for collections)
# Standard quality (128k) - good balance of size and quality
ffmpeg -y -i input.mp4 -vn -acodec libopus -b:a 128k output.opus
# High quality (192k) - for studio sessions and interviews
ffmpeg -y -i input.mp4 -vn -acodec libopus -b:a 192k output.opus
# Lower quality (96k) - for long-form content like full concerts
ffmpeg -y -i input.mp4 -vn -acodec libopus -b:a 96k output.opus
To FLAC (Lossless preservation)
ffmpeg -y -i input.mp4 -vn -acodec flac output.flac
To MP3 (Maximum compatibility)
# VBR quality 2 (~190kbps, excellent quality)
ffmpeg -y -i input.mp4 -vn -acodec libmp3lame -q:a 2 output.mp3
# CBR 320kbps (maximum quality)
ffmpeg -y -i input.mp4 -vn -acodec libmp3lame -b:a 320k output.mp3
Batch Extraction
All Videos in Directory to Opus
for f in video/*.mp4; do
[ -f "$f" ] || continue
base=$(basename "${f%.mp4}")
[ -f "audio/${base}.opus" ] && continue # Skip existing
ffmpeg -y -i "$f" -vn -acodec libopus -b:a 128k "audio/${base}.opus"
done
Parallel Batch Extraction (GNU parallel)
find video/ -name "*.mp4" -print0 | \
xargs -0 -P 4 -I{} sh -c '
base=$(basename "${1%.mp4}")
[ -f "audio/${base}.opus" ] || \
ffmpeg -y -i "$1" -vn -acodec libopus -b:a 128k "audio/${base}.opus"
' _ {}
Format Transcoding
FLAC to Opus
ffmpeg -y -i input.flac -acodec libopus -b:a 128k output.opus
FLAC to MP3
ffmpeg -y -i input.flac -acodec libmp3lame -q:a 2 output.mp3
Opus to MP3 (when Opus not supported by target)
ffmpeg -y -i input.opus -acodec libmp3lame -q:a 2 output.mp3
M4A to Opus
ffmpeg -y -i input.m4a -acodec libopus -b:a 128k output.opus
Quality Verification
Check Audio Bitrate
ffprobe -v quiet -show_entries format=bit_rate \
-of default=noprint_wrappers=1:nokey=1 input.opus
Check Audio Format Details
ffprobe -v quiet -show_entries stream=codec_name,sample_rate,channels,bit_rate \
-of json input.opus
Detect Clipping/Distortion
ffmpeg -i input.opus -af "volumedetect" -f null /dev/null 2>&1 | grep max_volume
# If max_volume > 0 dB, audio is clipping
Check Duration
ffprobe -v quiet -show_entries format=duration \
-of default=noprint_wrappers=1:nokey=1 input.opus
Format Selection Guide
| Source Content | Extract To | Bitrate | Rationale |
|---|---|---|---|
| Music video (studio) | Opus | 128k | Good balance for music |
| Live performance | Opus | 128k | Crowd noise doesn't need more |
| Studio session | Opus | 192k | Preserve detail |
| Interview | Opus | 96k | Speech doesn't need high bitrate |
| Full concert (2+ hours) | Opus | 96k | Size management |
| Archival source (FLAC) | FLAC | Lossless | Preserve original quality |
Segment Handling
Concatenate Audio Segments
# Create file list
for f in segments/*.opus; do
echo "file '$f'" >> filelist.txt
done
# Concatenate without re-encoding
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.opus
Split Long Recording into Tracks
# Split at specific timestamps (from setlist)
ffmpeg -i concert.opus -ss 00:00:00 -to 00:04:30 -c copy "01 - Jumpsuit.opus"
ffmpeg -i concert.opus -ss 00:04:30 -to 00:08:15 -c copy "02 - Levitate.opus"
Thumbnail/Frame Extraction
Extract Video Thumbnail (for cover art)
# Extract frame at 5 seconds
ffmpeg -y -ss 5 -i video.mp4 -vframes 1 -q:v 2 cover.jpg
# Extract frame as WebP (smaller)
ffmpeg -y -ss 5 -i video.mp4 -vframes 1 cover.webp
References
- @$AIWG_ROOT/agentic/code/addons/aiwg-utils/rules/human-authorization.md — Seek explicit authorization before overwriting existing audio files
- @$AIWG_ROOT/agentic/code/frameworks/media-curator/skills/acquire/SKILL.md — Acquisition skill that invokes audio extraction via --extract-audio flag
- @$AIWG_ROOT/agentic/code/frameworks/media-curator/skills/integrity-verification/SKILL.md — Verify extracted audio file integrity after processing
- @$AIWG_ROOT/agentic/code/frameworks/media-curator/skills/metadata-tagging/SKILL.md — Tag extracted audio files with correct metadata after extraction
04 同仓库更多 Skills
plugin-search
Search marketplaces for plugins using configured local manifests and directory caches; rank matching plugins by observed installs, review tier and cache dates without installing or fetching anything
plugin-search
Search marketplaces for plugins using configured local manifests and directory caches; rank matching plugins by observed installs, review tier and cache dates without installing or fetching anything
host-hardening
Read-only system hardening baseline and plan-first host hardening recommendations for SSH, Docker bind addresses, firewall persistence, datastores, exporters and audit retention.
exposure-analysis
Read-only firewall analysis and effective host exposure reconstruction for Docker published ports, UFW bypass, stale rules, CDN scope, IPv6 asymmetry and external probe allowlists.
host-hardening
Read-only system hardening baseline and plan-first host hardening recommendations for SSH, Docker bind addresses, firewall persistence, datastores, exporters and audit retention.
exposure-analysis
Read-only firewall analysis and effective host exposure reconstruction for Docker published ports, UFW bypass, stale rules, CDN scope, IPv6 asymmetry and external probe allowlists.