FFmpeg - Encode AC3: Difference between revisions

From PiRho Knowledgebase
Jump to navigationJump to search
m Knowledgebaseadmin moved page FFMpeg - Encode AC3 to FFmpeg - Encode AC3
Dex (talk | contribs)
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
The bit rates listed here assume Stereo (2 ch) and sample rate of 44.1 KHz or 48 KHz. Usable range 160 Kbps.<br/>
[[Category:FFmpeg]]
<code>ffmpeg -i <input.file> -c:a ac3 -ac 2 -b:a 160k <output.file></code><br/>
[[Category:AC3]]
Reference: [[https://trac.ffmpeg.org/wiki/Encode/HighQualityAudio FFmpeg: Guidelines for high quality lossy audio encoding]]<br/>
AC-3 (Dolby Digital) is a widely supported lossy multichannel audio codec used in DVD, broadcast, set-top boxes, and legacy home-cinema systems. This article explains how to encode AC-3 audio using FFmpeg with safe, standards-compliant settings.
Reference: [[https://ffmpeg.org/ffmpeg-codecs.html#ac3-and-ac3_005ffixed FFmpeg: FFmpeg Codecs Documentation]]<br/>
 
== Summary ==
AC-3 audio supports mono, stereo, and multichannel output at sample rates of 32 kHz, 44.1 kHz, and 48 kHz. For stereo sources, the usable quality range begins at 160 kbps, with 192–224 kbps being typical for transparent or near‑transparent output.
 
This article provides a recommended FFmpeg command, bit‑rate guidance, and reference links to official documentation.
 
== Recommended FFmpeg Command ==
To encode a stereo AC‑3 stream at 160 kbps:
 
<pre>
ffmpeg -i <input.file> -c:a ac3 -ac 2 -b:a 160k <output.file>
</pre>
 
=== Explanation of parameters ===
* '''-c:a ac3''' — Use the native FFmpeg AC‑3 encoder
* '''-ac 2''' — Downmix or encode as 2‑channel stereo
* '''-b:a 160k''' — Audio bitrate (minimum advisable for acceptable stereo AC‑3)
 
== Bit‑Rate Considerations ==
=== Stereo (2.0) ===
{| class="wikitable"
! Bitrate !! Notes
|-
| 160 kbps || Minimum usable quality for music or mixed content
|-
| 192 kbps || Common DVD‑quality stereo bitrate
|-
| 224–256 kbps || Higher clarity, useful for rich stereo music
|-
| >256 kbps || Rarely necessary for stereo; diminishing returns
|}
 
=== Supported Sample Rates ===
AC‑3 allows:
* 32000 Hz
* 44100 Hz
* 48000 Hz (most common for film, video, and broadcast)
 
FFmpeg will preserve the input sample rate unless explicitly changed.
 
== Channel Layouts ==
Although this article focuses on stereo, AC‑3 supports:
* 1.0 (Mono)
* 2.0 (Stereo)
* 5.1 Surround
 
Examples:
 
'''5.1 at 448 kbps:'''
<pre>
ffmpeg -i input.wav -c:a ac3 -b:a 448k output.ac3
</pre>
 
'''5.1 at 640 kbps (maximum AC‑3 bitrate):'''
<pre>
ffmpeg -i input.wav -c:a ac3 -b:a 640k output.ac3
</pre>
 
== When to Use AC‑3 ==
AC‑3 remains useful when:
* Targeting DVD‑Video or broadcast specifications
* Playback device requires Dolby Digital compatibility
* You need a widely-supported legacy format
* Building media for set-top boxes, old TVs, or home-cinema receivers
 
== Troubleshooting ==
=== "Bitrate not allowed" Errors ===
AC‑3 only accepts specific bitrates depending on channel count. Try using: 160k, 192k, 224k, 256k, 320k for stereo.
 
=== "Invalid samplerate" ===
Ensure the sample rate is one of:
* 32000
* 44100
* 48000
 
=== Audio seems quieter ===
AC‑3 includes Dialog Normalization (dialnorm) metadata. FFmpeg sets default values; receivers may adjust playback gain accordingly.
 
== References ==
* https://trac.ffmpeg.org/wiki/Encode/HighQualityAudio
* https://ffmpeg.org/ffmpeg-codecs.html#ac3-and-ac3_005ffixed

Latest revision as of 13:52, 14 March 2026

AC-3 (Dolby Digital) is a widely supported lossy multichannel audio codec used in DVD, broadcast, set-top boxes, and legacy home-cinema systems. This article explains how to encode AC-3 audio using FFmpeg with safe, standards-compliant settings.

Summary

AC-3 audio supports mono, stereo, and multichannel output at sample rates of 32 kHz, 44.1 kHz, and 48 kHz. For stereo sources, the usable quality range begins at 160 kbps, with 192–224 kbps being typical for transparent or near‑transparent output.

This article provides a recommended FFmpeg command, bit‑rate guidance, and reference links to official documentation.

Recommended FFmpeg Command

To encode a stereo AC‑3 stream at 160 kbps:

ffmpeg -i <input.file> -c:a ac3 -ac 2 -b:a 160k <output.file>

Explanation of parameters

  • -c:a ac3 — Use the native FFmpeg AC‑3 encoder
  • -ac 2 — Downmix or encode as 2‑channel stereo
  • -b:a 160k — Audio bitrate (minimum advisable for acceptable stereo AC‑3)

Bit‑Rate Considerations

Stereo (2.0)

Bitrate Notes
160 kbps Minimum usable quality for music or mixed content
192 kbps Common DVD‑quality stereo bitrate
224–256 kbps Higher clarity, useful for rich stereo music
>256 kbps Rarely necessary for stereo; diminishing returns

Supported Sample Rates

AC‑3 allows:

  • 32000 Hz
  • 44100 Hz
  • 48000 Hz (most common for film, video, and broadcast)

FFmpeg will preserve the input sample rate unless explicitly changed.

Channel Layouts

Although this article focuses on stereo, AC‑3 supports:

  • 1.0 (Mono)
  • 2.0 (Stereo)
  • 5.1 Surround

Examples:

5.1 at 448 kbps:

ffmpeg -i input.wav -c:a ac3 -b:a 448k output.ac3

5.1 at 640 kbps (maximum AC‑3 bitrate):

ffmpeg -i input.wav -c:a ac3 -b:a 640k output.ac3

When to Use AC‑3

AC‑3 remains useful when:

  • Targeting DVD‑Video or broadcast specifications
  • Playback device requires Dolby Digital compatibility
  • You need a widely-supported legacy format
  • Building media for set-top boxes, old TVs, or home-cinema receivers

Troubleshooting

"Bitrate not allowed" Errors

AC‑3 only accepts specific bitrates depending on channel count. Try using: 160k, 192k, 224k, 256k, 320k for stereo.

"Invalid samplerate"

Ensure the sample rate is one of:

  • 32000
  • 44100
  • 48000

Audio seems quieter

AC‑3 includes Dialog Normalization (dialnorm) metadata. FFmpeg sets default values; receivers may adjust playback gain accordingly.

References