TransFLAC：将 FLAC 转换为有损格式
FLAC
![](/data/attachment/album/202308/25/142504tpt99jjz99o955v2.jpg)


### FLAC：无损音频压缩格式


自由无损音频编解码器（[FLAC](https://xiph.org/flac/)）是一种无损音频压缩格式，可保留所有原始音频数据。这意味着 FLAC 文件可以解码成与原始音频文件完全相同的副本，而不会有任何质量上的损失。不过，无损压缩通常会比有损压缩的文件大小更大，这就是为什么需要一种将 FLAC 转为有损格式的方法。而这就是 TransFLAC 可以提供帮助的地方。


FLAC 是一种流行的数字音频文件存档格式，也可用于在家用电脑上存储音乐收藏。音乐流媒体服务也越来越普遍地提供 FLAC 作为高品质音频的一种选择。


对于存储空间有限的便携设备，通常使用 MP3、AAC 和 OGG Vorbis 等有损音频格式。这些格式的文件大小比无损格式小得多，但音质仍然很好。


一般来说，FLAC 是对无损音频质量要求较高的应用（如存档、母带制作和 <ruby> 鉴定聆听 <rt>  critical listening </rt></ruby>）的不错选择。对于文件大小更为重要的应用，如在便携设备上存储音乐或通过互联网串流音乐，有损格式是不错的选择。


### TransFLAC：将 FLAC 转换为有损格式


[TransFLAC](https://bitbucket.org/gbcox/transflac/wiki/Home) 是一款命令行应用，可将 FLAC 音频文件转换为指定质量级别的有损格式。它能使 FLAC 和存储有损格式的音乐库保持部分或完全同步。TransFLAC 还能同步目录结构中存储的专辑封面、专辑封底和文件夹文件。你可以在终端窗口中交互式运行 TransFLAC，也可以使用 cron 或 systemd 等应用安排其自动运行。


必须指定以下四个参数：


1. **输入 FLAC 目录**：要递归搜索 FLAC 音频文件的目录。目录名大小写敏感。TransFLAC 会将目录树中的所有 FLAC 音频文件转换为指定的有损编解码格式。程序将解决遇到的任何符号链接，并显示物理路径。
2. **输出有损目录**：有损音频文件的存储目录。目录名大小写敏感。程序将解析遇到的任何符号链接并显示物理路径。
3. **有损编解码器**：用于转换 FLAC 音频文件的编解码器。编解码器名称的大小写并不重要。对于给定的文件大小或比特率，OPUS 通常能提供最佳音质，是推荐的编解码器。有效值为 [opus](https://opus-codec.org/) | [ogg](https://xiph.org/vorbis/) | [aac](https://en.wikipedia.org/wiki/Fraunhofer_FDK_AAC) | [mp3](https://lame.sourceforge.io/)
4. **编解码器质量**： 用于编码有损音频文件的质量预设。质量名称的大小写并不重要。**OPUS STANDARD** 质量提供全带宽、立体声音乐、良好的音频质量和透明度，是推荐的设置。有效值为 低 | 中 | 标准 | 高 | 优质


**TransFLAC** 允许对配置中的某些项目进行 [自定义](https://bitbucket.org/gbcox/transflac/wiki/src-tf-conf-override.sh)。项目 [维基](https://bitbucket.org/gbcox/transflac/wiki/TransFLAC) 提供了更多信息。


在 [Fedora Linux](https://fedoraproject.org/) 上安装：



```
$ sudo dnf install transflac

```

![](/data/attachment/album/202308/25/142505xfepju080dn8r5z8.svg)




---


via: <https://fedoramagazine.org/transflac-convert-flac-to-lossy-formats/>


作者：[Gerald B. Cox](https://fedoramagazine.org/author/gbcox/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
**FLAC: The Lossless Audio Compression Format**

[FLAC](https://xiph.org/flac/), or Free Lossless Audio Codec, is a lossless audio compression format that preserves all the original audio data. This means that FLAC files can be decoded to an identical copy of the original audio file, without any loss in quality. However, lossless compression typically results in larger file sizes than lossy compression, which is why a method to convert FLAC to lossy formats is desirable. This is where TransFLAC can help.

FLAC is a popular format for archiving digital audio files, as well as for storing music collections on home computers. It is also becoming increasingly common for music streaming services to offer FLAC as an option for high-quality audio.

For portable devices, where storage space is limited, lossy audio formats such as MP3, AAC, and OGG Vorbis are often used. These formats can achieve much smaller file sizes than lossless formats, while still providing good sound quality.

In general, FLAC is a good choice for applications where lossless audio quality is important, such as archiving, mastering, and critical listening. Lossy formats are a good choice for applications where file size is more important, such as storing music on portable devices or streaming music over the internet.

## TransFLAC: Convert FLAC to lossy formats

[TransFLAC](https://bitbucket.org/gbcox/transflac/wiki/Home) is a command-line application that converts FLAC audio files to a lossy format at a specified quality level. It can keep both the FLAC and lossy libraries synchronized, either partially or fully. TransFLAC also synchronizes album art stored in the directory structure, such as cover, albumart, and folder files. You can run TransFLAC interactively in a terminal window, or you can schedule it to run automatically using applications such as cron or systemd.

The following four parameters must be specified:

**Input FLAC Directory**: The directory to recursively search for FLAC audio files. The case of the directory name matters. TransFLAC will convert all FLAC audio files in the directory tree to the specified lossy codec format. The program will resolve any symlinks encountered and display the physical path.**Output Lossy Directory:**The directory to store the lossy audio files. The case of the directory name matters. The program will resolve any symlinks encountered and display the physical path.**Lossy Codec:**The codec used to convert the FLAC audio files. The case of the codec name does not matter. OPUS generally provides the best sound quality for a given file size or bitrate, and is the recommended codec.

Valid values are:[OPUS](https://opus-codec.org/)|[OGG](https://xiph.org/vorbis/)|[AAC](https://en.wikipedia.org/wiki/Fraunhofer_FDK_AAC)|[MP3](https://lame.sourceforge.io/)**Codec Quality:**The quality preset used to encode the lossy audio files. The case of the quality name does not matter.**OPUS STANDARD**quality provides full bandwidth, stereo music, good audio quality approaching transparency, and is the recommended setting.

Valid values are: LOW | MEDIUM | STANDARD | HIGH | PREMIUM

**TransFLAC** allows for [customization](https://bitbucket.org/gbcox/transflac/wiki/src-tf-conf-override.sh) of certain items in the configuration. The project [wiki](https://bitbucket.org/gbcox/transflac/wiki/TransFLAC) provides additional information.

**Installation** on [Fedora Linux](https://fedoraproject.org/):

$ sudo dnf install transflac

## Gregory Bartholomew

If the animated SVG at the end doesn’t autoplay, try refreshing the page by pressing the F5 key. (Sorry, it’s the first time we’ve tried to use an animated SVG in an article.)

## Chris Moller

sox does flac conversion out of the box.

## Gerald B. Cox

AFAIK: SOX cannot convert FLAC files to OPUS or AAC formats. TransFLAC, on the other hand, can recursively scan a directory and convert all FLAC files found, using multiple threads to speed up the process.

## SigmaSquadron

have you heard about the magical artefact that is ffmpeg?

## Gerald B. Cox

See response to @darvond

## Darvond

Aside from a pretty text interface, what might this offer over the tried, tested, code mature ffmpeg?

Don’t get me wrong, the chrome on this is neat, but this is also just akin to showing someone who has a workflow based around ImageMagick/GraphicsMagick a bespoke gif converter.

## Gerald B. Cox

I’m well aware of ffmpeg. In fact, TransFLAC uses it for the conversion to MP3 and AAC files. However, what you are missing is that ffmpeg only provides a small subset of the entire functionality. For more information, refer to the wiki mentioned in the article.

## Grandpa Leslie

Congratulations on a very well done presentation.

Not many people (very very few people) could do better

## Cornel Panceac

In the .srpm:

$ file gbcox-transflac-884f17e71b29.tar.bz2

gbcox-transflac-884f17e71b29.tar.bz2: Zip archive data, at least v1.0 to extract, compression method=store

If it’s .zip, maybe it should be called .zip 🙂

(as opposed to .tar.bz2)

## Richard England

A “tar.bz2” file is a compressed archive file created using the tar command in Unix/Linux and the opensource patent free bzip2 compression algorithm.

https://sourceware.org/bzip2/

## Gregory Bartholomew

The contents of the file are independent of the file name:

## Richard England

That is true, but the bz2 extension tells the user what compression was used. This might be useful if someone wishes to un-compress the tar file but not extract the contents of the tar file. I’ve had a need to do that in the past.

## Gerald Cox

Thanks for reporting. It was due to a difference in the way Bitbucket handles downloads. Odd it didn’t seem to cause any errors in the build process. In any event, it is fixed in v1.2.4, If you notice any further problems/concerns, please report in fedora bugzilla or in the bitbucket transflac repo under issues.

## Cornel Panceac

The truth is TransFLAC is an amazing piece of software. It’s living proof things can still be simple in this very complex world.

## Patrick Perkins

Not sure why, but i get ZERO output using this tool. ffmpeg -i works perfectly. Unfortunately, I have music library of over 2800 flac files and was hoping to use this tool to convert about 500 of them to be used in my watch for when I ride my bike..

I suspect the tool is sensitive to spaces or other characters in my files

‘Disc 1 – 05 – All Along the Watchtower (live).flac’

Ill keep searching for a tool that works for me.

## Gerald B. Cox

Interesting, I tried with renaming a track to “Disc 1 – 05 – All Along the Watchtower (live).flac” and it encoded to mp3 with no problem. If you are still having an issue with this or the aac format, please open a bug report. Thanks!

## Patrick Perkins

Some additional infofor my comment above.

This works great when converting to MP3 format.

I get no output when attempting to convert to an AAC format.

I guess I am either missing an rpm or have an incorrect rpm installed.

## Vijay

So this allows more lossy formats that just mp3? Do they occupy volume space or does it do it on the fly in a virtual filesystem like mp3fs?

## Gerald B. Cox

opusenc is used to convert to opus

oggenc is used to convert to ogg

ffmpeg is used to convert to mp3 and aac

## Patrick Perkins

After reviewing the source code, I found that I don’t have the version of ffmpeg that allows the libfdk-aac codec which is used by transflac.

But the built-in ffmpeg aac codec works fine for what I want.

Was considering modifying transflac to use aac and then found a very sweet one line terminal command that converts all the files in a directory to the aac format that I am looking for.

Still, transflac is a very kewl tool for converting flac files to other formats.

## Gerald B. Cox

> After reviewing the source code, I found that I don’t have the version of ffmpeg that allows

> the libfdk-aac codec which is used by transflac.

Really? Where are you getting your version of ffmpeg. Fedora has ffmpeg-free which contains all the codecs needed by TransFLAC, as does most 3rd party repositories, e.g. freshrpms, negativo, etc. Since libfdk-aac is free now, I can’t imaging why anyone would exclude it from their ffmpeg build.

## Patrick Perkins

I have a couple of astronomical apps (Siril and Stellarium) that I believe pulled ffmpeg in as a dependency from rpm-fusion

I’ll do some clean up and see if i can get the ffmpeg-free installed and working with my astro-imaging apps.

I apologize for all the troubles I’ve caused you, Gerald.

And I thank you for your kindness and support

## Gregory Bartholomew

Just my 2¢, but it might be worth checking at installation time anyway. e.g.: if ! ffmpeg -encoders |& grep -qi "\saac\s\+AAC (Advanced Audio Coding)$"; then echo "warning: aac encoding support not detected"; fi

## Patrick Perkins

This is actually VERY fast too. I converted 2583 (70.7 GB) flac files to AAC Standard in less than 5 minutes.

Fedora 38, AMD Ryzen 5900X (4.25GHZ clock).

Very very nice!