extract-audio

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Format Decision Tree

格式决策树

User wantsFormatFlagsWhy
Music, archive qualityFLAC
-c:a flac
Lossless, no quality loss
Music, small + transparentMP3 VBR
-c:a libmp3lame -q:a 0
~200kbps avg, perceptually lossless
Podcast / voiceMP3 128k CBR
-c:a libmp3lame -b:a 128k
Sufficient for speech, universally compatible
Mobile / streamingAAC 192k
-c:a aac -b:a 192k
Better than MP3 at equivalent bitrate
DAW / editingWAV
-c:a pcm_s16le -ar 44100
No encoding loss, widest DAW support
Source already target formatCopy
-c:a copy
No re-encode, instant, lossless
用户需求格式参数原因
音乐、归档级质量FLAC
-c:a flac
无损,无质量损失
音乐、体积小且音质接近无损MP3 VBR
-c:a libmp3lame -q:a 0
平均约200kbps,感知无损
播客/语音内容MP3 128k CBR
-c:a libmp3lame -b:a 128k
满足语音需求,兼容性广泛
移动设备/流媒体AAC 192k
-c:a aac -b:a 192k
相同比特率下表现优于MP3
数字音频工作站(DAW)/编辑WAV
-c:a pcm_s16le -ar 44100
无编码损失,支持绝大多数DAW
源文件已是目标格式复制
-c:a copy
无需重新编码,即时完成,无损

Process

流程

1. Probe audio streams

1. 探测音频流

bash
ffprobe -v quiet -print_format json -show_streams "$INPUT" | \
  python3 -c "
import json, sys
streams = [s for s in json.load(sys.stdin)['streams'] if s['codec_type']=='audio']
for i, s in enumerate(streams):
    print(f'Stream {i}: {s[\"codec_name\"]} {s.get(\"bit_rate\",\"?\")} bps {s.get(\"channel_layout\",\"?\")}')
"
bash
ffprobe -v quiet -print_format json -show_streams "$INPUT" | \
  python3 -c "
import json, sys
streams = [s for s in json.load(sys.stdin)['streams'] if s['codec_type']=='audio']
for i, s in enumerate(streams):
    print(f'Stream {i}: {s[\"codec_name\"]} {s.get(\"bit_rate\",\"?\")} bps {s.get(\"channel_layout\",\"?\")}')
"

2. Determine format

2. 确定格式

Apply the decision tree above if the user didn't specify. If the source audio codec already matches the target, use
-c:a copy
to avoid transcoding.
If multiple audio streams exist, ask the user which to extract — or use
-map 0:a
to extract all. Once the user responds, apply
-map 0:a:N
(where N is the zero-based stream index they chose) or
-map 0:a
for all streams in the Phase 3 command.
若用户未指定格式,应用上述决策树。若源音频编码已匹配目标格式,使用
-c:a copy
避免转码。
若存在多个音频流,询问用户要提取哪一个——或使用
-map 0:a
提取所有流。用户回复后,在第3阶段的命令中应用
-map 0:a:N
(其中N为用户选择的从零开始的流索引)或
-map 0:a
提取所有流。

3. Construct command

3. 构建命令

bash
undefined
bash
undefined

General pattern (-vn drops the video stream entirely):

General pattern (-vn drops the video stream entirely):

ffmpeg -i "$INPUT" -vn [FORMAT_FLAGS] "$OUTPUT"
ffmpeg -i "$INPUT" -vn [FORMAT_FLAGS] "$OUTPUT"

Examples:

Examples:

ffmpeg -i video.mp4 -vn -c:a libmp3lame -q:a 0 audio.mp3 # MP3 VBR best quality ffmpeg -i video.mp4 -vn -c:a libmp3lame -b:a 128k podcast.mp3 # MP3 128k CBR ffmpeg -i video.mp4 -vn -c:a flac archive.flac # FLAC lossless ffmpeg -i video.mp4 -vn -c:a aac -b:a 192k mobile.aac # AAC ffmpeg -i video.mp4 -vn -c:a pcm_s16le -ar 44100 edit.wav # WAV for DAW ffmpeg -i video.mp4 -vn -c:a copy original.m4a # Copy audio stream
undefined
ffmpeg -i video.mp4 -vn -c:a libmp3lame -q:a 0 audio.mp3 # MP3 VBR best quality ffmpeg -i video.mp4 -vn -c:a libmp3lame -b:a 128k podcast.mp3 # MP3 128k CBR ffmpeg -i video.mp4 -vn -c:a flac archive.flac # FLAC lossless ffmpeg -i video.mp4 -vn -c:a aac -b:a 192k mobile.aac # AAC ffmpeg -i video.mp4 -vn -c:a pcm_s16le -ar 44100 edit.wav # WAV for DAW ffmpeg -i video.mp4 -vn -c:a copy original.m4a # Copy audio stream
undefined

4. Confirm and run

4. 确认并执行

Show: detected source codec and bitrate, chosen output format, output path. Wait for approval, then run.
Report output file size and duration:
ffprobe -v quiet -show_format "$OUTPUT" | grep -E "duration|size"
展示:检测到的源编码和比特率、选定的输出格式、输出路径。等待用户确认后执行。
报告输出文件大小和时长:
ffprobe -v quiet -show_format "$OUTPUT" | grep -E "duration|size"

Key Decisions

关键决策

Preserve generation quality: avoid transcoding chains that degrade source fidelity. Each decision below is an application of this principle.
  • Lossy-to-lossy warning: if the source is already lossy (MP3, AAC, OGG) and the user wants a different lossy format, warn them that re-encoding degrades quality. Recommend keeping the source format or using
    -c:a copy
    where container compatibility allows.
  • For files >1 hour, ask whether the user wants the full file or a specific range — trimming can be added with
    -ss
    and
    -to
    before
    -vn
    .
  • M4A vs AAC: AAC is the codec, M4A is the container. Use
    .m4a
    extension for Apple device compatibility; use
    .aac
    for a raw stream.
保留生成质量:避免会降低源文件保真度的转码链。以下每项决策均遵循此原则。
  • 有损转有损警告:若源文件已是有损格式(MP3、AAC、OGG),且用户想要转换为另一种有损格式,需警告用户重新编码会降低质量。建议保留源格式,或在容器兼容的情况下使用
    -c:a copy
  • 对于时长超过1小时的文件,询问用户是要完整文件还是特定片段——可在
    -vn
    前添加
    -ss
    -to
    参数进行修剪。
  • M4A与AAC:AAC是编码格式,M4A是容器。为兼容苹果设备,使用
    .m4a
    扩展名;若需原始流,使用
    .aac
    扩展名。