Debian Codegraph @

docs/plugins/convert.rst

raw
1 Convert Plugin
2 ==============
3
4 The ``convert`` plugin lets you convert parts of your collection to a directory
5 of your choice, transcoding audio and embedding album art along the way. It can
6 transcode to and from any format using a configurable command line. Optionally
7 an m3u playlist file containing all the converted files can be saved to the
8 destination path.
9
10 Installation
11 ------------
12
13 To use the ``convert`` plugin, first enable it in your configuration (see
14 :ref:`using-plugins`). By default, the plugin depends on FFmpeg_ to transcode
15 the audio, so you might want to install it.
16
17 .. _ffmpeg: https://ffmpeg.org
18
19 Usage
20 -----
21
22 To convert a part of your collection, run ``beet convert QUERY``. The command
23 will transcode all the files matching the query to the destination directory
24 given by the ``-d`` (``--dest``) option or the ``dest`` configuration. The path
25 layout mirrors that of your library, but it may be customized through the
26 ``paths`` configuration. Files that have been previously converted---and thus
27 already exist in the destination directory---will be skipped.
28
29 The plugin uses a command-line program to transcode the audio. With the ``-f``
30 (``--format``) option you can choose the transcoding command and customize the
31 available commands :ref:`through the configuration <convert-format-config>`.
32
33 Unless the ``-y`` (``--yes``) flag is set, the command will list all the items
34 to be converted and ask for your confirmation.
35
36 The ``-a`` (or ``--album``) option causes the command to match albums instead of
37 tracks.
38
39 By default, the command places converted files into the destination directory
40 and leaves your library pristine. To instead back up your original files into
41 the destination directory and keep converted files in your library, use the
42 ``-k`` (or ``--keep-new``) option.
43
44 To test your configuration without taking any actions, use the ``--pretend``
45 flag. The plugin will print out the commands it will run instead of executing
46 them.
47
48 By default, files that do not need to be transcoded will be copied to their
49 destination. Passing the ``-l`` (``--link``) flag creates symbolic links
50 instead, passing ``-H`` (``--hardlink``) creates hard links. Note that album art
51 embedding is disabled for files that are linked. Refer to the ``link`` and
52 ``hardlink`` options below.
53
54 The ``-F`` (or ``--force``) option forces transcoding even when safety options
55 such as ``no_convert``, ``never_convert_lossy_files``, or ``max_bitrate`` would
56 normally cause a file to be copied or skipped instead. This can be combined with
57 ``--format`` to explicitly transcode lossy inputs to a chosen target format. The
58 default value for this flag comes from the ``force`` configuration option.
59
60 The ``-m`` (or ``--playlist``) option enables the plugin to create an m3u8
61 playlist file in the destination folder given by the ``-d`` (``--dest``) option
62 or the ``dest`` configuration. The path to the playlist file can either be
63 absolute or relative to the ``dest`` directory. The contents will always be
64 relative paths to media files, which tries to ensure compatibility when read
65 from external drives or on computers other than the one used for the conversion.
66 There is one caveat though: A list generated on Unix/macOS can't be read on
67 Windows and vice versa. Depending on the beets user's settings a generated
68 playlist potentially could contain unicode characters. This is supported,
69 playlists are written in `M3U8 format`_.
70
71 The ``-r`` (or ``--refresh``) option allows to refresh the converted files if
72 the originals ones are modified. It instructs the plugin to compare the
73 timestamps of the latest modification for both the originals and the converted
74 files. If an original file is newer than a converted file, the converted file
75 will be removed from the filesystem, and the original file will be converted
76 once again.
77
78 Plugin Event
79 ------------
80
81 After successfully converting or copying an item, this plugin sends the
82 ``after_convert`` event. See :ref:`plugin_events` for its listener parameters.
83
84 Configuration
85 -------------
86
87 To configure the plugin, make a ``convert:`` section in your configuration file.
88 The available options are:
89
90 - **auto**: Import transcoded versions of your files automatically during
91 imports. With this option enabled, the importer will transcode all (in the
92 default configuration) non-MP3 files over the maximum bitrate before adding
93 them to your library. Default: ``no``.
94 - **auto_keep**: Convert your files automatically on import to **dest** but
95 import the non transcoded version. It uses the default format you have defined
96 in your config file. Default: ``no``. This import behavior is fixed and is not
97 affected by ``keep_new``.
98
99 .. note::
100
101 You probably want to use only one of the ``auto`` and ``auto_keep``
102 options, not both. Enabling both will convert your files twice on import,
103 which you probably don't want.
104
105 - **tmpdir**: The directory where temporary files will be stored during import.
106 Default: none (system default),
107 - **copy_album_art**: Copy album art when copying or transcoding albums matched
108 using the ``-a`` option. Default: ``no``.
109 - **album_art_maxwidth**: Downscale album art if it's too big. The resize
110 operation reduces image width to at most ``maxwidth`` pixels while preserving
111 the aspect ratio. The specified image size will apply to both embedded album
112 art and external image files.
113 - **dest**: The directory where the files will be converted (or copied) to.
114 Default: none.
115 - **embed**: Embed album art in converted items. Default: ``yes``.
116 - **id3v23**: Can be used to override the global ``id3v23`` option. Default:
117 ``inherit``.
118 - **write_metadata**: Can be used to disable writing metadata to converted
119 files. Default: ``true``.
120 - **max_bitrate**: By default, the plugin does not transcode files that are
121 already in the destination format. This option instead also transcodes files
122 with high bitrates, even if they are already in the same format as the output.
123 Note that this does not guarantee that all converted files will have a lower
124 bitrate---that depends on the encoder and its configuration. Default: none.
125 This option is ignored when ``force`` is enabled (via config or ``--force``).
126 - **no_convert**: Does not transcode items matching the query string provided
127 (see :doc:`/reference/query`). For example, to not convert AAC or WMA formats,
128 you can use ``format:AAC, format:WMA`` or ``path::\.(m4a|wma)$``. If you only
129 want to transcode WMA format, you can use a negative query, e.g.,
130 ``^path::\.(wma)$``, to not convert any other format except WMA. This option
131 is ignored when ``force`` is enabled (via config or ``--force``).
132 - **never_convert_lossy_files**: Cross-conversions between lossy codecs---such
133 as mp3, ogg vorbis, etc.---makes little sense as they will decrease quality
134 even further. If set to ``yes``, lossy files are always copied. Default:
135 ``no``. When ``never_convert_lossy_files`` is enabled, lossy source files (for
136 example MP3 or Ogg Vorbis) are normally not transcoded and are instead copied
137 or linked as-is. To explicitly transcode lossy files in spite of this, use the
138 ``force`` setting (from config or ``--force``) with the ``convert`` command
139 (optionally together with ``--format`` to choose a target format)
140 - **force**: Force transcoding by default. When enabled, items are transcoded
141 even when ``no_convert``, ``never_convert_lossy_files``, or ``max_bitrate``
142 would otherwise copy or skip them. This applies to both ``beet convert`` and
143 automatic conversion during import (``auto`` and ``auto_keep``). Default:
144 ``false``.
145 - **keep_new**: Enable ``--keep-new`` behavior by default for ``beet convert``.
146 Converted files stay in your library and originals are moved to the external
147 destination. This option applies only to ``beet convert`` and does not change
148 ``auto_keep`` import semantics. Default: ``false``.
149 - **paths**: The directory structure and naming scheme for the converted files.
150 Uses the same format as the top-level ``paths`` section (see
151 :ref:`path-format-config`). Default: Reuse your top-level path format
152 settings.
153 - **quiet**: Prevent the plugin from announcing every file it processes.
154 Default: ``false``.
155 - **threads**: The number of threads to use for parallel encoding. By default,
156 the plugin will detect the number of processors available and use them all.
157 - **link**: By default, files that do not need to be transcoded will be copied
158 to their destination. This option creates symbolic links instead. Note that
159 options such as ``embed`` that modify the output files after the transcoding
160 step will cause the original files to be modified as well if ``link`` is
161 enabled. For this reason, album-art embedding is disabled for files that are
162 linked. Default: ``false``.
163 - **hardlink**: This options works similar to ``link``, but it creates hard
164 links instead of symlinks. This option overrides ``link``. Only works when
165 converting to a directory on the same filesystem as the library. Default:
166 ``false``.
167 - **delete_originals**: Transcoded files will be copied or moved to their
168 destination, depending on the import configuration. By default, the original
169 files are not modified by the plugin. This option deletes the original files
170 after the transcoding step has completed. Default: ``false``.
171 - **playlist**: The name of a playlist file that should be written on each run
172 of the plugin. A relative file path (e.g ``playlists/mylist.m3u8``) is allowed
173 as well. The final destination of the playlist file will always be relative to
174 the destination path (``dest``, ``--dest``, ``-d``). This configuration is
175 overridden by the ``-m`` (``--playlist``) command line option. Default: none.
176 - **refresh**: Refresh the converted files if needed by re-converting modified
177 original files. This configuration is overridden by the ``-r`` (``--refresh``)
178 command line option. Default: ``false``.
179
180 You can also configure the format to use for transcoding (see the next section):
181
182 - **format**: The name of the format to transcode to when none is specified on
183 the command line. Default: ``mp3``.
184 - **formats**: A set of formats and associated command lines for transcoding
185 each.
186
187 .. _convert-format-config:
188
189 Configuring the transcoding command
190 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191
192 You can customize the transcoding command through the ``formats`` map and select
193 a command with the ``--format`` command-line option or the ``format``
194 configuration.
195
196 ::
197
198 convert:
199 format: speex
200 formats:
201 speex:
202 command: ffmpeg -i $source -y -acodec speex $dest
203 extension: spx
204 wav: ffmpeg -i $source -y -acodec pcm_s16le $dest
205
206 In this example ``beet convert`` will use the *speex* command by default. To
207 convert the audio to ``wav``, run ``beet convert -f wav``. This will also use
208 the format key (``wav``) as the file extension.
209
210 Each entry in the ``formats`` map consists of a key (the name of the format) as
211 well as the command and optionally the file extension. ``extension`` is the
212 filename extension to be used for newly transcoded files. If only the command is
213 given as a string or the extension is not provided, the file extension defaults
214 to the format's name. ``command`` is the command to use to transcode audio. The
215 tokens ``$source`` and ``$dest`` in the command are replaced with the paths to
216 the existing and new file.
217
218 The plugin in comes with default commands for the most common audio formats:
219 ``mp3``, ``alac``, ``flac``, ``aac``, ``opus``, ``ogg``, ``wma``. For details
220 have a look at the output of ``beet config -d``.
221
222 For a one-command-fits-all solution use the ``convert.command`` and
223 ``convert.extension`` options. If these are set, the formats are ignored and the
224 given command is used for all conversions.
225
226 ::
227
228 convert:
229 command: ffmpeg -i $source -y -vn -aq 2 $dest
230 extension: mp3
231
232 Gapless MP3 encoding
233 ~~~~~~~~~~~~~~~~~~~~
234
235 While FFmpeg cannot produce "gapless_" MP3s by itself, you can create them by
236 using LAME_ directly. Use a shell script like this to pipe the output of FFmpeg
237 into the LAME tool:
238
239 ::
240
241 #!/bin/sh
242 ffmpeg -i "$1" -f wav - | lame -V 2 --noreplaygain - "$2"
243
244 Then configure the ``convert`` plugin to use the script:
245
246 ::
247
248 convert:
249 command: /path/to/script.sh $source $dest
250 extension: mp3
251
252 This strategy configures FFmpeg to produce a WAV file with an accurate length
253 header for LAME to use. Using ``--noreplaygain`` disables gain analysis; you can
254 use the :doc:`/plugins/replaygain` to do this analysis. See the LAME
255 documentation_ and the `HydrogenAudio wiki`_ for other LAME configuration
256 options and a thorough discussion of MP3 encoding.
257
258 .. _documentation: https://sourceforge.net/projects/lame/
259
260 .. _gapless: https://wiki.hydrogenaudio.org/index.php?title=Gapless_playback
261
262 .. _hydrogenaudio wiki: https://wiki.hydrogenaudio.org/index.php?title=LAME
263
264 .. _lame: https://sourceforge.net/projects/lame/
265
266 .. _m3u8 format: https://en.wikipedia.org/wiki/M3U#M3U8